Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between subPath and mountPath in Kubernetes

Tags:

kubernetes

I am trying to add files in volumeMounts to .dockerignore and trying to understand the difference between subPath and mountPath. Reading official documentation isn't clear to me.

I should add from what I read mountPath is the directory in the pod where volumes will be mounted.

from official documentation: "subPath The volumeMounts.subPath property specifies a sub-path inside the referenced volume instead of its root." https://kubernetes.io/docs/concepts/storage/volumes/#using-subpath (this part isn't clear)

- mountPath: /root/test.pem
            name: test-private-key
            subPath: test.testing.com.key

In this example should I include both test.pem and test.testing.com.key to dockerignore?

like image 989
girlcoder1 Avatar asked Dec 21 '20 20:12

girlcoder1


1 Answers

mountPath shows where the referenced volume should be mounted in the container. For instance, if you mount a volume to mountPath: /a/b/c, the volume will be available to the container under the directory /a/b/c.

Mounting a volume will make all of the volume available under mountPath. If you need to mount only part of the volume, such as a single file in a volume, you use subPath to specify the part that must be mounted. For instance, mountPath: /a/b/c, subPath: d will make whatever d is in the mounted volume under directory /a/b/c

like image 124
Burak Serdar Avatar answered Sep 28 '22 08:09

Burak Serdar