<p>I've seen following two types of <code>volumeMounts</code></p>
<pre><code>volumeMounts:
- mountPath: &lt;path&gt;
  name: someName
</code></pre>
<p>and</p>
<pre><code>volumeMounts:
- name: someNameHere
  mountPath: &lt;somePathHere&gt;
</code></pre>
<p>what is the difference in the two? When do we put content in volume and when do we fetch content from volume?</p>
<p>For e.g. in the <a href="https://github.com/DeekshithSN/kubernetes/blob/master/kubernetes-conatiner-patterns/init-sidecar/nginx_dep.yaml" rel="nofollow noreferrer">link</a> initContainer updates the volume, but nginx container takes data from that volume. And similarly, sidecar reads for the volume.</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp
spec:
  selector:
    matchLabels:
      app: myapp-dep
  template:
    metadata:
      labels:
        app: myapp-dep
    spec:
      initContainers:
      - name: ssl-cert-creation
        image: deekshithsn/openssl
        command: [&quot;/bin/sh&quot;]
        args: [&quot;-c&quot;,&quot;mkdir -p /etc/nginx/ssl;openssl req -newkey rsa:2048 -nodes -keyout /etc/nginx/ssl/nginx.key -x509 -days 365 -out /etc/nginx/ssl/nginx.crt -subj '/C=GB/ST=London/L=London/O=Global Security/OU=IT Department/CN=example.com'&quot;]
        volumeMounts: 
          - name: ssl-cert
            mountPath: /etc/nginx/ssl
      containers:
      - name: myapp-dep
        image: deekshithsn/nginxhttps
        command: [&quot;/home/auto-reload-nginx.sh&quot;]
        ports:
        - containerPort: 443
        - containerPort: 80
        livenessProbe:
            httpGet:
              path: /index.html
              port: 80
            initialDelaySeconds: 30
            timeoutSeconds: 1
        volumeMounts:
          - mountPath: /etc/nginx/ssl
            name: ssl-cert
          - mountPath: /etc/nginx/conf.d
            name: nginx-files
          - mountPath: /var/log/nginx
            name: logs

      - name: sidecar-logs
        image: xueshanf/awscli
        command: [&quot;/bin/sh&quot;]
        args: [&quot;-c&quot;,&quot;cp /root/scripts/syncs3.sh /root/syncs3.sh;chmod 777 /root/syncs3.sh;while true; do sh /root/syncs3.sh; sleep 10;done&quot;]
        volumeMounts:
          - name: logs
            mountPath: /var/log/nginx
          - name: aws-credentials
            mountPath: /root/.aws/config
            subPath: config
          - name: aws-credentials
            mountPath: /root/scripts/syncs3.sh
            subPath: syncs3.sh
      volumes:
        - name: ssl-cert
          emptyDir: {}
        - name: logs
          emptyDir: {}
        - name: aws-credentials
          configMap:
            name: &quot;aws-config&quot;
        - name: nginx-files
          configMap:
            name: &quot;nginx-config&quot;

  replicas: 2
</code></pre>

prabodhprakash
<pre><code>volumeMounts:
- mountPath: &lt;somePathHere&gt;
  name: someNameHere
</code></pre>
<pre><code>volumeMounts:
- name: someNameHere
  mountPath: &lt;somePathHere&gt;
</code></pre>
<p>First and Second both mean same, all contents stored in volume <code>someNameHere</code> are mounted into the Pod at path <code>somePathHere</code>. Volumes mount at the specified paths within the image. It means volume is mounted with pod path, now the read/write depends on the application.</p>
