liveBook · Manning

Subpath

As explained in Kubernetes in Action, Second Edition

SubPath is a Kubernetes volume-mount field that selects a file or subdirectory within a volume for mounting.

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

How Kubernetes in Action, Second Edition covers it

How deep it goes
Explains selection and masking with a manifest example, but defers deeper volume-mount behavior and lifecycle details.
Examples
Demonstrates mounting my-app.conf at /etc/my-app.conf from a ConfigMap volume.
What it assumes
Assumes familiarity with volumes, volume mounts, container paths, and ConfigMaps.
What you can do after
Operate/configure Kubernetes volumeMounts to expose selected volume content while preserving unrelated container files.
How it connects
Connects subPath with volume mounts, ConfigMap volumes, subPathExpr, Downward API, and shared volumes.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kubernetes in Action, Second Edition. The section links point to the parts of the book it draws on.