CKAD field manual

k8s emptyDir YAML example

Mount storage into a container. Same name in volumes[] and volumeMounts[].

A satchel on the ship dies with it; the warehouse of crates stays. A satchel on the ship dies with it; the warehouse of crates stays.
emptyDir
apiVersion: v1
kind: Pod
metadata:
  name: share
spec:
  containers:
    - name: writer
      image: busybox:1.36
      command: ["sh", "-c", "echo hi > /data/out; sleep 3600"]
      volumeMounts:
        - name: cache
          mountPath: /data
    - name: reader
      image: busybox:1.36
      command: ["sh", "-c", "cat /data/out; sleep 3600"]
      volumeMounts:
        - name: cache
          mountPath: /data
  volumes:
    - name: cache
      emptyDir: {}
PVC
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: data
  namespace: default
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
Pod + PVC
apiVersion: v1
kind: Pod
metadata:
  name: app
spec:
  containers:
    - name: app
      image: nginx:1.27
      volumeMounts:
        - name: data
          mountPath: /usr/share/nginx/html
  volumes:
    - name: data
      persistentVolumeClaim:
        claimName: data
Inspect
kubectl get pvc,pv
kubectl describe pvc data
kubectl exec app -- ls /usr/share/nginx/html

Fields

emptyDir
Lives with the Pod. Survives a container crash. Gone when the Pod is.
volumeMounts
name must equal a volumes[].name. Typo → mount is empty.
claimName
The PVC name, not the PV.

Watch

  • volumes[].name must equal volumeMounts[].name. claimName is the PVC, not the PV.
  • emptyDir survives a container crash. It is wiped when the Pod leaves the node.
  • A PVC is namespaced. Omit storageClassName to use the default StorageClass.

Official docs Volumes Persistent Volumes

Practice these objects on a live cluster →