将nginx.conf添加到Kubernetes集群

将configuration文件传递给k8s群集中的NGINX的最佳实践是什么?

您可以创建一个ConfigMap对象,然后将这些值安装为需要它们的文件:

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

而在你的pod规范中:

 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 

(注意mountPath中文件名的重复,并使用完全相同的子路径;与绑定挂载文件相同。

有关ConfigMap的更多信息,请参阅: https : //kubernetes.io/docs/user-guide/configmap/