Built-in admission control with nothing extra to install: three named profiles enforced by Kubernetes' Pod Security admission controller and driven entirely by namespace labels. It's less expressive than Kyverno or Gatekeeper, and that simplicity is the whole point.
make up secOrientation
Lock down what each profile requires and how the labels work, and PSS turns into the fastest points on the exam. PSS replaced PodSecurityPolicy (removed in 1.25), so if a scenario brings up PSP, the answer is straightforward: it's gone, use PSS for pod hardening and a policy engine for anything PSS can't express.
Profiles and modes
| Profile | Blocks / requires | Use for |
|---|---|---|
| privileged | Nothing: completely unrestricted | System namespaces, CNIs, storage drivers |
| baseline | Blocks known-dangerous settings: privileged containers, hostNetwork/hostPID/hostIPC, hostPath volumes, added capabilities outside a safe list, unconfined seccomp/AppArmor, host ports | The sane default for tenant namespaces |
| restricted | Requires active hardening: runAsNonRoot, allowPrivilegeEscalation: false, all capabilities dropped (ALL, with NET_BIND_SERVICE allowed back), seccompProfile: RuntimeDefault, no hostPath, restricted volume types | Every workload you can make comply |
The one-liner to remember: baseline stops you from being dangerous; restricted forces you to be safe.
You set the three modes independently on each namespace: enforce rejects pods at admission, audit writes violations into the audit log, and warn prints warnings back to the client. Here's the label grammar:
pod-security.kubernetes.io/enforce: baseline
pod-security.kubernetes.io/enforce-version: v1.31 # pin, or "latest"
pod-security.kubernetes.io/warn: restricted
pod-security.kubernetes.io/audit: restrictedVersion pinning matters more than it looks: PSS profiles tighten across Kubernetes releases, so leaving a namespace on latest means a routine cluster upgrade can suddenly start blocking pods that deployed fine yesterday. Pinning trades that surprise for a deliberate migration.
Tweak a pod spec and watch all three profiles react:
team-a runs enforce baseline, warn and audit restricted. Nothing overtly dangerous gets admitted, while every restricted violation surfaces to both the developer (as a kubectl warning) and the platform team (in the audit log) well before anyone flips the enforce switch. That staged rollout mirrors the Audit → Enforce choreography from 5.2, and it generalizes to every control in this domain.
The profiles at field level
Every PSS rejection explicitly names the violated controls (privileged, hostPath volumes, allowPrivilegeEscalation != false, unrestricted capabilities, runAsNonRoot != true, seccompProfile). Knowing which YAML field backs each control turns an error message into a ten-second fix.
| Control | Field(s), on pod and every container (containers, initContainers, ephemeralContainers) | Baseline | Restricted adds |
|---|---|---|---|
| Host namespaces | spec.hostNetwork, hostPID, hostIPC | Must be false or unset | Same |
| Privileged | securityContext.privileged | False or unset | Same |
| Capabilities | securityContext.capabilities.add / drop | add only from: AUDIT_WRITE, CHOWN, DAC_OVERRIDE, FOWNER, FSETID, KILL, MKNOD, NET_BIND_SERVICE, SETFCAP, SETGID, SETPCAP, SETUID, SYS_CHROOT | drop: ["ALL"] required; add may only include NET_BIND_SERVICE |
| HostPath volumes | spec.volumes[*].hostPath | Forbidden | Same |
| Host ports | containers[*].ports[*].hostPort | Unset or 0 | Same |
| AppArmor | securityContext.appArmorProfile.type | RuntimeDefault, Localhost, or unset; never Unconfined | Same |
| SELinux | securityContext.seLinuxOptions.type / user / role | Type in container_t, container_init_t, container_kvm_t, container_engine_t or unset; user and role must stay unset | Same |
| /proc mount | securityContext.procMount | Default or unset | Same |
| Seccomp | securityContext.seccompProfile.type | Not Unconfined (unset is allowed) | Must be explicitly set to RuntimeDefault or Localhost at pod level or on every container |
| Sysctls | spec.securityContext.sysctls[*].name | Only the safe set (kernel.shm_rmid_forced, net.ipv4.ip_local_port_range, net.ipv4.tcp_syncookies, net.ipv4.ping_group_range, net.ipv4.ip_unprivileged_port_start, and a few others) | Same |
| Volume types | spec.volumes[*] | Anything except hostPath | Only configMap, csi, downwardAPI, emptyDir, ephemeral, persistentVolumeClaim, projected, secret |
| Privilege escalation | containers[*].securityContext.allowPrivilegeEscalation | n/a | Must be false on every container (Linux pods) |
| Non-root | securityContext.runAsNonRoot; runAsUser | n/a | runAsNonRoot: true at pod level or on every container; runAsUser must not be 0 if set |
| Windows HostProcess | securityContext.windowsOptions.hostProcess | False or unset | Same |
- Pod level vs container level.
runAsNonRoot,runAsUser,seccompProfile,appArmorProfile, andseLinuxOptionscan live onspec.securityContextand flow down to containers (which can still override them). By contrast,allowPrivilegeEscalation,capabilities,privileged,procMount, andreadOnlyRootFilesystemexist only per container. When an error calls out "container x", check the container block; when it says "pod or container", pod-level fixes everything at once. - What restricted does not require.
readOnlyRootFilesystem, resource limits, and a non-rootfsGrouparen't part of PSS. If a task demands those, you're looking at a policy engine rule or a hardened manifest, not PSS. - Images built to run as root. Setting
runAsNonRoot: trueon an image whose defaultUSERis root passes admission fine and then fails at container startup withcontainer has runAsNonRoot and image will run as root(aCreateContainerConfigError). Fix it by settingrunAsUser: 1000(and usuallyrunAsGroup), or switching to a non-root image. - Ephemeral containers count too. Running
kubectl debuginside a restricted namespace fails unless you add--profile=restricted, because the injected debug container has to satisfy the same profile.
When a pod gets rejected, split the error message on commas: each clause maps to one row above and tells you which container failed. Fix all of them in a single edit. PSS reports every violation at once, so your second apply should go through cleanly.
Two operational facts that decide troubleshooting tasks
- PSS enforces on pods. A Deployment with a violating pod template gets created with zero errors, and then silently fails to spawn pods. The actual rejection lives on the ReplicaSet, one level below where you looked first (same indirection as ResourceQuota in 1.4). Spotting that pattern immediately is worth more than memorizing any single profile rule.
- Enforcement only fires at admission. Tightening a namespace label never evicts pods that are already running; they keep going until their next write or rollout. That's why Kubernetes gives you a built-in preview command:
kubectl label --dry-run=server --overwrite ns <ns> pod-security.kubernetes.io/enforce=restrictedoutputcaptured 2026-08-26
(a merely-baseline pod, lazy from the first exercise, is running in team-b for this preview)
$ kubectl label --dry-run=server --overwrite ns team-b pod-security.kubernetes.io/enforce=restricted
Warning: existing pods in namespace "team-b" violate the new PodSecurity enforce level "restricted:latest"
Warning: lazy: allowPrivilegeEscalation != false, unrestricted capabilities, runAsNonRoot != true, seccompProfile
namespace/team-b labeled (server dry run)The API server checks every existing pod against the proposed profile and warns you about each one that would fail, without changing a thing. It's the single handiest PSS command to keep in muscle memory, turning a risky policy tightening into a predictable migration.
What a compliant pod looks like
securityContext: # pod level
runAsNonRoot: true
runAsUser: 1000
seccompProfile: { type: RuntimeDefault }
containers:
- name: app
securityContext: # container level
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true # not required by restricted, but good practice
capabilities: { drop: ["ALL"] }The demo app's manifest (examples/demo-app/base/deployment.yaml) gives you a live working example of a restricted-compliant pod. Read its securityContext blocks closely, since writing this exact stanza from memory is fair game on the exam. Notice the split: runAsNonRoot and seccompProfile fit naturally at pod level, while capabilities and allowPrivilegeEscalation belong on each container.
PSS is built-in, zero-ops, and laser-focused on pod hardening. A policy engine is installable, flexible, and handles everything else (allowed registries, required labels, ownership, cross-object rules) at the cost of running a webhook. The mature answer to "which one?" is both: use PSS as the always-on baseline floor and a policy engine for organization-specific rules (or for namespaces where you need fine-grained exceptions PSS can't express).
Cluster-wide defaults, exemptions, and newer knobs
Defaults and exemptions live on the API server
Namespace labels handle the per-namespace layer. For cluster-wide defaults and exemptions, configure the PodSecurity admission plugin and pass it to kube-apiserver via --admission-control-config-file:
apiVersion: apiserver.config.k8s.io/v1
kind: AdmissionConfiguration
plugins:
- name: PodSecurity
configuration:
apiVersion: pod-security.admission.config.k8s.io/v1
kind: PodSecurityConfiguration
defaults: # applied to namespaces with no label for that mode
enforce: baseline
enforce-version: latest
audit: restricted
audit-version: latest
warn: restricted
warn-version: latest
exemptions:
usernames: [] # authenticated or impersonated users
runtimeClasses: [kata] # pods with this runtimeClassName
namespaces: [kube-system] # whole namespaces- A namespace label always overrides the cluster default for that mode; defaults only fill in what a namespace didn't specify. So "every new namespace must enforce at least baseline" is solved with this config file (or, on a managed control plane where you can't touch API server flags, with a policy engine that stamps labels onto new namespaces).
- Exempt requests bypass all three modes. Exempting a username only exempts objects that user creates directly, not pods a controller creates for them. That's why Kubernetes explicitly warns against exempting controller ServiceAccounts like the ReplicaSet controller: doing so would accidentally exempt everyone who can create a Deployment.
- Watch
pod_security_evaluations_totalandpod_security_exemptions_totalon the API server to track how often each mode triggers; a spike indecision="deny"right after a label change is your immediate rollout signal.
Workload resources and updates
warn and audit evaluate Deployments, StatefulSets, Jobs, and other pod-template controllers directly, so the person running kubectl apply sees the warning right away. enforce only evaluates the resulting pods, which is why violating Deployments fail one level down on the ReplicaSet. Pod updates that only touch metadata (other than seccomp or AppArmor annotations), activeDeadlineSeconds, or tolerations skip re-evaluation. Anything that spawns a new pod, including a Deployment rollout, runs through full admission, which is when a newly tightened label first hits an existing app. Use kubectl label --dry-run=server to preview a namespace tightening, and kubectl apply --dry-run=server on a workload to preview its warnings before creating anything.
Newer knobs that change what "compliant" means
- User namespaces (GA in 1.36). Setting
spec.hostUsers: falsemaps container UIDs to unprivileged host UIDs, so UID 0 inside the container isn't root on the host node. It requires a Linux 6.3+ kernel with idmap mount support across every filesystem the pod uses (including tmpfs), containerd 2.0+ or CRI-O, and runc 1.2+ or crun 1.9+. It's Linux-only and doesn't apply tohostPathor host namespaces. PSS still evaluates the pod normally; user namespaces add defense in depth underneath it. - AppArmor (GA in 1.30). Configure it via
securityContext.appArmorProfile: { type: RuntimeDefault | Localhost | Unconfined, localhostProfile: name }. The oldcontainer.apparmor.security.beta.kubernetes.io/<container>annotation is deprecated and gets rejected if it conflicts with the field. Baseline checks this field directly. - Seccomp.
RuntimeDefaultuses your container runtime's default profile, whileLocalhostreadslocalhostProfilerelative to the kubelet's/var/lib/kubelet/seccomp/directory on each node. Passing--seccomp-default(orseccompDefault: trueinKubeletConfiguration) appliesRuntimeDefaultfleet-wide to pods that omit seccomp, though keep in mind PSS inspects the pod spec at admission rather than the kubelet's runtime default, so restricted still insists the field is written in the spec. - PodSecurityPolicy was removed back in 1.25. If a task hands you a
policy/v1beta1 PodSecurityPolicymanifest, treat it as a trap and answer with PSS labels plus a policy engine.
"Make namespace X enforce restricted without breaking existing workloads" means: preview with --dry-run=server, fix the fields the warnings call out (usually allowPrivilegeEscalation, capabilities.drop, runAsNonRoot, and seccompProfile), and then apply the label with a pinned enforce-version. "Allow one system workload that needs hostPath in an otherwise restricted cluster" means an exemption by namespace or a dedicated privileged namespace, never a per-pod exception, because PSS doesn't have those.
Exercises
In team-a (enforce: baseline):
kubectl -n team-a run priv --image=busybox:1.37 --restart=Never \
--overrides='{"spec":{"containers":[{"name":"priv","image":"busybox:1.37","command":["sleep","300"],"securityContext":{"privileged":true}}]}}'outputcaptured 2026-08-26
$ kubectl -n team-a run priv --image=busybox:1.37 --restart=Never \
--overrides='{"spec":{"containers":[{"name":"priv","image":"busybox:1.37","command":["sleep","300"],"securityContext":{"privileged":true}}]}}'
Error from server (Forbidden): pods "priv" is forbidden: violates PodSecurity "baseline:latest": privileged (container "priv" must not set securityContext.privileged=true)Now run a bare, unhardened pod (kubectl -n team-a run lazy --image=busybox:1.37 --restart=Never -- sleep 300) and read the warnings printed back: admitted under baseline, flagged against restricted by the warn label.
Create a namespace called hardened enforcing restricted. Take the lazy pod spec and harden it until it passes: runAsNonRoot: true (busybox also needs an explicit runAsUser, like 1000), allowPrivilegeEscalation: false, capabilities.drop: ["ALL"], and seccompProfile.type: RuntimeDefault. Let the live rejection messages guide your edits; they list every missing control, making PSS pleasantly self-documenting during the exam.
hardened, and your final securityContext matches the demo app's pattern.In hardened, run kubectl -n hardened create deploy sneaky --image=busybox:1.37 -- sleep 300. The Deployment succeeds, yet no pod ever starts. Track the denial down to where it actually lives:
kubectl -n hardened get deploy sneaky # READY 0/1, no error here
kubectl -n hardened describe rs -l app=sneaky | tail -5outputcaptured 2026-08-26
$ kubectl -n hardened get deploy sneaky # READY 0/1, no error here
NAME READY UP-TO-DATE AVAILABLE AGE
sneaky 0/1 0 0 11s
$ kubectl -n hardened describe rs -l app=sneaky | tail -5
Warning FailedCreate 11s replicaset-controller Error creating: pods "sneaky-595c4bc9c7-bs46b" is forbidden: violates PodSecurity "restricted:latest": allowPrivilegeEscalation != false (container "busybox" must set securityContext.allowPrivilegeEscalation=false), unrestricted capabilities (container "busybox" must set securityContext.capabilities.drop=["ALL"]), runAsNonRoot != true (pod or container "busybox" must set securityContext.runAsNonRoot=true), seccompProfile (pod or container "busybox" must set securityContext.seccompProfile.type to "RuntimeDefault" or "Localhost")
Warning FailedCreate 11s replicaset-controller Error creating: pods "sneaky-595c4bc9c7-df7n2" is forbidden: violates PodSecurity "restricted:latest": allowPrivilegeEscalation != false (container "busybox" must set securityContext.allowPrivilegeEscalation=false), unrestricted capabilities (container "busybox" must set securityContext.capabilities.drop=["ALL"]), runAsNonRoot != true (pod or container "busybox" must set securityContext.runAsNonRoot=true), seccompProfile (pod or container "busybox" must set securityContext.seccompProfile.type to "RuntimeDefault" or "Localhost")
Warning FailedCreate 11s replicaset-controller Error creating: pods "sneaky-595c4bc9c7-v8xwt" is forbidden: violates PodSecurity "restricted:latest": allowPrivilegeEscalation != false (container "busybox" must set securityContext.allowPrivilegeEscalation=false), unrestricted capabilities (container "busybox" must set securityContext.capabilities.drop=["ALL"]), runAsNonRoot != true (pod or container "busybox" must set securityContext.runAsNonRoot=true), seccompProfile (pod or container "busybox" must set securityContext.seccompProfile.type to "RuntimeDefault" or "Localhost")
Warning FailedCreate 10s replicaset-controller Error creating: pods "sneaky-595c4bc9c7-z48jz" is forbidden: violates PodSecurity "restricted:latest": allowPrivilegeEscalation != false (container "busybox" must set securityContext.allowPrivilegeEscalation=false), unrestricted capabilities (container "busybox" must set securityContext.capabilities.drop=["ALL"]), runAsNonRoot != true (pod or container "busybox" must set securityContext.runAsNonRoot=true), seccompProfile (pod or container "busybox" must set securityContext.seccompProfile.type to "RuntimeDefault" or "Localhost")
Warning FailedCreate 1s (x3 over 9s) replicaset-controller (combined from similar events): Error creating: pods "sneaky-595c4bc9c7-pf2pl" is forbidden: violates PodSecurity "restricted:latest": allowPrivilegeEscalation != false (container "busybox" must set securityContext.allowPrivilegeEscalation=false), unrestricted capabilities (container "busybox" must set securityContext.capabilities.drop=["ALL"]), runAsNonRoot != true (pod or container "busybox" must set securityContext.runAsNonRoot=true), seccompProfile (pod or container "busybox" must set securityContext.seccompProfile.type to "RuntimeDefault" or "Localhost")Run kubectl label --dry-run=server --overwrite ns team-b pod-security.kubernetes.io/enforce=restricted and inspect which running pods would break.
audit label has been quietly logging all along.Pod Security lets this pod straight through because the spec is completely compliant. Then the kubelet refuses to start it, because the image's default user is root while the spec forbids root. That's why the failure lands in container status rather than at admission: the pod object gets created and then never starts.
kubectl create ns hardened --dry-run=client -o yaml | kubectl apply -f -
kubectl label ns hardened pod-security.kubernetes.io/enforce=restricted --overwrite
kubectl -n hardened apply -f - <<'EOF'
apiVersion: v1
kind: Pod
metadata: { name: rootimage }
spec:
securityContext:
runAsNonRoot: true
seccompProfile: { type: RuntimeDefault }
containers:
- name: c
image: nginx:1.27-alpine
securityContext:
allowPrivilegeEscalation: false
capabilities: { drop: ["ALL"] }
EOF
sleep 20
kubectl -n hardened get pod rootimage -o jsonpath='{.status.containerStatuses[0].state}' | jq
kubectl -n hardened describe pod rootimage | sed -n '/Events/,$p'
kubectl -n hardened delete pod rootimageoutputcaptured 2026-11-18
$ kubectl create ns hardened --dry-run=client -o yaml | kubectl apply -f -
namespace/hardened created
$ kubectl label ns hardened pod-security.kubernetes.io/enforce=restricted --overwrite
namespace/hardened labeled
$ kubectl -n hardened apply -f - <<'EOF'
apiVersion: v1
kind: Pod
metadata: { name: rootimage }
spec:
securityContext:
runAsNonRoot: true
seccompProfile: { type: RuntimeDefault }
containers:
- name: c
image: nginx:1.27-alpine
securityContext:
allowPrivilegeEscalation: false
capabilities: { drop: ["ALL"] }
EOF
pod/rootimage created
$ sleep 20
$ kubectl -n hardened get pod rootimage -o jsonpath='{.status.containerStatuses[0].state}' | jq
{
"waiting": {
"message": "container has runAsNonRoot and image will run as root (pod: \"rootimage_hardened(ea1bc5ba-ec01-4f25-8a09-2531b28d3296)\", container: c)",
"reason": "CreateContainerConfigError"
}
}
$ kubectl -n hardened describe pod rootimage | sed -n '/Events/,$p'
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning PolicyViolation 20s kyverno-admission policy require-resource-requests/validation fail: every container must set cpu and memory requests
Normal Scheduled 20s default-scheduler Successfully assigned hardened/rootimage to cnpe-worker
Normal Pulled 4s (x3 over 18s) kubelet spec.containers{c}: Container image "nginx:1.27-alpine" already present on machine and can be accessed by the pod
Warning Failed 4s (x3 over 18s) kubelet spec.containers{c}: Error: container has runAsNonRoot and image will run as root (pod: "rootimage_hardened(ea1bc5ba-ec01-4f25-8a09-2531b28d3296)", container: c)
$ kubectl -n hardened delete pod rootimage
pod "rootimage" deleted from hardened namespaceCreateContainerConfigError with an event stating that runAsNonRoot is set while the image will run as root.kubectl debug injects an ephemeral container, and that container faces the exact same admission checks as every other container. Inside a restricted namespace, the default debug container gets rejected, and --profile=restricted is the flag most people don't know exists.
kubectl -n hardened run target --image=ghcr.io/nginxinc/nginx-unprivileged:1.27-alpine --restart=Never --overrides='{"spec":{"securityContext":{"runAsNonRoot":true,"seccompProfile":{"type":"RuntimeDefault"}},"containers":[{"name":"target","image":"ghcr.io/nginxinc/nginx-unprivileged:1.27-alpine","securityContext":{"allowPrivilegeEscalation":false,"capabilities":{"drop":["ALL"]}}}]}}'
kubectl -n hardened wait --for=condition=Ready pod/target --timeout=120s
kubectl -n hardened debug target --image=busybox:1.36 --target=target -- true
kubectl -n hardened debug target --image=busybox:1.36 --target=target --profile=restricted -- true
kubectl -n hardened get pod target -o jsonpath='{range .spec.ephemeralContainers[*]}{.name} {.securityContext.allowPrivilegeEscalation} {.securityContext.capabilities.drop}{"\n"}{end}'
sleep 10
kubectl -n hardened get pod target -o json | jq -r '.status.ephemeralContainerStatuses[]? | "\(.name) \(.state|keys[0])"'
kubectl -n hardened delete pod targetoutputcaptured 2026-09-13
$ kubectl -n hardened run target --image=ghcr.io/nginxinc/nginx-unprivileged:1.27-alpine --restart=Never --overrides='{"spec":{"securityContext":{"runAsNonRoot":true,"seccompProfile":{"type":"RuntimeDefault"}},"containers":[{"name":"target","image":"ghcr.io/nginxinc/nginx-unprivileged:1.27-alpine","securityContext":{"allowPrivilegeEscalation":false,"capabilities":{"drop":["ALL"]}}}]}}'
pod/target created
$ kubectl -n hardened wait --for=condition=Ready pod/target --timeout=120s
pod/target condition met
$ kubectl -n hardened debug target --image=busybox:1.36 --target=target -- true
Targeting container "target". If you don't see processes from this container it may be because the container runtime doesn't support this feature.
Defaulting debug container name to debugger-s56nq.
Error from server (Forbidden): pods "target" is forbidden: violates PodSecurity "restricted:latest": allowPrivilegeEscalation != false (container "debugger-s56nq" must set securityContext.allowPrivilegeEscalation=false), unrestricted capabilities (container "debugger-s56nq" must set securityContext.capabilities.drop=["ALL"]; container "debugger-s56nq" must not include "SYS_PTRACE" in securityContext.capabilities.add)
$ kubectl -n hardened debug target --image=busybox:1.36 --target=target --profile=restricted -- true
Targeting container "target". If you don't see processes from this container it may be because the container runtime doesn't support this feature.
Defaulting debug container name to debugger-67shh.
$ kubectl -n hardened get pod target -o jsonpath='{range .spec.ephemeralContainers[*]}{.name} {.securityContext.allowPrivilegeEscalation} {.securityContext.capabilities.drop}{"\n"}{end}'
debugger-67shh false ["ALL"]
$ sleep 10
$ kubectl -n hardened get pod target -o json | jq -r '.status.ephemeralContainerStatuses[]? | "\(.name) \(.state|keys[0])"'
debugger-67shh waiting
$ kubectl -n hardened delete pod target
pod "target" deleted from hardened namespace--profile=restricted goes right through. Inspecting the pod spec confirms the debug container carries allowPrivilegeEscalation: false and capabilities.drop: ["ALL"], generated for you by the profile. Check the spec rather than the status here: the kubelet populates ephemeralContainerStatuses a beat later, so an immediate status read may show waiting or nothing yet. Notice the profile only changes the debug container spec, never the namespace's policy.hostUsers: false maps container root to an unprivileged UID on the host, defanging a whole class of container escapes. Support depends on the host kernel and runtime, and inside this kind cluster it won't start: a kind node is itself a container, so the runtime refuses the mounts a nested user namespace needs. Seeing that refusal is the exercise, because it's the exact error you'll encounter on any cluster without user-namespace support.
kubectl -n default apply -f - <<'EOF'
apiVersion: v1
kind: Pod
metadata: { name: userns }
spec:
hostUsers: false
containers:
- name: c
image: busybox:1.36
command: ["sh", "-c", "sleep 600"]
EOF
sleep 30
kubectl -n default get pod userns -o jsonpath='{.status.phase} {.status.conditions[*].message}{"\n"}'
kubectl -n default get events --field-selector involvedObject.name=userns,reason=FailedCreatePodSandBox -o jsonpath='{range .items[*]}{.reason}: {.message}{"\n"}{end}' | tail -1
kubectl -n default exec userns -- cat /proc/self/uid_map
kubectl -n default exec userns -- id
kubectl -n default delete pod usernsoutputcaptured 2026-11-18
$ kubectl -n default apply -f - <<'EOF'
apiVersion: v1
kind: Pod
metadata: { name: userns }
spec:
hostUsers: false
containers:
- name: c
image: busybox:1.36
command: ["sh", "-c", "sleep 600"]
EOF
pod/userns created
$ sleep 30
$ kubectl -n default get pod userns -o jsonpath='{.status.phase} {.status.conditions[*].message}{"\n"}'
Pending no pod sandbox exists containers with unready status: [c] containers with unready status: [c]
$ kubectl -n default get events --field-selector involvedObject.name=userns,reason=FailedCreatePodSandBox -o jsonpath='{range .items[*]}{.reason}: {.message}{"\n"}{end}' | tail -1
FailedCreatePodSandBox: Failed to create pod sandbox: rpc error: code = Unknown desc = failed to start sandbox "cc4756c58ce6e33dcde4c9a6536a43339c2c0a971b3ace9f2acbc19db0c39503": failed to create containerd task: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error mounting "sysfs" to rootfs at "/sys": mount src=sysfs, dst=/sys, dstFd=/proc/thread-self/fd/11, flags=MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC: operation not permitted
$ kubectl -n default exec userns -- cat /proc/self/uid_map
error: unable to upgrade connection: container not found ("c")
$ kubectl -n default exec userns -- id
error: unable to upgrade connection: container not found ("c")
$ kubectl -n default delete pod userns
pod "userns" deleted from default namespacePending with containers with unready status: [c], and the sandbox event reports FailedCreatePodSandBox ... error mounting "sysfs" to rootfs at "/sys": ... operation not permitted. That's the container runtime refusing, not the API server: admission accepted hostUsers: false, so the follow-up exec fails with container not found rather than anything mentioning user namespaces. On a cluster that does support it, cat /proc/self/uid_map inside the pod maps container UID 0 to a high unprivileged host UID instead of 0, which is the verification check to keep in mind.warn and audit labels let you see everything restricted would block long before you enforce it. A server-side dry run asks that same question for a single manifest at zero cost.
kubectl create ns warnzone --dry-run=client -o yaml | kubectl apply -f -
kubectl label ns warnzone pod-security.kubernetes.io/warn=restricted pod-security.kubernetes.io/audit=restricted --overwrite
kubectl -n warnzone apply --dry-run=server -f - <<'EOF'
apiVersion: apps/v1
kind: Deployment
metadata: { name: legacy-app }
spec:
replicas: 1
selector: { matchLabels: { app: legacy-app } }
template:
metadata: { labels: { app: legacy-app } }
spec:
containers:
- name: c
image: nginx:1.27-alpine
EOF
kubectl -n warnzone apply -f - <<'EOF'
apiVersion: apps/v1
kind: Deployment
metadata: { name: legacy-app }
spec:
replicas: 1
selector: { matchLabels: { app: legacy-app } }
template:
metadata: { labels: { app: legacy-app } }
spec:
containers:
- name: c
image: nginx:1.27-alpine
EOF
kubectl -n warnzone get deploy legacy-app
kubectl delete ns warnzoneoutputcaptured 2026-09-12
$ kubectl create ns warnzone --dry-run=client -o yaml | kubectl apply -f -
namespace/warnzone created
$ kubectl label ns warnzone pod-security.kubernetes.io/warn=restricted pod-security.kubernetes.io/audit=restricted --overwrite
namespace/warnzone labeled
$ kubectl -n warnzone apply --dry-run=server -f - <<'EOF'
apiVersion: apps/v1
kind: Deployment
metadata: { name: legacy-app }
spec:
replicas: 1
selector: { matchLabels: { app: legacy-app } }
template:
metadata: { labels: { app: legacy-app } }
spec:
containers:
- name: c
image: nginx:1.27-alpine
EOF
Warning: would violate PodSecurity "restricted:latest": allowPrivilegeEscalation != false (container "c" must set securityContext.allowPrivilegeEscalation=false), unrestricted capabilities (container "c" must set securityContext.capabilities.drop=["ALL"]), runAsNonRoot != true (pod or container "c" must set securityContext.runAsNonRoot=true), seccompProfile (pod or container "c" must set securityContext.seccompProfile.type to "RuntimeDefault" or "Localhost")
deployment.apps/legacy-app created (server dry run)
$ kubectl -n warnzone apply -f - <<'EOF'
apiVersion: apps/v1
kind: Deployment
metadata: { name: legacy-app }
spec:
replicas: 1
selector: { matchLabels: { app: legacy-app } }
template:
metadata: { labels: { app: legacy-app } }
spec:
containers:
- name: c
image: nginx:1.27-alpine
EOF
Warning: would violate PodSecurity "restricted:latest": allowPrivilegeEscalation != false (container "c" must set securityContext.allowPrivilegeEscalation=false), unrestricted capabilities (container "c" must set securityContext.capabilities.drop=["ALL"]), runAsNonRoot != true (pod or container "c" must set securityContext.runAsNonRoot=true), seccompProfile (pod or container "c" must set securityContext.seccompProfile.type to "RuntimeDefault" or "Localhost")
deployment.apps/legacy-app created
$ kubectl -n warnzone get deploy legacy-app
NAME READY UP-TO-DATE AVAILABLE AGE
legacy-app 0/1 0 0 0s
$ kubectl delete ns warnzone
namespace "warnzone" deletedSelf-check
Name the three profiles in one clause each.
Privileged: completely unrestricted. Baseline: blocks known privilege escalations (privileged containers, host namespaces, hostPath, unsafe capabilities). Restricted: actively requires non-root, allowPrivilegeEscalation: false, all capabilities dropped, and RuntimeDefault (or Localhost) seccomp.
A Deployment is created and no pods appear. Where is the PSS error?
On the ReplicaSet. Because PSS enforces at the pod level, the Deployment succeeds and the ReplicaSet controller logs the rejection one level down. Check kubectl describe rs -l … or namespace events.
You want to know who breaks if you tighten a namespace. Command?
kubectl label --dry-run=server --overwrite ns <ns> pod-security.kubernetes.io/enforce=restricted. The API server evaluates every running pod against the proposed label and prints a warning for each offender without modifying anything.
Why pin enforce-version?
Because PSS profiles gain stricter checks across Kubernetes releases. Leaving it on latest means a routine cluster upgrade can start rejecting pods that deployed cleanly before. Pinning turns that into a scheduled migration instead of a surprise outage.
PSS or Kyverno for "images must come from our registry"?
Kyverno (or Gatekeeper). PSS only covers the fixed pod-hardening profile and knows nothing about image registries. Treat PSS as the always-on floor and run a policy engine alongside it for organization-specific rules.
A pod passes restricted admission and then sits in CreateContainerConfigError with container has runAsNonRoot and image will run as root. What happened?
Setting runAsNonRoot: true satisfied PSS at admission, but the container image's default user is root, so the kubelet refused to launch it. Set runAsUser (and runAsGroup) to a non-zero UID, or switch to an image built with a non-root USER. Remember: PSS checks the pod spec; the kubelet checks the image.
How do you make every namespace without labels enforce baseline and warn on restricted, cluster-wide, and what does a namespace label do to that default?
Configure an AdmissionConfiguration containing a PodSecurityConfiguration whose defaults set enforce: baseline and warn: restricted (with versions), and pass it to kube-apiserver via --admission-control-config-file. Any namespace label overrides the default for that mode only. On a managed cluster where you can't touch API server flags, use a policy engine to stamp those labels onto namespaces as they're created.
Restricted rejects a container for seccompProfile, yet the kubelet runs with seccompDefault: true. Why is that not enough?
PSS inspects the pod spec at admission, whereas the kubelet default only takes effect later at container creation and is invisible to admission control. Restricted requires seccompProfile.type to be explicitly set to RuntimeDefault or Localhost in the spec (at pod level or on every container). The kubelet flag is still worth enabling to cover pods in non-restricted namespaces.
Docs to know your way around
- kubernetes.io: Pod Security Standards (the profile tables; don't memorize the capability lists, just know where to look) and Enforce Pod Security Standards with Namespace Labels.
- Offline: the rejection messages themselves. Because PSS names every violated control, it's the most self-documenting admission mechanism in Kubernetes, backed up by
kubectl explain pod.spec.securityContext. - kubernetes.io/docs/concepts/security/pod-security-standards: the field-by-field reference tables; /docs/concepts/security/pod-security-admission for workload-resource behavior and exemptions.
- kubernetes.io/docs/tasks/configure-pod-container/enforce-standards-admission-controller: the
AdmissionConfigurationlayout; /docs/concepts/workloads/pods/user-namespaces forhostUsersand its kernel/runtime requirements.