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
