Pod Security Best Practices
You'll learn how to layer multiple security controls to protect your Kubernetes Pods through least privilege, immutability, and defense in depth.
What is Defense in Depth for Pods?
Imagine your Pod is a castle: you don't rely on just a moat, or just thick walls, or just guards—you use all of them. Similarly, comprehensive Pod security means applying multiple layers of protection so that if one control fails, others still protect your workload.
Core Security Hardening Patterns
Least Privilege
Grant only the minimum permissions needed:
- Run as non-root user (
runAsNonRoot: true) - Drop unnecessary Linux capabilities
- Use read-only root filesystem
- Avoid privileged containers unless absolutely required
Immutability
Make your container filesystem unchangeable after deployment:
- Set
readOnlyRootFilesystem: true - Mount temporary directories as emptyDir volumes for write operations
- Prevents runtime tampering and malware installation
Defense in Depth
Layer complementary controls:
- RBAC limits what ServiceAccounts can do
- Security contexts restrict container capabilities
- Pod Security Standards enforce baseline policies
- Network policies control traffic flow
- Seccomp/AppArmor/SELinux add kernel-level protection
- Disable
allowPrivilegeEscalationto prevent runtime privilege gain
The Complete Pattern
Apply all relevant controls together. A well-hardened Pod runs as non-root, uses a read-only filesystem, drops all capabilities except what's needed, disables privilege escalation, enforces restrictive Pod Security Standards, and limits ServiceAccount permissions through RBAC.
Key Takeaway: Pod security isn't a single checkbox—it's applying multiple complementary protections (least privilege, immutability, defense in depth) so your workloads remain secure even when individual controls are bypassed.