Ultra Secure Kubernetes Pod: Security-Hardened Deployment Template

Hardening a Kubernetes pod against common attack vectors requires configuring security contexts, RBAC, Linux security modules, image policies, resource limits, and secret management together. This template implements the full set of Kubernetes pod security best practices in a single deployable manifest, covering non-root execution, read-only filesystems, seccomp and AppArmor profiles, SELinux labels, least-privilege RBAC, and volume-mounted secrets with restricted permissions.
| Component | Type | Port | Role |
|---|---|---|---|
| ServiceAccount | ServiceAccount | - | Minimal-permission identity with API token mounting disabled |
| Role + RoleBinding | RBAC | - | Least-privilege permissions bound to the ServiceAccount |
| Secret | Secret | - | Credentials injected as environment variables and volume-mounted files |
| Deployment | Deployment | - | Hardened pod with all security controls applied |
The pod runs as UID 1000 with privilege escalation disabled and a read-only root filesystem backed by temporary writable volumes. A dedicated ServiceAccount with a Role and RoleBinding applies minimal RBAC permissions and disables automatic API token mounting. Sensitive data is injected as environment variables from SecretRefs and as volume-mounted files with 0400 permissions. Seccomp runtime default, AppArmor enforcement, and SELinux multi-level labels provide OS-level confinement. CPU, memory, and ephemeral storage limits prevent resource exhaustion.
kubectl exec -n <namespace> <pod> -- id should return uid=1000.kubectl exec -n <namespace> <pod> -- touch /test should return a permission denied error.kubectl get pod <pod> -n <namespace> -o jsonpath='{.spec.securityContext.seccompProfile}'.kubectl exec -n <namespace> <pod> -- ls /var/run/secrets/kubernetes.io/serviceaccount/ should return empty or not found.This template configures a Kubernetes pod with the full set of security controls applied at the container, identity, OS, and resource level. For a full walkthrough, read Securing Kubernetes Pods: A Complete Guide to Pod-Level Security Configuration.