K8s by Example: Security Context
| Security context controls privilege and access settings. Apply at Pod level (all containers) or container level. Essential for production hardening and defense in depth. |
| security-context-pod.yaml | |
| Pod-level security context applies to all containers. | |
| security-context-container.yaml | |
| Container-level security context overrides Pod level for that container. Drops Linux capabilities and prevents privilege escalation. Each container can have different settings. | |
| security-context-capabilities.yaml | |
| Linux capabilities are fine-grained privileges. Drop | |
| security-context-seccomp.yaml | |
| Seccomp (Secure Computing Mode) restricts syscalls a container can make. | |
| security-context-readonly.yaml | |
|
| |
| security-context-production.yaml | |
| Complete production-ready security context. Combine Pod and container settings for defense in depth. This is the recommended baseline for most workloads. | |
| terminal | |
| Debug security context issues by checking Pod events and container status. Common errors: “container has runAsNonRoot but image will run as root” and “permission denied” on volume mounts (often fsGroup issues). Use | |