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.
More on Kubernetes admission control and Pod Security
`Error from server: admission webhook "validate.kyverno.svc-fail" denied the request: policy Deployment/prod/api for resource violation: require-run-as-nonroot`BeginnerPods do not appear, but `kubectl apply` of the Deployment succeededBeginner`pods "api-7d9" is forbidden: violates PodSecurity "restricted:latest": allowPrivilegeEscalation != false, unrestricted capabilities, seccompProfile`BeginnerEnabling `enforce=restricted` on a namespace did not evict the existing non-compliant podsBeginner`Error from server (InternalError): Internal error occurred: failed calling webhook "validation.gatekeeper.sh": ... context deadline exceeded` blocks every deployIntermediateKyverno is down and now the whole cluster, including Kyverno's own namespace, cannot be fixed because writes are rejectedAdvanced