Interview Prep/DevSecOps/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`

BeginnerTroubleshootingKubernetes admission control and Pod Security
Answer

Likely causes → A Kyverno ClusterPolicy in Enforce mode requires runAsNonRoot: true and the Deployment does not set it.

Diagnose →

kubectl get clusterpolicy require-run-as-nonroot -o yaml | yq '.spec.rules[].validate'
kyverno apply policies/require-run-as-nonroot.yaml -r deploy.yaml

Fix → Set the securityContext at pod level (runAsNonRoot: true, runAsUser: 10001) and make sure the image actually runs as a non-root UID.

Prevent → Run kyverno apply against rendered manifests in CI so developers see the same message before deploy.

All DevSecOps questions Roadmap: Policy as code

More on Kubernetes admission control and Pod Security