- Pod-level security settings live under
spec.securityContext(commonly called the pod security context). Fields such asrunAsUser,fsGroup, andseLinuxOptionsset defaults that apply to every container in the Pod unless a container explicitly overrides them. - Container-level security settings belong under each container’s
securityContext(spec.containers[*].securityContext). Container-level settings take precedence and override equivalent Pod-level defaults.

securityContext that overrides runAsUser. Use kubectl apply -f to create the Pod, and inspect the applied values with:
kubectl get pod web-pod -o yamlkubectl describe pod web-pod
capabilities field modifies the set of Linux capabilities for the container. Note that Linux capabilities must be configured at the container level (containers[*].securityContext) — they are not supported in the Pod-level spec.securityContext.
Notes:
Pod-level
securityContext supports fields such as runAsUser, fsGroup, and seLinuxOptions. Linux capabilities (the capabilities field) must be configured at the container level under containers[*].securityContext.Granting capabilities such as
SYS_ADMIN is very powerful and can effectively grant broad privileges. Only add capabilities that are strictly necessary for the container workload, and follow the principle of least privilege.
Best practices
- Prefer setting minimally required privileges. Use
runAsNonRoot: truewhen possible and limitrunAsUserto unprivileged UIDs. - Apply Pod-level defaults for consistent baseline behavior across containers, and reserve container-level securityContext for exceptions.
- Avoid adding powerful capabilities (like
SYS_ADMIN) unless absolutely necessary. When you must add them, document why and scope them narrowly. - Use
readOnlyRootFilesystem: trueand drop unnecessary capabilities to reduce attack surface. - Test and verify with
kubectl describeandkubectl get -o yamlto confirm the effective security settings.
- View the full manifest:
kubectl get pod web-pod -o yaml - See events and container-level settings:
kubectl describe pod web-pod - Check effective filesystem group (fsGroup) behavior by inspecting mounted volumes and file modes
- Kubernetes: Configure Security Context for a Pod or Container
- Kubernetes Pod Security Policy (deprecated guidance — use Pod Security Admission or OPA/Gatekeeper instead)
- Kubernetes Concepts: Security Context