> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Kubernetes Security Essentials

> Practical Kubernetes security guidance for platform engineering covering authentication, authorization, admission control, secrets management, network policies, policy as code, and observability to enable secure multi-tenant platforms

Welcome back, students.

This lesson covers practical Kubernetes security essentials for platform engineering. When your platform supports many teams and environments, design for isolation, zero-trust principles, automated governance, and compliance — while preserving developer productivity. Balance protecting the cluster with enabling developers: too much restriction stifles velocity; too little invites risk.

<Callout icon="lightbulb" color="#1CB2FE">
  Adopt a defense-in-depth strategy: combine authentication, authorization, admission control, secrets protection, network segmentation, and observability to reduce blast radius while enabling safe developer workflows.
</Callout>

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/5GOdY0mbVYrHqNpp/images/Prep-Course-Certified-Cloud-Native-Platform-Engineering-Associate-CNPA/Domain-2-Platform-Observability-Security-and-Conformance/Kubernetes-Security-Essentials/kubernetes-security-platform-engineering-pillars.jpg?fit=max&auto=format&n=5GOdY0mbVYrHqNpp&q=85&s=219f80dc08d07d3babc392e697a0828f" alt="A presentation slide titled &#x22;Kubernetes Security – Foundation of Platform Engineering&#x22; showing four pillars: Multi-Tenant Clusters, Zero-Trust Architecture, Policy as Code, and Compliance Requirements, each with an icon and short caption." width="1920" height="1080" data-path="images/Prep-Course-Certified-Cloud-Native-Platform-Engineering-Associate-CNPA/Domain-2-Platform-Observability-Security-and-Conformance/Kubernetes-Security-Essentials/kubernetes-security-platform-engineering-pillars.jpg" />
</Frame>

Common areas to address

* Secrets management and encryption at rest
* Network policies and pod-to-pod communication
* Admission control (what requests get modified or validated)
* Authorization and authentication (who is the caller and what can they do)
* Policy-as-code and automated governance (OPA Gatekeeper, Kyverno)
* Observability, audit logs, and compliance reporting

Authentication (authn) vs Authorization (authz)

Authentication establishes identity; authorization determines allowed actions. Kubernetes supports several authentication methods — integrate with federated identity providers and PKI where possible.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/5GOdY0mbVYrHqNpp/images/Prep-Course-Certified-Cloud-Native-Platform-Engineering-Associate-CNPA/Domain-2-Platform-Observability-Security-and-Conformance/Kubernetes-Security-Essentials/authentication-methods-service-accounts-oidc-x509.jpg?fit=max&auto=format&n=5GOdY0mbVYrHqNpp&q=85&s=6925c52364eb3db55a5ba38f7d9dbc2e" alt="A presentation slide titled &#x22;Identity and Permissions – Authentication vs Authorization&#x22; showing an &#x22;Authentication&#x22; icon and three methods: 1) Service Accounts (pod identities), 2) OIDC Integration (human users via corporate identity providers), and 3) X.509 Certificates (client certificate authentication)." width="1920" height="1080" data-path="images/Prep-Course-Certified-Cloud-Native-Platform-Engineering-Associate-CNPA/Domain-2-Platform-Observability-Security-and-Conformance/Kubernetes-Security-Essentials/authentication-methods-service-accounts-oidc-x509.jpg" />
</Frame>

Authorization determines what an authenticated subject may do. Kubernetes supports RBAC, legacy ABAC, and external webhook-based authorization.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/5GOdY0mbVYrHqNpp/images/Prep-Course-Certified-Cloud-Native-Platform-Engineering-Associate-CNPA/Domain-2-Platform-Observability-Security-and-Conformance/Kubernetes-Security-Essentials/authentication-vs-authorization-rbac-abac-webhook.jpg?fit=max&auto=format&n=5GOdY0mbVYrHqNpp&q=85&s=147ee16dc9178f338e330d4a3f22249f" alt="A presentation slide titled &#x22;Identity and Permissions – Authentication vs Authorization&#x22; showing an &#x22;Authorization&#x22; icon and listing three authorization approaches: 1) RBAC: Role-Based Access Control, 2) ABAC: Attribute-Based Access Control, and 3) Webhook: External authorization services." width="1920" height="1080" data-path="images/Prep-Course-Certified-Cloud-Native-Platform-Engineering-Associate-CNPA/Domain-2-Platform-Observability-Security-and-Conformance/Kubernetes-Security-Essentials/authentication-vs-authorization-rbac-abac-webhook.jpg" />
</Frame>

RBAC essentials

