Kubernetes security 101: 10 best practices to secure clusters, workloads, and runtime

Kubernetes security 101: 10 best practices to secure clusters, workloads, and runtime

Santerra Holler October 05, 2026

Kubernetes security 101: 10 best practices to secure clusters, workloads, and runtime

Book a Demo

Updated on November 4, 2026

A perfectly configured pod still loses if the API server is exposed, and a locked-down cluster still loses if it runs a backdoored image. Kubernetes security protects clusters, workloads, and runtime across four layers (cloud, cluster, container, and code), and each layer depends on the one beneath it. Ten practices matter most: scanned minimal images, signed images, admission policy, a hardened control plane, least-privilege RBAC, Pod Security Admission, managed secrets, workload and node hardening, default-deny networking, and runtime detection. This guide covers each practice in four stages: build, deploy, cluster governance, and runtime. Every practice comes with what to configure, a common mistake, an example, and a validation step. It reflects Kubernetes features and managed-service behaviour as of November 2026, including PodSecurityPolicy’s replacement and modern supply chain controls.

Key takeaways

  • ✓Kubernetes security works as layered defense, so a control at one layer (cloud, cluster, container, or code) never compensates for a gap at another.
  • ✓PodSecurityPolicy was removed in Kubernetes 1.25, and Pod Security Admission with the baseline and restricted standards is now the built-in way to enforce pod hardening.
  • ✓Signed images, SBOMs, and admission policies that block unsigned or “:latest” images stop most supply chain risk before a pod is scheduled.
  • ✓Default-deny NetworkPolicies for both ingress and egress only take effect when the cluster’s CNI plugin enforces them.
  • ✓Configuration scanning shows what could go wrong, while runtime detection shows what is going wrong, and a mature program needs both.

Kubernetes security best practices at a glance

The ten practices group into three layers: supply chain and images, cluster access and policy, and runtime and network defense. The table maps each practice to the risk it addresses, the effort it takes, and how to confirm it works.

# Practice Risk addressed Effort Validation
1 Build minimal, scanned images Known CVEs, bloated attack surface Low trivy image in CI
2 Sign images and verify provenance Tampered or untrusted images Medium cosign verify
3 Enforce admission policies Non-compliant workloads reaching the cluster Medium Apply a test pod that should be rejected
4 Harden the control plane and etcd API exposure, plaintext data at rest Medium kube-bench, audit log review
5 Least-privilege RBAC and service accounts Privilege escalation, token abuse Medium kubectl auth can-i --list
6 Pod Security Admission Privileged and host-level pods Low Server-side dry run against namespace labels
7 Manage secrets properly Credential leakage Medium Read raw etcd value, check encryption prefix
8 Harden workloads and nodes Container escape, node takeover Medium Kubescape, kube-bench node checks
9 Default-deny network traffic Lateral movement, data exfiltration Medium Connection test from a debug pod
10 Runtime detection and response Active attacks, zero-days High Trigger a test event such as a shell in a pod

Most real-world Kubernetes security issues trace back to defaults that were never changed. Common examples are a pod running as root, a default service account with a mounted token, a flat network, or an API endpoint open to the internet. The practices below close those gaps in order.

Supply chain and Kubernetes container security

Kubernetes container security starts before deployment. You decide what goes into an image and prove where it came from, then refuse anything that fails those checks at admission. Many of the same principles apply outside Kubernetes. See our guide to Docker container security best practices for the image-level fundamentals.

1. Build minimal, scanned images

Why it matters: every package in an image is a potential CVE. Distroless or Alpine-based images commonly cut the package count by an order of magnitude compared with full OS bases.

  • ✓Use multi-stage builds so compilers and package managers never ship.
  • ✓Pin base images by digest (@sha256:...), not by mutable tag.
  • ✓Scan in CI and fail the build on fixable critical and high findings.
  • ✓Push only to a private registry with access controls and pull-through caching. You decide what enters your environment, and an upstream registry outage stops being your outage.
