Kubernetes Security
Secure clusters, workloads, RBAC, network policy, images and runtime behaviour across Kubernetes and OpenShift.
Where it fits in the lifecycle
- Plan
- Code
- Build
- Test
- Release
- Deploy
- Operate
- Monitor
- Deploy Policy enforcement, admission control and infrastructure security.
- Operate Runtime security, secrets rotation and configuration reconciliation.
Overview
Kubernetes security spans control-plane configuration, workload hardening, least-privilege RBAC, network segmentation, admission control and runtime detection. Each layer is independently configurable, which is why defence in depth matters here.
Why it matters
Default Kubernetes settings favour flexibility over restriction. Without deliberate hardening, a single compromised pod can often reach the API server, other namespaces and cloud credentials.
How it works
- 01Pod Security Admission or an equivalent policy engine restricts workload capabilities.
- 02RBAC is scoped per service account and audited for wildcard verbs.
- 03NetworkPolicies establish default-deny east-west traffic.
- 04Runtime sensors detect unexpected process, file and network behaviour.
Common tools
Implementation examples
securityContext: runAsNonRoot: true runAsUser: 10001 allowPrivilegeEscalation: false readOnlyRootFilesystem: true seccompProfile: type: RuntimeDefault capabilities: drop: ["ALL"]apiVersion: networking.k8s.io/v1kind: NetworkPolicymetadata: name: default-deny-ingress namespace: paymentsspec: podSelector: {} policyTypes: [Ingress]Security considerations
- Audit RBAC for cluster-admin bindings and wildcard resources.
- Restrict service-account token automounting where it is not needed.
Best practices
- Enforce the restricted Pod Security standard for application namespaces.
- Default-deny network traffic and allow explicitly.
- Keep node and control-plane versions on a supported release cadence.
Common mistakes
- Granting cluster-wide roles for convenience.
- Relying on image scanning alone with no runtime detection.
Hands-on labs
- Lab 04 — Enforce Kubernetes Policy
Scan Kubernetes manifests, then enforce a policy with Kyverno in a local cluster.
- Lab 05 — Restrict Pod Privileges
Apply Pod Security Admission and fix a workload that fails the restricted profile.
- Lab 08 — Detect Runtime Anomalies
Install Falco and trigger a runtime detection inside a container.