liveBook · Manning

Mountpath

As explained in Kubernetes in Action, Second Edition

MountPath is a Kubernetes container volume-mount field that specifies the path where a volume is mounted in the container filesystem.

mountPath specifies the path inside a container where a named volume is mounted. The volume must first be defined in the Pod, then referenced in the container’s volumeMounts array. section 9.2.1

Mount MongoDB data at /data/db

A MongoDB container mounts the Pod volume named quiz-data at /data/db, directing database files to the volume instead of the container filesystem. section 9.2.1

Listing 9.2 The quiz pod with an emptyDir volume for the mongo container
apiVersion: v1
kind: Pod
metadata:
  name: quiz
spec:
  volumes:               #1
  - name: quiz-data      #1
    emptyDir: {}         #1
  containers:
  - name: quiz-api
    image: luksa/quiz-api:0.1
    ports:
    - name: http
      containerPort: 8080
  - name: mongo
    image: mongo
    volumeMounts:             #2
    - name: quiz-data         #2
      mountPath: /data/db     #2

Inspect the complete Pod manifest showing the volume definition, volumeMounts entry, matching volume name, and /data/db mountPath. section 9.2.1

Related mount settings provide additional control:

  • readOnly controls whether the volume is mounted read-only; recursiveReadOnly can extend that behavior to subpaths. section 9.2.1
  • subPath and subPathExpr mount selected directories, including separate replica directories from a shared volume. section 9.2.1

How Kubernetes in Action, Second Edition covers it

How deep it goes
Explains the field, required volume-name relationship, MongoDB example, and related mount options without detailing implementation internals.
Examples
Demonstrates an emptyDir volume mounted into MongoDB at /data/db within a quiz Pod.
What it assumes
Assumes basic Pod and container definitions while establishing that volumes require both a Pod definition and a container mount.
What you can do after
Operate/configure a Pod manifest by mounting a named volume at the application’s required container path.
How it connects
Connects mountPath with volumes, volumeMounts, containers, Pods, emptyDir, readOnly, subPath, and subPathExpr.

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.