> ## 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 Primitives

> Overview of Kubernetes security primitives covering host hardening, API server authentication and RBAC authorization, TLS/mTLS for components, and NetworkPolicy best practices.

In this guide we cover the core Kubernetes security primitives you should understand to secure clusters running production workloads. Kubernetes is widely used for mission-critical applications, so protecting the control plane, nodes, and workload communications is essential. This article gives a focused overview of the most important building blocks and practical recommendations for each area.

## Host security (Control plane and worker nodes)

All access to the machines that host control plane components and worker nodes must be hardened. Attackers who gain shell access to these hosts can pivot into workloads and cluster services.

Key host-hardening practices:

* Disable direct root logins and disable password-based SSH authentication. Use SSH key-based authentication only.
* Restrict SSH access with allowlists (by IP, bastion host, or IAM-based access).
* Apply OS-level hardening (SELinux/AppArmor, minimal packages, up-to-date kernels).
* Restrict cloud/virtualization management consoles and metadata APIs.
* Use centralized logging and host-level intrusion detection/monitoring.

<Callout icon="warning" color="#FF6B6B">
  If a host (control plane or worker) is compromised, an attacker can potentially gain control of workloads and cluster services. Prioritize host-level hardening and access controls.
</Callout>

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/szXnfDEgCPpDiwaI/images/Certified-Kubernetes-Administrator-CKA/Security/Kubernetes-Security-Primitives/secure-hosts-servers-ssh-key-only.jpg?fit=max&auto=format&n=szXnfDEgCPpDiwaI&q=85&s=1334bc7c0983cbfccbf6a1fbba33dfad" alt="A dark-themed slide titled &#x22;Secure Hosts&#x22; showing three stylized server tower icons in the center. Two rounded labels beneath read &#x22;Password based authentication disabled&#x22; and &#x22;SSH Key based authentication.&#x22;" width="1920" height="1080" data-path="images/Certified-Kubernetes-Administrator-CKA/Security/Kubernetes-Security-Primitives/secure-hosts-servers-ssh-key-only.jpg" />
</Frame>

## API server: Risks, authentication, and authorization

The kube-apiserver is the central control plane component—all management operations (kubectl, client libraries, controllers) interact with it. Because it exposes powerful cluster APIs, you must control access carefully.

Two fundamental questions to answer:

* Who can access the API server? (Authentication)
* What are they allowed to do? (Authorization)

### Authentication — Who can access the API server?

Kubernetes supports several authentication methods. Choose a method appropriate for each actor (human user, system component, or in-cluster workload).

| Method | Typical use case | Notes / Recommendation |
| - | - | - |
| Static token files | Legacy tooling, bootstrap scripts | Not recommended for production due to lack of rotation |
| TLS client certificates | Components (kubelets, controller manager) and service accounts | Common for component-to-component auth; requires certificate lifecycle management |
| External identity providers (OIDC, LDAP) | Human users and SSO integration | Use OIDC (e.g., Dex, Keycloak) for federated authentication and central identity management |
| Service accounts | In-cluster workloads (Pods) | Use for pod identities; pair with RBAC and limit token scope and lifetime |

Best practice: Integrate an external identity provider (OIDC) for user authentication and enforce short-lived credentials where possible.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/szXnfDEgCPpDiwaI/images/Certified-Kubernetes-Administrator-CKA/Security/Kubernetes-Security-Primitives/authentication-access-methods-slide.jpg?fit=max&auto=format&n=szXnfDEgCPpDiwaI&q=85&s=a18517725206196536e0fa51013020ef" alt="A presentation slide titled &#x22;Authentication&#x22; with a central &#x22;Who can access?&#x22; button. It lists four access methods: Static Token File, Certificates, External Authentication providers - LDAP, and Service Accounts on a dark blue background." width="1920" height="1080" data-path="images/Certified-Kubernetes-Administrator-CKA/Security/Kubernetes-Security-Primitives/authentication-access-methods-slide.jpg" />
</Frame>

### Authorization — What can authenticated subjects do?

After authentication, authorization determines permitted actions. RBAC (Role-Based Access Control) is the most widely used authorization mechanism in Kubernetes and should be the default choice for most clusters.

| Authorization mode | Purpose | When to use |
| - | - | - |
| RBAC | Assign roles and bind them to users, groups, and service accounts | Standard for most clusters; implement least privilege |
| ABAC (Attribute-Based) | Policy based on attributes in requests | Deprecated/legacy in many setups; avoid for new clusters |
| Node Authorizer | Restricts kubelet access to API objects related to its node | Enabled in clusters to protect node-specific resources |
| Webhook authorizer | External decision point for authorization | Use for custom or centralized policy engines |

