/ / कुबेरनेट्स क्लस्टर में nginx.conf जोड़ें - nginx, kubernetes

कुबेरनेट्स क्लस्टर में nginx.conf जोड़ें - nginx, kubernetes

एक k8s क्लस्टर के अंदर एक NGINX को config फाइल पास करने के लिए सबसे अच्छा अभ्यास क्या हैं

उत्तर:

उत्तर № 1 के लिए 15

आप एक कॉन्फ़िगॉप ऑब्जेक्ट बना सकते हैं और फिर मानों को उन फ़ाइलों के रूप में माउंट कर सकते हैं, जहाँ आपको उनकी आवश्यकता है:

apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-config
data:
nginx.conf: |
your config
comes here
like this
other.conf: |
second file
contents

और आप फली कल्पना में:

spec:
containers:
- name: nginx
image: nginx
volumeMounts:
- name: nginx-config
mountPath: /etc/nginx/nginx.conf
subPath: nginx.conf
- name: nginx-config
mountPath: /etc/nginx/other.conf
subPath: other.conf
volumes:
- name: nginx-config
configMap:
name: nginx-config

(माउंटपाथ में फ़ाइलनाम के दोहराव पर ध्यान दें और ठीक उसी सबपाथ का उपयोग करके; उसी तरह फ़ाइलों को बाँधें।)

ConfigMap के बारे में अधिक जानकारी के लिए देखें: https://kubernetes.io/docs/user-guide/configmap/


उत्तर № 2 के लिए 1

मुझे कॉन्फ़िगरेशन में nginx कॉन्फ़िगरेशन सामग्री से बचने के लिए एक अच्छा तरीका नहीं मिला। मेरे लिए सबसे अच्छा सहारा फ़ाइलों का उपयोग करके कॉन्फिगरेशन निर्माण का उपयोग करना था।

निम्न के रूप में सहेजें ./data/nginx.conf

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

events {
worker_connections  1024;
}


http {
include       /etc/nginx/mime.types;
default_type  application/octet-stream;

log_format  main  "$remote_addr - $remote_user [$time_local] "$request" "
"$status $body_bytes_sent "$http_referer" "
""$http_user_agent" "$http_x_forwarded_for"";

access_log  /var/log/nginx/access.log  main;

sendfile        on;
#tcp_nopush     on;

keepalive_timeout  65;

#gzip  on;

include /etc/nginx/conf.d/*.conf;
}

अब configMap बनाएँ kubectl create configmap confnginx --from-file=./data/nginx.conf

निम्न परिनियोजन और पॉड यम को इस रूप में सहेजें nginx.yaml

apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
name: nginx
labels:
app: nginx
spec:
selector:
matchLabels:
app: nginx
replicas: 1 # tells deployment to run 2 pods matching the template
template: # create pods using pod definition in this template
metadata:
# unlike pod-nginx.yaml, the name is not included in the meta data as a unique name is
# generated from the deployment name
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:alpine
ports:
- containerPort: 80
volumeMounts:
- name: nginx-config
mountPath: /etc/nginx/nginx.conf
subPath: nginx.conf
volumes:
- name: nginx-config
configMap:
name: confnginx

अब इसे k8 में बनाएँ kubectl apply -f nginx.yaml