<p>I'm trying to create a Nginx server using Kubernetes and the official docker image. Unfortunately, when I'm trying to mount a custom config file, nothing happen. My container works just fine but with it's default configuration file. Moreover the another mount on /etc (the lets encrypt folder) doesn't work too. Nevertheless the certbot mount works just fine...
(If I check inside the container /etc/nginx/nginx.conf it's not the file I'm trying to mount, and /etc/letsencrypt doesn't exist)
I link my deployment file just below..
If someone has an idea and want to help it would be delightful !</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 1 
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.19.6
        ports:
        - containerPort: 80
        - containerPort: 443 
        volumeMounts:
        - name: nginx-config
          mountPath: /etc/nginx/nginx.conf
          subPath: nginx.conf
          readOnly: true
        volumeMounts:
        - name: letsencrypt
          mountPath: /etc/letsencrypt
          readOnly: true
        volumeMounts:
        - name: certbot
          mountPath: /var/www/certbot
      volumes:
        - name: nginx-config
          nfs: 
            server: 192.168.2.9
            path: /volume1/nginx/nginx.conf     
        - name: letsencrypt
          nfs: 
            server: 192.168.2.9
            path: /volume1/nginx/letsencrypt
        - name: certbot
          nfs: 
            server: 192.168.2.9
            path: /volume1/nginx/certbot
</code></pre>
<p><strong>Edit :</strong>
To solve this problem I had to put all my volume mount inside a single volumeMount section and to remove the reference to file in the volume section, like this :</p>
<pre><code>    volumeMounts:
    - name: nginx-config
      mountPath: /etc/nginx/nginx.conf
      subPath: nginx.conf
      readOnly: true
    - name: letsencrypt
      mountPath: /etc/letsencrypt
      readOnly: true

    - name: certbot
      mountPath: /var/www/certbot
  volumes:
    - name: nginx-config
      nfs: 
        server: 192.168.2.9
        path: /volume1/nginx/    
    - name: letsencrypt
      nfs: 
        server: 192.168.2.9
        path: /volume1/nginx/letsencrypt
    - name: certbot
      nfs: 
        server: 192.168.2.9
        path: /volume1/nginx/certbot
</code></pre>

tellierflexus
<p>This is not working because you are incorrectly referencing your <code>Volumes</code>. There is no need to reference the file name at the <code>Volumes</code> mount stage:</p>
<pre class="lang-yaml prettyprint-override"><code>      volumes:
        - name: nginx-config
          nfs: 
            server: 192.168.2.9
            path: /volume1/nginx/nginx.conf  
</code></pre>
<p>Once I applied your config my pod was in <code>CreateContainerConfigError</code> status with
<code>failed to prepare subPath for volumeMount &quot;nginx-config&quot; of container &quot;nginx&quot;</code> error.</p>
<p>The correct yaml should in this case look like this:</p>
<pre class="lang-yaml prettyprint-override"><code>      volumes:
        - name: nginx-config
          nfs: 
            server: 192.168.2.9
            path: /volume1/nginx/  
</code></pre>
<p>I have added a line <code>#This is my custom config</code> just to know that my custom file was load and there are the results of that:</p>
<pre class="lang-sh prettyprint-override"><code>➜ keti nginx-deployment-66c5547c7c-nsfzv  -- cat  /etc/nginx/nginx.conf
</code></pre>
<pre class="lang-json prettyprint-override"><code>#This is my custom config

user  nginx;
worker_processes  1;

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


events {
    worker_connections  1024;
}

.....
</code></pre>
