Interview Prep/DevSecOps/Kubernetes admission control and Pod Security

Pod creation fails with `container has runAsNonRoot and image will run as root`

BeginnerTroubleshootingKubernetes admission control and Pod Security
Answer

Likely causes → The kubelet check: the pod requires non-root but the image has no numeric USER (or USER root), and no runAsUser is set.

Diagnose →

kubectl describe pod api-7d9 | grep -A3 "Error"
docker inspect --format '{{.Config.User}}' ghcr.io/acme/api:1.4

Fix → Add USER 10001 (numeric) in the Dockerfile, or set runAsUser: 10001 and ensure file permissions allow that UID.

Prevent → Lint Dockerfiles for a numeric non-root USER.

All DevSecOps questions Roadmap: Policy as code

More on Kubernetes admission control and Pod Security