Role-Based Access Control (RBAC) maps subjects (users, groups, service accounts) to Roles or ClusterRoles. RoleBindings (namespace-scoped) or ClusterRoleBindings (cluster-scoped) attach subjects to roles. Remember:

* Role and RoleBinding are namespace-scoped and must be created inside the same namespace.
* ClusterRole and ClusterRoleBinding are cluster-scoped and can grant permissions across namespaces.
* Follow least-privilege: grant the minimal verbs and resources required.

Example RoleBinding (namespace-scoped):

```yaml theme={null}
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: pony-dev-binding
  namespace: pony-dev
subjects:
- kind: User
  name: phuong@sparkleponyranch.com
  apiGroup: rbac.authorization.k8s.io
roleRef:
  kind: Role
  name: pony-developer
  apiGroup: rbac.authorization.k8s.io
```

Service accounts and pod identity

Pods run as a ServiceAccount by default. Bind ServiceAccounts to Roles (or ClusterRoles) to grant pods permissions while minimizing privileges.

Example ServiceAccount and RoleBinding that grants a service account permissions in the `pony-production` namespace:

```yaml theme={null}
apiVersion: v1
kind: ServiceAccount
metadata:
  name: pony-spawner-sa
  namespace: pony-production
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: pony-spawner-binding
  namespace: pony-production
subjects:
- kind: ServiceAccount
  name: pony-spawner-sa
  namespace: pony-production
roleRef:
  kind: Role
  name: pony-app-role
  apiGroup: rbac.authorization.k8s.io
```

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/wvZOAiRg_-4PgnSp/images/Prep-Course-Certified-Cloud-Native-Platform-Engineering-Associate-CNPA/Domain-2-Platform-Observability-Security-and-Conformance/Kubernetes-Security-Essentials/service-accounts-pod-identity-permissions-slide.jpg?fit=max&auto=format&n=wvZOAiRg_-4PgnSp&q=85&s=0fb0fa7222372e41ffcd04de62e75998" alt="A presentation slide titled &#x22;Service Accounts – Pod Identity and Permissions&#x22; showing three colored user icons labeled Swati, Alan, and Phuong with brief role descriptions and a &#x22;Sparkle Pony Ranch&#x22; tag. Each entry summarizes responsibilities for creating and securing service accounts for microservices." width="1920" height="1080" data-path="images/Prep-Course-Certified-Cloud-Native-Platform-Engineering-Associate-CNPA/Domain-2-Platform-Observability-Security-and-Conformance/Kubernetes-Security-Essentials/service-accounts-pod-identity-permissions-slide.jpg" />
</Frame>

Platform RBAC strategy

Namespaces can be organized per application, per team, or by environment (dev/prod). The critical controls are least privilege, separation of duties, and periodic permission audits.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/wvZOAiRg_-4PgnSp/images/Prep-Course-Certified-Cloud-Native-Platform-Engineering-Associate-CNPA/Domain-2-Platform-Observability-Security-and-Conformance/Kubernetes-Security-Essentials/platform-rbac-team-permissions-best-practices.jpg?fit=max&auto=format&n=wvZOAiRg_-4PgnSp&q=85&s=bd49d34b63a710acfe22d1bdd975d52a" alt="A presentation slide titled &#x22;Platform RBAC Strategy – Team-Based Permissions&#x22; with four numbered boxes outlining: Team Namespaces, Least Privilege, Separation of Duties, and Regular Audits, each with a short description. It summarizes access-control best practices for development teams." width="1920" height="1080" data-path="images/Prep-Course-Certified-Cloud-Native-Platform-Engineering-Associate-CNPA/Domain-2-Platform-Observability-Security-and-Conformance/Kubernetes-Security-Essentials/platform-rbac-team-permissions-best-practices.jpg" />
</Frame>

Admission controllers

Every Kubernetes API request flows through stages: authentication, authorization, mutating admission controllers, validating admission controllers, then persistence to etcd. Mutating admission controllers run before validating ones and can modify requests (e.g., inject sidecars, add labels).

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/5GOdY0mbVYrHqNpp/images/Prep-Course-Certified-Cloud-Native-Platform-Engineering-Associate-CNPA/Domain-2-Platform-Observability-Security-and-Conformance/Kubernetes-Security-Essentials/kubernetes-admission-controllers-request-validation-mutation.jpg?fit=max&auto=format&n=5GOdY0mbVYrHqNpp&q=85&s=6d66ed1d03490be99efb89253c3ba77d" alt="An infographic titled &#x22;Admission Controllers — Request Validation and Mutation&#x22; showing a vertical flow of Kubernetes API request handling stages with icons. It lists API Request, Authentication, Authorization (RBAC), Mutating Admission, Validating Admission, and Persistence with short notes like &#x22;kubectl/API call,&#x22; &#x22;modify request (add labels, inject sidecars),&#x22; and &#x22;store in etcd.&#x22;" width="1920" height="1080" data-path="images/Prep-Course-Certified-Cloud-Native-Platform-Engineering-Associate-CNPA/Domain-2-Platform-Observability-Security-and-Conformance/Kubernetes-Security-Essentials/kubernetes-admission-controllers-request-validation-mutation.jpg" />
</Frame>

