subPath selects one file or subdirectory inside a volume and mounts that item at a chosen container path. This lets containers share a volume without mounting its entire contents. section 9.2.1
Mount one configuration file
A ConfigMap volume containing my-app.conf can mount only that file at /etc/my-app.conf, leaving the container's other /etc files visible. section 9.5.2
Listing 9.12 Mounting an individual file into a container
spec:
containers:
- name: my-container
volumeMounts:
- name: my-volume
subPath: my-app.conf #1
mountPath: /etc/my-app.conf #2
Inspect the manifest showing subPath: my-app.conf paired with mountPath: /etc/my-app.conf. section 9.5.2
Use subPath when:
- A volume contains several directories that should be mounted at different locations or into different containers. section 9.2.1
- Mounting the complete volume at a directory would hide files already supplied by the container image. section 9.5.2
- Use subPathExpr instead when each pod replica needs a directory named from a Downward API environment variable. section 9.2.1
