The default Kubernetes experience is permissive by design — pods can run as root, mount the host filesystem, and use every Linux capability unless you explicitly lock them down. Most breaches that escalate from "compromised container" to "compromised cluster" exploit exactly that gap. Here's a practical checklist for closing it, from the container image up through network policy.

1. Run Containers as Non-Root

This is the single highest-leverage change you can make. If an attacker gets code execution inside a container running as root, they're one misconfiguration away from a host-level compromise. Enforce non-root at the pod level:

securityContext:
  runAsNonRoot: true
  runAsUser: 10000
  runAsGroup: 10000
  fsGroup: 10000

Build this into your base image too — use a USER directive in your Dockerfile so the container can't accidentally run as root even if the Kubernetes-level setting is missing:

FROM node:20-slim
RUN useradd -u 10000 -m appuser
USER 10000

2. Use a Read-Only Root Filesystem

Most application containers never need to write to their own filesystem. Making it read-only means that even a successful RCE can't drop a persistent payload on disk or modify binaries in place:

securityContext:
  readOnlyRootFilesystem: true

If your app needs scratch space (logs, temp files, cache), mount a dedicated emptyDir volume for just that path instead of leaving the whole filesystem writable:

volumes:
  - name: tmp
    emptyDir: {}
volumeMounts:
  - name: tmp
    mountPath: /tmp

3. Drop Linux Capabilities You Don't Need

By default, container runtimes grant a set of Linux capabilities that most applications never use (raw socket access, kernel module loading, etc.). Drop everything, then add back only what's required:

securityContext:
  capabilities:
    drop:
      - ALL
    add:
      - NET_BIND_SERVICE   # only if binding to a port <1024

If your container doesn't need to bind to a privileged port, don't add anything back — drop: ALL with no additions is the correct default for the vast majority of workloads.

4. Never Allow Privilege Escalation

Set allowPrivilegeEscalation: false explicitly. This blocks a process from gaining more privileges than its parent via setuid binaries or similar mechanisms — and it's required if you want drop: ALL capabilities to actually hold:

securityContext:
  allowPrivilegeEscalation: false
  privileged: false

Confirm privileged: false too — a privileged container has essentially the same access as a process running directly on the host node, bypassing most of the isolation Kubernetes provides.

5. Restrict Syscalls with Seccomp

Seccomp profiles restrict which system calls a container can make to the kernel, shrinking the kernel attack surface available to an attacker who achieves code execution. Kubernetes ships a RuntimeDefault profile that blocks a reasonable set of dangerous syscalls with no extra configuration:

securityContext:
  seccompProfile:
    type: RuntimeDefault

As of Kubernetes 1.27+, you can also cluster-wide default this via the PodSecurity admission controller so teams don't have to remember to set it per-workload.

6. Enforce Pod Security Standards at the Namespace Level

PodSecurityPolicy was removed in Kubernetes 1.25. The replacement is Pod Security Standards, enforced via namespace labels using the built-in Pod Security Admission controller:

apiVersion: v1
kind: Namespace
metadata:
  name: production
  labels:
    pod-security.kubernetes.io/enforce: restricted
    pod-security.kubernetes.io/audit: restricted
    pod-security.kubernetes.io/warn: restricted

The restricted profile enforces nearly everything above by default — non-root, dropped capabilities, no privilege escalation, seccomp — so misconfigured pods get rejected at admission time instead of relying on every team remembering every setting. For more granular, custom policy, layer on Kyverno or OPA Gatekeeper.

7. Set Resource Requests and Limits

Unbounded containers can starve the node, triggering OOM kills or CPU contention across the entire cluster — effectively a denial-of-service that doesn't even require malicious intent. Every container should declare both:

resources:
  requests:
    cpu: "100m"
    memory: "128Mi"
  limits:
    cpu: "500m"
    memory: "256Mi"

8. Isolate Traffic with NetworkPolicies

By default, every pod in a Kubernetes cluster can talk to every other pod. That flat network model means a single compromised pod can probe and pivot across your entire cluster. Apply a default-deny policy per namespace, then explicitly allow only the traffic each workload actually needs:

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: default-deny
  namespace: production
spec:
  podSelector: {}
  policyTypes:
    - Ingress
    - Egress

Then add targeted allow rules — e.g., letting your API pods reach the database pods on port 5432, and nothing else.

9. Scan Images and Pin Digests

Hardened runtime settings don't help if the image itself ships a vulnerable base OS or a known-bad dependency. Scan images in CI before they ever reach the cluster (Trivy, Grype, or your registry's built-in scanner), and pin deployments to image digests rather than mutable tags:

image: myregistry/app@sha256:4f2b1e8c9a...
# not: image: myregistry/app:latest

Pinning by digest also closes the same class of risk behind recent supply chain incidents — a mutable tag like latest can point to a different, potentially compromised image tomorrow than it does today.

10. Keep Secrets Out of Images and Env Vars Where Possible

Avoid baking secrets into images or plain environment variables, both of which are easy to accidentally expose via docker inspect, logs, or crash dumps. Use Kubernetes Secrets mounted as files, or better, an external secrets manager (AWS Secrets Manager, HashiCorp Vault, or your cloud provider's equivalent) integrated via a CSI driver or operator:

volumes:
  - name: db-creds
    csi:
      driver: secrets-store.csi.k8s.io
      readOnly: true
      volumeAttributes:
        secretProviderClass: "db-creds-provider"

Putting It Together: A Minimal Hardened Pod Spec

apiVersion: v1
kind: Pod
metadata:
  name: hardened-app
spec:
  securityContext:
    runAsNonRoot: true
    runAsUser: 10000
    seccompProfile:
      type: RuntimeDefault
  containers:
    - name: app
      image: myregistry/app@sha256:4f2b1e8c9a...
      securityContext:
        allowPrivilegeEscalation: false
        readOnlyRootFilesystem: true
        capabilities:
          drop: ["ALL"]
      resources:
        requests:
          cpu: "100m"
          memory: "128Mi"
        limits:
          cpu: "500m"
          memory: "256Mi"
      volumeMounts:
        - name: tmp
          mountPath: /tmp
  volumes:
    - name: tmp
      emptyDir: {}

Why This Matters

None of these controls are exotic — they're all native Kubernetes primitives, available on every managed cluster (EKS, GKE, AKS) with no third-party tooling required. The gap between a default cluster and a hardened one is almost entirely a matter of whether someone sat down and set these fields deliberately, workload by workload, instead of accepting the permissive defaults. The cost of doing it upfront is a few extra lines of YAML per deployment; the cost of skipping it is a single compromised container turning into a cluster-wide incident.

Need Help Hardening Your Kubernetes Clusters?

Ez IT Expert audits Kubernetes workloads against Pod Security Standards, CIS Benchmarks, and your cloud provider's security baselines, then implements the fixes without breaking existing deployments. We'll show you exactly where your clusters stand before and after.

Get a Free Kubernetes Security Audit →