`pods "api-7d9" is forbidden: violates PodSecurity "restricted:latest": allowPrivilegeEscalation != false, unrestricted capabilities, seccompProfile`
BeginnerTroubleshootingKubernetes admission control and Pod Security
Answer
Likely causes → The namespace has pod-security.kubernetes.io/enforce=restricted and the pod spec misses required fields.
Diagnose →
kubectl get ns prod --show-labels
kubectl label --dry-run=server --overwrite ns prod pod-security.kubernetes.io/enforce=restricted
Fix →
securityContext:
runAsNonRoot: true
seccompProfile: { type: RuntimeDefault }
containers:
- name: api
securityContext:
allowPrivilegeEscalation: false
capabilities: { drop: ["ALL"] }
Prevent → Roll out PSA with warn and audit labels before enforce.
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 succeededBeginnerEnabling `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