Built-in admission controllers you should know

| Admission Controller | Purpose | Notes |
| - | - | - |
| `PodSecurity` | Enforces Pod Security Standards (replace PSP) | Supports `audit`, `warn`, and `enforce` modes |
| `ResourceQuota` | Limits resource consumption per namespace | Prevents noisy neighbors and resource exhaustion |
| `LimitRanger` | Applies default resource requests/limits | Helps ensure pods specify sensible resources |
| `NodeRestriction` | Limits kubelet access to node and pod info | Reduces privilege of kubelets to modify unrelated resources |
| `ValidatingAdmissionWebhook` / `MutatingAdmissionWebhook` | External webhook-based validation/mutation | Integrate policy engines like Gatekeeper or Kyverno |

Pod security

PodSecurityPolicy (PSP) has been deprecated; use the Pod Security admission controller and policy-as-code tools (OPA Gatekeeper, Kyverno) for richer enforcement. Teams commonly use `audit`, `warn`, and `enforce` modes to progressively tighten policies.

<Frame>
  <img src="https://mintlify.s3.us-west-1.amazonaws.com/kodekloud-c4ac6d9a/images/Prep-Course-Certified-Cloud-Native-Platform-Observability-Security-and-Conformance/Kubernetes-Security-Essentials/k8s-essential-admission-controllers-list.jpg" alt="A slide titled &#x22;Essential Built-in Admission Controllers&#x22; showing a numbered list of Kubernetes admission controllers. It lists PodSecurityPolicy (noting it's deprecated), PodSecurity, ResourceQuota, LimitRanger, and NetworkPolicy with brief descriptions of each." />
</Frame>

OPA Gatekeeper example

Gatekeeper provides ConstraintTemplates and Constraints to enforce organization-wide rules via admission webhooks. Below is a simplified ConstraintTemplate that requires specific labels on resources; the Rego snippet checks `metadata.labels` and emits violations for missing labels.

```yaml theme={null}
# Require labels on all pony services
apiVersion: templates.gatekeeper.sh/v1beta1
kind: ConstraintTemplate
metadata:
  name: requirelabels
spec:
  crd:
    spec:
      validation:
        properties:
          labels:
            type: array
            items:
              type: string
  targets:
  - target: admission.k8s.gatekeeper.sh
    rego: |
      package requirelabels

      violation[{"msg": msg}] {
        required := input.parameters.labels
        provided := input.review.object.metadata.labels
        missing := required[_]
        not provided[missing]
        msg := sprintf("Missing required label: %v", [missing])
      }
```