trivy image --severity CRITICAL,HIGH --ignore-unfixed --exit-code 1 registry.example.com/api:1.4.2

Common mistake: scanning only at build time. Images in production age, and new CVEs land against packages that passed last month. Rescan running images on a schedule.

2. Sign images and verify provenance

Why it matters: a scan tells you an image has no known bugs. A signature tells you it is the image your pipeline actually built.

  1. Generate an SBOM at build time with Syft or Trivy, in SPDX or CycloneDX format.
  2. Sign the image with Sigstore cosign. Keyless signing ties the signature to your CI’s OIDC identity.
  3. Attach the SBOM and SLSA provenance as attestations.
  4. Verify signatures at admission (practice 3).
cosign sign --yes registry.example.com/api@sha256:3f1c...
cosign attest --yes --predicate sbom.spdx.json --type spdxjson registry.example.com/api@sha256:3f1c...
cosign verify registry.example.com/api@sha256:3f1c... \
  --certificate-identity-regexp 'https://github.com/acme/.*' \
  --certificate-oidc-issuer https://token.actions.githubusercontent.com

Validation: cosign verify returns the signing certificate’s identity. If it fails, the image should never run.

3. Enforce admission policies

Why it matters: policies written in a wiki are suggestions. Admission controllers turn them into rules the API server enforces on every create and update request.

Every request passes three gates in order:

  1. Authentication checks who you are, using client certificates, OIDC tokens, or service account tokens.
  2. Authorization checks what you are allowed to do, usually through RBAC.
  3. Admission control checks whether the object itself is acceptable. Mutating webhooks run first, then validating webhooks.

Kyverno (YAML-native policies), OPA Gatekeeper (Rego), and Sigstore policy-controller (signature verification) are the common engines. On Kubernetes 1.30+, the built-in ValidatingAdmissionPolicy with CEL expressions covers simple rules with no webhook to operate. This Kyverno policy blocks :latest and untagged images:

apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
  name: disallow-latest-tag
spec:
  validationFailureAction: Enforce
  rules:
  - name: require-pinned-tag
    match:
      any:
      - resources:
          kinds: ["Pod"]
    validate:
      message: "Images must use a pinned tag or digest, not :latest."
      pattern:
        spec:
          containers:
          - image: "!*:latest & *:*"

validationFailureAction: Enforce rejects violating pods. Start with Audit to see what would break first. Add companion rules for runAsNonRoot: true and a verifyImages rule tied to your cosign identity.

Common mistake: setting a webhook’s failurePolicy: Ignore. If the policy engine goes down, every pod is admitted unchecked.

Kubernetes cluster security: control plane, identity, and policy

At the cluster level, you protect the API server and etcd, give humans and workloads the least access they need, and enforce pod standards and secret handling with built-in Kubernetes security features. Managed services change who owns what. On Amazon EKS, GKE, or AKS, the provider runs the control plane, so some settings below are toggles in the cloud console or API rather than flags you edit.

4. Harden the control plane and etcd

  • ✓Restrict API exposure: use a private endpoint, or allowlist CIDRs on the public one. On EKS, set endpointPublicAccess=false or limit publicAccessCidrs.
  • ✓Enable audit logging and ship the logs off-cluster. On EKS, enable the audit control plane log type to CloudWatch.
  • ✓Encrypt etcd at rest, ideally with a KMS provider (envelope encryption) instead of a local key.
  • ✓Rotate certificates. Enable kubelet certificate rotation and track kubeadm cert expiry with kubeadm certs check-expiration.
  • ✓Disable anonymous auth on the API server and kubelet, and keep etcd reachable only from the API server over mutual TLS.

For self-managed clusters, the API server reads an EncryptionConfiguration through --encryption-provider-config:

