🎁 New User? Get 20% off your first purchase with code NEWUSER20 Register Now →
Menu

Categories

Kubernetes Security Complete Guide: Hardening, RBAC, Network Policies (2026)

Kubernetes Security Complete Guide: Hardening, RBAC, Network Policies (2026)

Kubernetes security is one of the most critical and challenging aspects of running containerized workloads in production. With Kubernetes powering 90%+ of container orchestration, securing your clusters is not optional — it is essential. This guide covers every layer of K8s security, from cluster hardening to runtime protection.

Kubernetes Security Hardening

Free Kubernetes Security Cheat Sheet

Pod Security Standards, RBAC, Network Policies, Secrets Management, and scanning tools in a printable PDF.

Download Free PDF

Table of Contents

Kubernetes Threat Landscape

Common attack vectors in Kubernetes:

  • Misconfigured RBAC — Overly permissive roles allowing privilege escalation
  • Exposed dashboards — Kubernetes Dashboard, etcd, or API server publicly accessible
  • Vulnerable images — Container images with known CVEs
  • Container escape — Privileged containers breaking out to the host
  • Secrets in plain text — Kubernetes Secrets are base64-encoded, not encrypted
  • Lateral movement — Flat network allows pod-to-pod communication by default
  • Supply chain attacks — Compromised base images or dependencies

Security Layers (Defense in Depth)

LayerWhat to SecureKey Controls
ClusterAPI server, etcd, kubeletTLS, audit logging, encryption at rest
AuthenticationUser and service identityOIDC, service accounts, no static tokens
AuthorizationAccess controlRBAC, least privilege, namespace isolation
NetworkPod communicationNetwork Policies, service mesh, mTLS
PodContainer securityPod Security Standards, security contexts
ImageContainer imagesScanning, signing, minimal base images
RuntimeRunning containersFalco, seccomp, AppArmor/SELinux
DataSecrets & configExternal secrets, Vault, encryption

Cluster Hardening

  • API Server — Restrict access with firewall rules, enable audit logging, use OIDC for authentication
  • etcd — Encrypt at rest, restrict network access, enable TLS client certificates
  • Kubelet — Disable anonymous auth, enable webhook authentication, read-only port disabled
  • CIS Benchmarks — Run kube-bench to validate cluster configuration against CIS Kubernetes Benchmark

RBAC (Role-Based Access Control)

RBAC is Kubernetes' built-in authorization mechanism. Key principles:

  • Least privilege — Grant only the minimum permissions needed
  • Namespace scoping — Use Roles (namespace) over ClusterRoles where possible
  • No wildcard permissions — Avoid resources: ["*"] or verbs: ["*"]
  • Service accounts per workload — Don't use the default service account
  • Regular audits — Review RBAC bindings periodically with rbac-lookup or kubectl

Pod Security Standards

LevelRestrictionsUse Case
PrivilegedNo restrictions (unrestricted)System-level pods (CNI, storage)
BaselineBlocks known privilege escalationsDefault for most workloads
RestrictedMaximum security hardeningUntrusted/multi-tenant workloads

Security Context Best Practices

  • runAsNonRoot: true — Never run containers as root
  • readOnlyRootFilesystem: true — Prevent writes to container filesystem
  • allowPrivilegeEscalation: false — Block privilege escalation
  • capabilities.drop: ["ALL"] — Drop all Linux capabilities
  • seccompProfile.type: RuntimeDefault — Apply default seccomp profile

Network Policies

By default, all pods can communicate with all other pods in a Kubernetes cluster. Network Policies let you define firewall rules at the pod level.

Critical: Your CNI plugin must support Network Policies. Calico, Cilium, and Weave support them. The default kubenet does NOT. Without a supporting CNI, NetworkPolicy resources are silently ignored.

Network Policy Strategy

  1. Default deny all — Start by blocking all ingress/egress traffic
  2. Allow specific flows — Whitelist only required pod-to-pod communication
  3. Namespace isolation — Restrict cross-namespace traffic
  4. DNS egress — Allow port 53 to kube-dns for name resolution

Secrets Management

MethodSecurity LevelRecommendation
K8s Secrets (default)Low (base64 only)Enable encryption at rest, minimum
Sealed SecretsMediumGood for GitOps workflows
External Secrets OperatorHighRecommended for production
HashiCorp VaultHighestEnterprise-grade, dynamic secrets

Image Security

  • Use minimal base images — distroless, Alpine, or scratch
  • Pin image versions — Never use :latest tag in production
  • Scan images — Trivy, Grype, Snyk in CI/CD pipeline
  • Sign images — Cosign for image integrity verification
  • Private registry — Don't pull from public registries in production
  • Admission control — OPA/Gatekeeper or Kyverno to enforce image policies

Runtime Security

  • Falco — Runtime threat detection based on syscall monitoring
  • Seccomp profiles — Restrict which syscalls containers can make
  • AppArmor/SELinux — Mandatory access control for containers
  • Read-only filesystem — Prevent runtime modifications
  • Resource limits — Set CPU/memory limits to prevent resource abuse

Scanning Tools

ToolTypeWhat It Scans
TrivyAll-in-oneImages, IaC, SBOM, misconfigs, secrets
FalcoRuntimeSyscalls, container behavior, anomalies
KubescapeComplianceNSA/CISA, MITRE, CIS Benchmarks
kube-benchCIS BenchmarkCluster config vs CIS K8s Benchmark
PolarisBest practicesDeployment configs, security contexts
OPA GatekeeperPolicyAdmission control with Rego policies

Security Checklist

  1. Enable RBAC, disable ABAC
  2. Use Network Policies (default deny)
  3. Pod Security Standards: Restricted level
  4. No root containers (runAsNonRoot: true)
  5. Drop all capabilities
  6. Read-only root filesystem
  7. Encrypt etcd at rest
  8. Enable audit logging
  9. Use External Secrets or Vault
  10. Scan images in CI/CD
  11. Sign and verify images
  12. Runtime monitoring (Falco)
  13. Resource limits on all pods
  14. Regular CIS Benchmark scans

Download the K8s Security Cheat Sheet

Pod Security, RBAC, Network Policies, Secrets, and scanning tools reference.

Download Free PDF

Related Articles

Share this article:
Dargslan Editorial Team (Dargslan)
About the Author

Dargslan Editorial Team (Dargslan)

Collective of Software Developers, System Administrators, DevOps Engineers, and IT Authors

Dargslan is an independent technology publishing collective formed by experienced software developers, system administrators, and IT specialists.

The Dargslan editorial team works collaboratively to create practical, hands-on technology books focused on real-world use cases. Each publication is developed, reviewed, and...

Programming Languages Linux Administration Web Development Cybersecurity Networking

Stay Updated

Subscribe to our newsletter for the latest tutorials, tips, and exclusive offers.