Interview Prep/Kubernetes/Storage and volumes

Postgres in a Pod fails with `initdb: error: could not change permissions of directory "/var/lib/postgresql/data/pgdata": Operation not permitted` on a new PVC.

IntermediateTroubleshootingStorage and volumes
Answer

Likely causes → The volume root is owned by root, and the container runs as a non-root UID that cannot write or chown it.

Diagnose →

kubectl exec db-0 -- id
kubectl exec db-0 -- ls -ld /var/lib/postgresql/data

Fix → Let the kubelet set group ownership with fsGroup, and avoid slow recursive chown on large volumes:

securityContext:
  runAsUser: 999
  fsGroup: 999
  fsGroupChangePolicy: OnRootMismatch

Point PGDATA at a subdirectory, not the mount root (which contains lost+found).

Prevent → Standard securityContext for stateful charts; test on an empty PVC.

All Kubernetes questions Roadmap: Kubernetes networking, storage & scaling

More on Storage and volumes