Best practice: Implement least privilege via RBAC, create narrowly scoped Roles/ClusterRoles, and prefer RoleBindings over ClusterRoleBindings unless cluster-wide permissions are explicitly required.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/szXnfDEgCPpDiwaI/images/Certified-Kubernetes-Administrator-CKA/Security/Kubernetes-Security-Primitives/authorization-rbac-abac-node-webhook.jpg?fit=max&auto=format&n=szXnfDEgCPpDiwaI&q=85&s=047a02eee7f2fa4dffcc41e1c08be75a" alt="A dark presentation slide titled &#x22;Authorization&#x22; with a central button labeled &#x22;What can they do?&#x22; and four rounded option buttons: &#x22;RBAC Authorization,&#x22; &#x22;ABAC Authorization,&#x22; &#x22;Node Authorization,&#x22; and &#x22;Webhook Mode.&#x22; The slide has a navy background and a small &#x22;© Copyright KodeKloud&#x22; note in the bottom-left." width="1920" height="1080" data-path="images/Certified-Kubernetes-Administrator-CKA/Security/Kubernetes-Security-Primitives/authorization-rbac-abac-node-webhook.jpg" />
</Frame>

## TLS and secure control plane / node communications

All control plane components (etcd, kube-apiserver, kube-controller-manager, kube-scheduler) and node components (kubelet, kube-proxy) should use TLS to encrypt and authenticate traffic. In production, mutual TLS (mTLS) with signed certificates is standard.

Key recommendations:

* Protect etcd with TLS and restricted access; enable encryption at rest where available.
* Use mTLS between kube-apiserver and kubelets, and between other control plane components.
* Implement certificate rotation and automate the certificate lifecycle.
* Limit API server access to trusted networks and load balancers; use API aggregation and admission controllers (e.g., PodSecurity, OPA/Gatekeeper) for additional enforcement.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/szXnfDEgCPpDiwaI/images/Certified-Kubernetes-Administrator-CKA/Security/Kubernetes-Security-Primitives/kubernetes-control-plane-tls-certificates.jpg?fit=max&auto=format&n=szXnfDEgCPpDiwaI&q=85&s=55796e9beb9e07470669e84cdb2b5cc2" alt="A diagram titled &#x22;TLS Certificates&#x22; showing Kubernetes control-plane components. It depicts etcd, kube-apiserver, kube-scheduler, kube-controller-manager, kubelet and kube-proxy connected by certificate icons to indicate TLS-secured communication." width="1920" height="1080" data-path="images/Certified-Kubernetes-Administrator-CKA/Security/Kubernetes-Security-Primitives/kubernetes-control-plane-tls-certificates.jpg" />
</Frame>

## Network-level security between workloads

By default, Kubernetes allows all pod-to-pod traffic across the cluster network. Use NetworkPolicy resources to restrict connectivity between pods by selectors, ports, and protocols. Enforcement depends on the cluster's CNI plugin—ensure your CNI supports NetworkPolicies.

Important NetworkPolicy principles:

* Start with a “deny by default” posture: create a default deny ingress/egress policy for namespaces, then allow required traffic.
* Use label selectors to express intent and keep policies maintainable.
* Test policies in non-production environments to verify connectivity and monitoring.

Example minimal ingress NetworkPolicy (YAML):

```yaml theme={null}
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: allow-frontend-to-backend
  namespace: production
spec:
  podSelector:
    matchLabels:
      app: backend
  policyTypes:
  - Ingress
  ingress:
  - from:
    - podSelector:
        matchLabels:
          app: frontend
    ports:
    - protocol: TCP
      port: 8080
```

<Callout icon="lightbulb" color="#1CB2FE">
  NetworkPolicies only take effect if your CNI/plugin enforces them. Verify compatibility and use network policy logging or flow exporters to audit traffic after applying policies.
</Callout>

## Summary / Conclusion

This article presented a concise overview of Kubernetes security primitives and recommended practices:

* Host hardening and tightly controlled SSH access to nodes.
* Strong API server authentication (prefer external identity providers for users) and RBAC-based authorization following least privilege.
* TLS/mTLS for control plane and node communications; secure etcd and automate certificate rotation.
* NetworkPolicies to enforce pod-to-pod isolation; adopt a deny-by-default approach.

Each of these domains deserves deeper, hands-on exploration for implementation details, automation, and continuous monitoring.

## Links and references

* Kubernetes Authentication: [https://kubernetes.io/docs/reference/access-authn-authz/authentication/](https://kubernetes.io/docs/reference/access-authn-authz/authentication/)
* Kubernetes RBAC: [https://kubernetes.io/docs/reference/access-authn-authz/rbac/](https://kubernetes.io/docs/reference/access-authn-authz/rbac/)
* NetworkPolicy docs: [https://kubernetes.io/docs/concepts/services-networking/network-policies/](https://kubernetes.io/docs/concepts/services-networking/network-policies/)
* etcd security guide: [https://etcd.io/docs/v3.5/op-guide/security/](https://etcd.io/docs/v3.5/op-guide/security/)
* OIDC in Kubernetes: [https://kubernetes.io/docs/reference/access-authn-authz/authentication/#openid-connect-tokens](https://kubernetes.io/docs/reference/access-authn-authz/authentication/#openid-connect-tokens)

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/cka-certification-course-certified-kubernetes-administrator/module/77826599-d456-4cb5-8cbc-b713cc077b45/lesson/99a21aa8-bf51-471d-a2e8-9daf8de96971" />
</CardGroup>


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