Skip to content

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.

  1. If a Deployment created no pods, look at the ReplicaSet’s events: kubectl describe rs -l app=web -n <ns>.
  2. Check the namespace’s level: kubectl get ns <ns> --show-labels and look for pod-security.kubernetes.io/enforce.

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.