Forbidden: violates PodSecurity
The namespace enforces a Pod Security Standard, and the pod spec breaks it. The pod is never created. For a Deployment, the error appears on the ReplicaSet, not on kubectl apply.
Diagnose
Section titled “Diagnose”- If a Deployment created no pods, look at the ReplicaSet’s events:
kubectl describe rs -l app=web -n <ns>. - Check the namespace’s level:
kubectl get ns <ns> --show-labelsand look forpod-security.kubernetes.io/enforce.
Fix the pod, not the namespace
Section titled “Fix the pod, not the namespace”A spec that passes restricted for most applications:
spec: securityContext: runAsNonRoot: true seccompProfile: { type: RuntimeDefault } containers: - name: web securityContext: allowPrivilegeEscalation: false capabilities: { drop: ['ALL'] }The image must also be able to run as a non-root user. If it needs root or port 80, rebuild it to run as a numeric user and listen on a high port.
Relabelling the namespace down to baseline or privileged makes the error go away by removing the control. In regulated environments, that needs a documented exception, not a quiet label change. On OpenShift, the equivalent mechanism is Security Context Constraints, and the default restricted-v2 SCC enforces similar rules.