<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
<p>They are semantically the same. <code>VolumeMounts</code> is a hashmap with two keys <code>mountPath</code> and <code>name</code>. There is no difference in how Kubernetes interprets them.</p>
<p>If you look at the json representation rather than yaml it might be more clear (The order of the keys does not matter)</p>
<pre class="lang-json prettyprint-override"><code>{
  &quot;volumeMounts&quot;: [
    {
      &quot;mountPath&quot;: &quot;&lt;path&gt;&quot;,
      &quot;name&quot;: &quot;name&quot;
    }
  ]
}
</code></pre>
<pre class="lang-json prettyprint-override"><code>{
  &quot;volumeMounts&quot;: [
    {
      &quot;name&quot;: &quot;someNameHere&quot;,
      &quot;mountPath&quot;: &quot;&lt;somePathHere&gt;&quot;
    }
  ]
}
</code></pre>
<p>A volume mount specifies a volume to mounted on the specified file system location inside the container. Whether you read or write to that volume is entirely up to the applications running inside the container. Whether you can read or write is governed by file permissions like on any mount.</p>
<p>Whether or not changes are propagated to other containers sharing the same mount depends on the <a href="http://kubernetes.io/docs/concepts/storage/volumes/#mount-propagation" rel="nofollow noreferrer">mount propagation settings</a>. Default is <code>None</code> in which case they will not.</p>
