Interview Prep/Kubernetes/Pod startup failures

`CreateContainerConfigError: Error: container has runAsNonRoot and image will run as root`.

IntermediateTroubleshootingPod startup failures
Answer

Likely causes → securityContext.runAsNonRoot: true (often enforced by the restricted Pod Security profile) but the image has no USER, or uses a named user (USER app) that the kubelet cannot verify is non-root.

Diagnose →

kubectl get pod web-x -o jsonpath='{.spec.securityContext}{"\n"}{.spec.containers[0].securityContext}'
docker inspect --format '{{.Config.User}}' registry.example.com/web:1.4

Fix → Set a numeric user in the Dockerfile (USER 10001) or in the Pod spec:

securityContext:
  runAsNonRoot: true
  runAsUser: 10001

Make sure files the app writes are owned by or writable for that UID.

Prevent → Standard base images with a numeric non-root user and a CI check (Trivy/Conftest) that fails images running as root.

All Kubernetes questions Roadmap: Kubernetes core

More on Pod startup failures