Skip to content
StackDecode
AdvancedLesson 24 of 35

Pod security

Harden what containers are allowed to do.

yaml
securityContext:
  runAsNonRoot: true
  runAsUser: 10001
  allowPrivilegeEscalation: false
  readOnlyRootFilesystem: true
  capabilities: { drop: ['ALL'] }
  seccompProfile: { type: RuntimeDefault }

Pod Security Standards (privileged, baseline, restricted) are enforced by the built-in Pod Security Admission, set with namespace labels:

bash
kubectl label ns prod pod-security.kubernetes.io/enforce=restricted

Avoid privileged: true, hostNetwork, hostPath mounts and the host PID/IPC namespaces unless there is a strong reason.