将自定义的nginx.conf挂载到nginx的k8s容器中

这是一篇帖子,顺便写写备忘录。

挂载自己的nginx.conf文件

通常情况下,我们可以通过将conf文件挂载到/etc/nginx/conf.d目录来对(默认的)nginx镜像进行nginx配置。但是在这种情况下,无法进行需要写入根部的设置,比如worker_processes。

使用subPath进行挂载

apiVersion: apps/v1
kind: Deployment
spec:
  template:
    spec:
      containers:
      - name: nginx
        image: nginx
        volumeMounts:
          - name: nginx-root-conf
            mountPath: /etc/nginx/nginx.conf # マウント先指定
            subPath: nginx.conf # 特定のファイルをマウント
      volumes:
      - name: nginx-root-conf
        configMap:
          name: nginx-root-conf
          items:
            - key: nginx_root.conf
              path: nginx.conf # ファイル名を変更
---

bannerAds