apiVersion: apiserver.config.k8s.io/v1
kind: EncryptionConfiguration
resources:
- resources: ["secrets"]
  providers:
  - kms:
      apiVersion: v2
      name: aws-kms
      endpoint: unix:///var/run/kmsplugin/socket.sock
  - identity: {}

The first provider encrypts new writes. identity stays last so existing plaintext data can still be read until you rewrite it with kubectl get secrets -A -o json | kubectl replace -f -.

Validation: read a secret directly from etcd with etcdctl get /registry/secrets/default/my-secret. The value should start with k8s:enc:kms:v2:, not readable text.

5. Apply least-privilege RBAC and scope service accounts

RBAC grants permissions through Roles (namespaced) or ClusterRoles, which RoleBindings attach to users, groups, or service accounts. These design patterns hold up in practice:

  • ✓Bind to groups from your identity provider, never to individual users.
  • ✓Prefer namespaced Roles. Reserve cluster-admin for break-glass accounts.
  • ✓Never grant wildcards (*) on verbs or resources. Treat escalate, bind, impersonate, and create pods/exec as admin-equivalent.
  • ✓Give each workload its own service account, and set automountServiceAccountToken: false when it never calls the API.
  • ✓For cloud access, use workload identity (EKS Pod Identity or IRSA, GKE Workload Identity, Azure Workload Identity) instead of static cloud keys stored in secrets.
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata: {namespace: payments, name: config-reader}
rules:
- apiGroups: [""]
  resources: ["configmaps"]
  verbs: ["get", "list"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata: {namespace: payments, name: config-reader-binding}
subjects:
- kind: ServiceAccount
  name: payments-api
  namespace: payments
roleRef:
  kind: Role
  name: config-reader
  apiGroup: rbac.authorization.k8s.io

Validation: kubectl auth can-i --list --as=system:serviceaccount:payments:payments-api -n payments should show only get and list on configmaps.

6. Enforce Pod Security Admission

PodSecurityPolicy was deprecated in 1.21 and removed in 1.25. Its replacement, Pod Security Admission (PSA), is built in. You configure it with namespace labels that point to one of three Pod Security Standards:

Standard What it allows Use for
privileged Everything System namespaces such as CNI and CSI agents only
baseline Blocks hostNetwork, hostPID, privileged containers, and most hostPath use The minimum for any application namespace
restricted Baseline plus non-root, dropped capabilities, seccomp, and no privilege escalation Default target for application workloads
kubectl label namespace payments \
  pod-security.kubernetes.io/enforce=baseline \
  pod-security.kubernetes.io/warn=restricted \
  pod-security.kubernetes.io/audit=restricted

This configuration rejects anything below baseline. The warnings and audit events show what still needs fixing before you tighten enforce to restricted.

Before labeling a live namespace, run kubectl label --dry-run=server --overwrite ns payments pod-security.kubernetes.io/enforce=restricted. The API server lists every existing pod that would violate the standard, without changing anything.

7. Manage secrets outside plaintext manifests

Kubernetes Secrets are base64-encoded, not encrypted, so anyone with read access to a manifest in Git can decode them.

  • ✓Keep the source of truth in an external manager such as AWS Secrets Manager, HashiCorp Vault, or Google Secret Manager. Sync it with External Secrets Operator or the Secrets Store CSI Driver.
  • ✓If secrets must live in Git, encrypt them with Sealed Secrets or SOPS.
  • ✓Rotate on a schedule. For example, rotate database credentials every 30 days, and immediately after any suspected exposure.
  • ✓Mount secrets as files rather than environment variables, which leak into crash dumps and kubectl describe output.
  • ✓Limit get, list, and watch on secrets. list returns the full contents, not just names.

Runtime and network defense

This layer limits what a compromised container can do. It restricts kernel access and isolates traffic, and it detects malicious behavior while workloads run. It also catches what earlier controls miss, including zero-days, stolen credentials, and insider misuse.

8. Harden workloads and nodes

Most container hardening happens in the securityContext:

spec:
  automountServiceAccountToken: false
  securityContext:
    runAsNonRoot: true
    runAsUser: 10001
    seccompProfile: {type: RuntimeDefault}
  containers:
  - name: api
    image: registry.example.com/api@sha256:3f1c...
    securityContext:
      allowPrivilegeEscalation: false
      readOnlyRootFilesystem: true
      capabilities: {drop: ["ALL"]}
      appArmorProfile: {type: RuntimeDefault}

Here is what each field does:

  • ✓runAsNonRoot makes the kubelet refuse to start the container as UID 0.
  • ✓seccompProfile: RuntimeDefault blocks dozens of rarely needed syscalls.
  • ✓Dropping ALL capabilities removes powers such as NET_RAW and SYS_ADMIN.
  • ✓readOnlyRootFilesystem stops attackers writing tools to disk. Mount an emptyDir for any path that needs writes.
  • ✓The appArmorProfile field requires 1.30+. Older clusters use annotations, and SELinux-based distributions use seLinuxOptions instead.

Also set resource requests and limits, plus a ResourceQuota and LimitRange per namespace, so one compromised pod cannot starve the node.

Kubernetes node security covers the host underneath the pods:

  • ✓Set kubelet --anonymous-auth=false and --authorization-mode=Webhook, and enable the NodeRestriction admission plugin.
  • ✓Enable --seccomp-default (GA in 1.27) so every pod gets RuntimeDefault without opting in.
  • ✓Avoid hostPath mounts. Mounting / or the container runtime socket is equivalent to root on the node.
  • ✓Use a minimal, container-optimized OS such as Bottlerocket, Container-Optimized OS, or Flatcar, and patch it through node image rotation.
  • ✓Sandbox untrusted or multi-tenant workloads with gVisor or Kata Containers through a RuntimeClass. Rootless or user-namespaced pods (hostUsers: false) add another boundary where your version supports them.

9. Default-deny network traffic

Kubernetes networking is flat by default, so every pod can reach every other pod. NetworkPolicies work as an allowlist. Once any policy selects a pod, only explicitly allowed traffic flows. Our explainer on Kubernetes network policy examples walks through more traffic patterns. Start each namespace with this policy:

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata: {name: default-deny-all, namespace: payments}
spec:
  podSelector: {}
  policyTypes: ["Ingress", "Egress"]
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata: {name: allow-dns, namespace: payments}
spec:
  podSelector: {}
  policyTypes: ["Egress"]
  egress:
  - to:
    - namespaceSelector:
        matchLabels: {kubernetes.io/metadata.name: kube-system}
      podSelector:
        matchLabels: {k8s-app: kube-dns}
    ports:
    - {protocol: UDP, port: 53}
    - {protocol: TCP, port: 53}

An empty podSelector selects every pod in the namespace. Listing both policy types denies all traffic in and out until you allow DNS and specific app flows, such as frontend to api on port 8080.

Keep these caveats in mind:

  • ✓CNI support: NetworkPolicies do nothing without an enforcing CNI such as Calico, Cilium, or Antrea. On EKS, the VPC CNI needs network policy enforcement enabled explicitly.
  • ✓DNS-based egress: core NetworkPolicy cannot filter by domain name. Cilium or Calico extensions can.
  • ✓Cloud metadata: block egress to the cloud metadata endpoint at 169.254.169.254 for pods that do not need it.

Validation: kubectl run t --rm -it --image=busybox -n payments -- wget -T 3 api:8080 should time out from any unapproved pod.

10. Detect and respond at runtime

Preventive controls reduce Kubernetes security risks, but they do not stop an attacker exploiting an unknown flaw in an allowed process. Runtime detection watches syscalls, process trees, file access, and network connections. eBPF-based tools such as Falco and Tetragon do this with low overhead. For the broader picture, see how cloud runtime security detects threats while workloads run.

Alert on these high-signal behaviors:

  • ✓A shell spawned inside a container, or kubectl exec into production.
  • ✓Writes to /etc or binary directories, and new executables appearing at runtime.
  • ✓Reads of the service account token followed by API calls the workload never normally makes.
  • ✓Outbound connections to the metadata endpoint, mining pools, or never-seen IPs.
  • ✓Audit log events such as new ClusterRoleBindings, secret list calls, or privileged pod creation.

Correlate runtime events with API audit logs and cloud logs such as CloudTrail. For a compromised pod, follow these steps:

  1. Isolate the pod with a deny-all NetworkPolicy targeting its labels.
  2. Remove it from load balancing by changing its labels, and keep it running for forensics.
  3. Cordon the node and capture memory and disk if a node escape is suspected.
  4. Revoke credentials. Rotate the service account token, the cloud role session, and any mounted secrets.
  5. Trace the entry point (image, dependency, or exposed API), fix it, and redeploy from a verified image.

Kubernetes security tools and how to audit your cluster

Kubernetes security tools do four jobs. They scan images and configuration, benchmark the cluster, enforce policy at admission, and detect threats at runtime. Most teams combine open-source tools for each job, or consolidate them in a platform.

Tool Category When to use it
Upwind Runtime-first CNAPP with an eBPF sensor You need findings prioritized by what is actually loaded, reachable, and executing across clusters and cloud accounts
Trivy Image, IaC, and cluster scanner CI gating and quick cluster-wide vulnerability reports
kube-bench CIS Benchmark checker Auditing node and control plane configuration against CIS
Kubescape Posture scanner Checking against NSA-CISA and MITRE ATT&CK-based frameworks
Kyverno / OPA Gatekeeper Admission policy engine Kyverno for YAML-native policies, Gatekeeper for teams already using Rego
cosign / policy-controller Signing and verification Proving image provenance and enforcing signatures
Falco / Tetragon Runtime detection Behavioral rules on syscalls and process activity

You can audit an existing cluster in about an hour with these commands:

# Who can do what? Check default service accounts first
kubectl auth can-i --list --as=system:serviceaccount:default:default
# Privileged pods anywhere
kubectl get pods -A -o json | jq -r '.items[] | select(.spec.containers[].securityContext.privileged==true) | .metadata.namespace+"/"+.metadata.name'
# Namespaces without Pod Security labels
kubectl get ns -L pod-security.kubernetes.io/enforce
# CIS checks on a node
kube-bench run --targets node
# Vulnerabilities and misconfigurations cluster-wide
trivy k8s --report summary
kubescape scan framework nsa

Running a managed cluster? kube-bench cannot inspect an EKS, GKE, or AKS control plane you do not own. Use the provider-specific CIS benchmark target, such as --benchmark eks-1.x, and audit control plane settings through the cloud API. For AWS Kubernetes security, also review EKS access entries, IAM roles mapped to Kubernetes groups, and node IAM role permissions. Those IAM roles are frequently over-privileged.

How Upwind adds runtime context to Kubernetes security

Upwind fits at practice 10 and feeds back into the rest. A lightweight eBPF sensor runs in your clusters, alongside posture scanning across AWS and Google Cloud, so your backlog reflects what is actually running instead of every CVE in every image. Upwind holds a 4.8/5 rating from 88 reviews on Gartner Peer Insights, where reviewers single out runtime visibility into Kubernetes and container environments and alerting accuracy. Its sensor cannot run on AWS Fargate, AWS Lambda, or Google Cloud Run, so heavily serverless estates rely on its agentless coverage there.

  • ✓Shows which vulnerable packages are loaded and which workloads are reachable.
  • ✓Flags live behavior such as a process spawning a shell.
  • ✓Ties running containers back to their registry and build source.
  • ✓Covers hosts, containers, and serverless functions in one platform.
  • ✓Uses AI agents to investigate threats and generate fixes from runtime context.

Kubernetes security checklist and implementation roadmap

Start by setting modern defaults on every cluster. Then confirm each best practice with its verification command, and sequence the remaining work from quick wins to advanced hardening.

Modern defaults every cluster should have:

  • ✓A private or CIDR-restricted API endpoint, audit logging on, and anonymous auth off.
  • ✓Secrets encrypted at rest with KMS.
  • ✓Pod Security Admission at baseline or above on every application namespace.
  • ✓Default-deny NetworkPolicies on an enforcing CNI.
  • ✓Seccomp RuntimeDefault, non-root containers, and no default service account tokens.
Practice Verification command
1. Scanned images trivy image --exit-code 1 --severity CRITICAL <image>
2. Signed images cosign verify <image@digest> --certificate-identity-regexp ...
3. Admission policy kubectl run bad --image=nginx:latest (expect a denial)
4. Control plane kube-bench run --targets master or the managed benchmark
5. RBAC kubectl auth can-i --list --as=system:serviceaccount:<ns>:<sa>
6. Pod Security Admission kubectl get ns -L pod-security.kubernetes.io/enforce
7. Secrets etcdctl get /registry/secrets/<ns>/<name> (expect the k8s:enc: prefix)
8. Workload and node hardening kubescape scan framework nsa, kube-bench run --targets node
9. Network policy kubectl get netpol -A plus a busybox connection test
10. Runtime detection kubectl exec -it <pod> -- sh (expect an alert)

Roadmap:

  1. Week 1, quick wins: restrict API access, enable audit logs, add PSA warn=restricted labels, disable default token automount, and scan images in CI.
  2. Month 1, medium-term: enforce PSA baseline, roll out default-deny NetworkPolicies namespace by namespace, move secrets to an external manager, adopt workload identity, and deploy Kyverno or Gatekeeper in audit mode.
  3. Quarter 1, advanced hardening: enforce signed images, move to PSA restricted, sandbox untrusted workloads with gVisor or Kata, and run runtime detection with a tested incident playbook.

Each minor Kubernetes release changes a default or graduates a feature, so revisit this list at every upgrade. Treat Kubernetes security as layered defense. Control what you build, restrict what you admit, and watch what actually runs. A cluster that does all three is far harder to breach than one that excels at only one.

FAQ

What are the most important Kubernetes security best practices?

The article highlights 10 key practices: build minimal scanned images, sign images and verify provenance, enforce admission policies, harden the control plane and etcd, apply least-privilege RBAC, enforce Pod Security Admission, manage secrets properly, harden workloads and nodes, default-deny network traffic, and add runtime detection and response.

What replaced PodSecurityPolicy in Kubernetes?

PodSecurityPolicy was removed in Kubernetes 1.25. Its built-in replacement is Pod Security Admission, which uses namespace labels to enforce the privileged, baseline, or restricted Pod Security Standards.

Why are signed container images important if images are already scanned?

Scanning shows whether an image contains known vulnerabilities, but signing proves the image came from your trusted build pipeline and was not tampered with. The guide recommends verifying signatures and provenance at admission so untrusted images never run.

Do Kubernetes NetworkPolicies work automatically in every cluster?

No. NetworkPolicies only take effect when your cluster uses a CNI plugin that enforces them, such as Calico, Cilium, or Antrea. Without enforcement, a default-deny policy does nothing.

Are Kubernetes Secrets secure if they are only base64-encoded?

No. Base64 encoding is not encryption. The article recommends storing secrets in an external manager such as AWS Secrets Manager, Vault, or Google Secret Manager, encrypting secrets at rest in etcd with KMS, and avoiding plaintext secrets in Git manifests.

Add the Upwind RSS Feed to Slack
Connect the Upwind RSS Feed to your Slack.
Follow the how-to here.
Threat RSS
Add the Upwind RSS Feed to Slack
Connect the Upwind RSS Feed to your Slack.
Follow the how-to here.
Main RSS