Gatekeeper produces clear violation messages and lets you enforce consistent policy-as-code across clusters. See the official docs: [https://open-policy-agent.github.io/gatekeeper/](https://open-policy-agent.github.io/gatekeeper/)

Secrets and data at rest

Kubernetes Secrets are Base64-encoded by default — Base64 is an encoding, not encryption. Protect secret data by enabling etcd encryption at rest and by using external secret stores for rotation, access control, and auditing.

<Callout icon="warning" color="#FF6B6B">
  Default Kubernetes Secrets are Base64-encoded (not encrypted). Always enable etcd encryption at rest and consider external secret managers (Vault, cloud KMS, Sealed Secrets, ExternalSecrets) for stronger protection and rotation.
</Callout>

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/5GOdY0mbVYrHqNpp/images/Prep-Course-Certified-Cloud-Native-Platform-Engineering-Associate-CNPA/Domain-2-Platform-Observability-Security-and-Conformance/Kubernetes-Security-Essentials/kubernetes-secrets-types-opaque-docker-tls.jpg?fit=max&auto=format&n=5GOdY0mbVYrHqNpp&q=85&s=fa517be6ae76500e66c820ec57205f73" alt="A presentation slide titled &#x22;Kubernetes Secrets — Secure Data Management.&#x22; It lists four secret types: Opaque (API keys/passwords), docker-registry (container registry credentials), tls (TLS certificates and private keys), and service-account-token (service account tokens for API authentication)." width="1920" height="1080" data-path="images/Prep-Course-Certified-Cloud-Native-Platform-Engineering-Associate-CNPA/Domain-2-Platform-Observability-Security-and-Conformance/Kubernetes-Security-Essentials/kubernetes-secrets-types-opaque-docker-tls.jpg" />
</Frame>

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/5GOdY0mbVYrHqNpp/images/Prep-Course-Certified-Cloud-Native-Platform-Engineering-Associate-CNPA/Domain-2-Platform-Observability-Security-and-Conformance/Kubernetes-Security-Essentials/kubernetes-secrets-base64-not-etcd-tls.jpg?fit=max&auto=format&n=5GOdY0mbVYrHqNpp&q=85&s=722ccfc6d3d2457de698026544afa174" alt="A slide titled &#x22;Kubernetes Secrets – Secure Data Management&#x22; showing three points: &#x22;Not Encryption&#x22; (Base64 is encoding, not encryption), &#x22;Encryption at Rest&#x22; (enable etcd encryption), and &#x22;Encryption in Transit&#x22; (TLS for API communication). Copyright KodeKloud is noted at the bottom." width="1920" height="1080" data-path="images/Prep-Course-Certified-Cloud-Native-Platform-Engineering-Associate-CNPA/Domain-2-Platform-Observability-Security-and-Conformance/Kubernetes-Security-Essentials/kubernetes-secrets-base64-not-etcd-tls.jpg" />
</Frame>

External secret solutions — quick comparison

| Solution | Use case | Key features / links |
| - | - | - |
| HashiCorp Vault | Enterprise secret management | Dynamic secrets, rotation, strong audit: [https://www.vaultproject.io](https://www.vaultproject.io) |
| Sealed Secrets (Bitnami) | Storing secrets safely in Git | Encrypts secret into a SealedSecret that only the controller can decrypt: [https://github.com/bitnami-labs/sealed-secrets](https://github.com/bitnami-labs/sealed-secrets) |
| External Secrets Operator | Sync external secrets into Kubernetes | Integrates cloud KMS and secret stores: [https://external-secrets.io](https://external-secrets.io) |

Good secrets management includes least-privilege access to secrets, automated rotation, auditing, and encrypting at rest.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/wvZOAiRg_-4PgnSp/images/Prep-Course-Certified-Cloud-Native-Platform-Engineering-Associate-CNPA/Domain-2-Platform-Observability-Security-and-Conformance/Kubernetes-Security-Essentials/secure-secrets-management-platform-practices.jpg?fit=max&auto=format&n=wvZOAiRg_-4PgnSp&q=85&s=efb06524c9dd35cf88df3032dec70279" alt="Slide titled &#x22;Secure Secrets Management – Platform Engineering Practices.&#x22; Four panels list External Secrets, Least Privilege, Rotation, and Auditing with icons and short notes about using external secret stores, limiting access, automating rotation, and tracking access." width="1920" height="1080" data-path="images/Prep-Course-Certified-Cloud-Native-Platform-Engineering-Associate-CNPA/Domain-2-Platform-Observability-Security-and-Conformance/Kubernetes-Security-Essentials/secure-secrets-management-platform-practices.jpg" />
</Frame>

Network security and CNI

Network security includes wire-level encryption (TLS/mTLS) and network isolation. Use NetworkPolicies (enforced by the CNI) to control pod-to-pod traffic and implement a default-deny posture with explicit allows for required communication.

Popular CNIs and service mesh technologies:

| Technology | Use case |
| - | - |
| Cilium | eBPF-based CNI for performance, policy, and observability: [https://cilium.io](https://cilium.io) |
| Calico | Policy-rich networking with network policy enforcement: [https://projectcalico.org](https://projectcalico.org) |
| Istio | Service mesh providing mTLS, traffic management, and observability: [https://istio.io/latest](https://istio.io/latest) |
| eBPF | Kernel-level observability and networking capabilities: [https://ebpf.io](https://ebpf.io) |

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/5GOdY0mbVYrHqNpp/images/Prep-Course-Certified-Cloud-Native-Platform-Engineering-Associate-CNPA/Domain-2-Platform-Observability-Security-and-Conformance/Kubernetes-Security-Essentials/cni-network-policies-encryption-microsegmentation-observability.jpg?fit=max&auto=format&n=5GOdY0mbVYrHqNpp&q=85&s=8bd2d48454d88678855a6f4fc66de586" alt="A presentation slide titled &#x22;CNI Security – Network Isolation and Policy Enforcement&#x22; showing four colored cards: Network Policies, Encryption, Micro-Segmentation, and Observability, each with a short description (e.g., pod-to-pod traffic control, wire-level encryption, fine-grained security, and network flow monitoring)." width="1920" height="1080" data-path="images/Prep-Course-Certified-Cloud-Native-Platform-Engineering-Associate-CNPA/Domain-2-Platform-Observability-Security-and-Conformance/Kubernetes-Security-Essentials/cni-network-policies-encryption-microsegmentation-observability.jpg" />
</Frame>

Example: default-deny with an explicit egress allow

```yaml theme={null}
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: default-deny-all
  namespace: pony-production
spec:
  podSelector: {}
  policyTypes:
  - Ingress
  - Egress
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: allow-pony-spawner-to-db
  namespace: pony-production
spec:
  podSelector:
    matchLabels:
      app: pony-spawner
  policyTypes:
  - Egress
  egress:
  - to:
    - podSelector:
        matchLabels:
          app: postgres
    ports:
    - protocol: TCP
      port: 5432
```

A default-deny posture with targeted allows is a practical path toward zero-trust networking in Kubernetes.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/wvZOAiRg_-4PgnSp/images/Prep-Course-Certified-Cloud-Native-Platform-Engineering-Associate-CNPA/Domain-2-Platform-Observability-Security-and-Conformance/Kubernetes-Security-Essentials/sparkle-pony-ranch-security-architecture.jpg?fit=max&auto=format&n=wvZOAiRg_-4PgnSp&q=85&s=7a07e88871d2e9b163637acdcd207573" alt="The image is a slide titled &#x22;Sparkle Pony Ranch Security Architecture&#x22; showing three colored avatar columns for Swati (Platform Security), Alan (Infrastructure Security), and Phuong (Application Security). Each column lists their responsibilities, e.g., RBAC and Vault secrets for platform, Cilium and pod limits for infrastructure, and app RBAC and network isolation for applications." width="1920" height="1080" data-path="images/Prep-Course-Certified-Cloud-Native-Platform-Engineering-Associate-CNPA/Domain-2-Platform-Observability-Security-and-Conformance/Kubernetes-Security-Essentials/sparkle-pony-ranch-security-architecture.jpg" />
</Frame>

Key takeaways

* RBAC with least privilege is the baseline. Use Namespaces, Roles, and RoleBindings consistently and audit permissions regularly.
* Enforce policies via admission controllers (PodSecurity admission controller, builtin controllers, and policy-as-code engines like OPA Gatekeeper or Kyverno).
* Kubernetes Secrets are Base64-encoded by default — not encrypted. Enable etcd encryption at rest and prefer external secret stores for rotation and auditing:
  * Vault: [https://www.vaultproject.io](https://www.vaultproject.io)
  * Sealed Secrets: [https://github.com/bitnami-labs/sealed-secrets](https://github.com/bitnami-labs/sealed-secrets)
  * ExternalSecrets: [https://external-secrets.io](https://external-secrets.io)
* Network security requires CNI-enforced NetworkPolicies and micro-segmentation. Consider eBPF CNIs (e.g., Cilium) or a service mesh (e.g., Istio) for mTLS and flow-level observability.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/wvZOAiRg_-4PgnSp/images/Prep-Course-Certified-Cloud-Native-Platform-Engineering-Associate-CNPA/Domain-2-Platform-Observability-Security-and-Conformance/Kubernetes-Security-Essentials/platform-security-key-takeaways.jpg?fit=max&auto=format&n=wvZOAiRg_-4PgnSp&q=85&s=8f84313bcf2bba5ee227303c77164939" alt="A slide titled &#x22;Key Takeaways – Platform Security&#x22; showing four colored boxes numbered 01–04. The boxes list RBAC, Admission Control, Secrets Management, and Network Security with brief descriptions of each." width="1920" height="1080" data-path="images/Prep-Course-Certified-Cloud-Native-Platform-Engineering-Associate-CNPA/Domain-2-Platform-Observability-Security-and-Conformance/Kubernetes-Security-Essentials/platform-security-key-takeaways.jpg" />
</Frame>

TLS, mutual TLS, service meshes, and observability tools are enhancements layered on Kubernetes’ core controls. A practical platform security posture combines authentication, authorization, admission controls, strong secrets management, and network policies to minimize risk while enabling teams to deliver value.

Thanks — this is the end of this lesson.

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/certified-cloud-native-platform-engineering-associate-cnpa/module/dfb06558-59c1-4a42-94f7-e4a13ad9c8af/lesson/60797e92-e879-4475-aef1-99f5d4ba695e" />
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.