`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.
More on Kubernetes admission control and Pod Security
Pods 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 rejectedAdvancedGatekeeper constraint is created but violations are not blocked; `kubectl get constraint` shows `TOTAL-VIOLATIONS: 12`Intermediate