Skip to main content
Secure your Kubernetes cluster by generating TLS certificates using OpenSSL. This guide walks through creating a root Certificate Authority (CA), issuing client certificates for users and system components, and setting up server certificates for etcd, the API server, and kubelet nodes.
  • Ensure OpenSSL is installed (openssl version).
  • Work in a secure directory with strict file permissions.
  • Replace placeholder IPs, hostnames, and node names to match your environment.

Certificate Overview


1. Generate the CA Certificate

Protect your CA private key at all costs—this key signs every other certificate in your cluster.
Protect ca.key securely. If compromised, all cluster certificates become untrusted.
  • ca.key: Private key for your root CA.
  • ca.csr: Certificate Signing Request with CA identity.
  • ca.crt: Self-signed root certificate trusted by all components.

2. Generate Client Certificates

Client certificates authenticate users and system services to the API server. All CSRs are signed by the root CA.

2.1 Admin User

Create a key, CSR, and certificate for the cluster administrator. Membership in system:masters grants full control.
  • Common Name (CN): Identifier seen in API audit logs.
  • Organization (O): Group membership.

2.2 System Component Users

Repeat the process for each Kubernetes control-plane component:
  • kube-scheduler
  • kube-controller-manager
  • kube-proxy
The image shows a certificate for "Kube Scheduler" with related icons and text about generating keys, certificate signing requests, and signing certificates.
Each CSR’s CN must be prefixed with system: (e.g., /CN=system:kube-scheduler).

3. Using Client Certificates

You can invoke the API directly with curl:
Or embed credentials in a kubeconfig file:
Most Kubernetes clients leverage kubeconfig to manage certificates and endpoints.

4. Server-Side Certificates

All Kubernetes servers must trust the CA root (ca.crt) and present valid certificates signed by it.
The image is a diagram showing the organization of client and server certificates for Kubernetes components, including keys and certificates for various services like kube-scheduler, kube-controller-manager, and kubelet.

4.1 etcd Server and Peers

Generate a certificate for the etcd server and peers in HA clusters:
For peer communication, use /CN=etcd-peer. Then configure your etcd service:
The image illustrates the structure of ETCD servers and peers, showing certificates and keys for secure communication. It includes a visual representation of a certificate labeled "ETCD-SERVER."

4.2 kube-apiserver

The API server certificate must cover all DNS names and IP addresses used by the service. Create an OpenSSL config (openssl.cnf) with an [ alt_names ] section:
Generate and sign the CSR:
The image shows a digital certificate for a Kube API server, including details like IP addresses and a key icon representing security credentials.
Configure the API server service:

4.3 Kubelet Server

Each Kubernetes node requires its own TLS certificate named after the node:
  • CN: system:node:<nodeName>
  • O: system:nodes
Embed the certificates in the kubelet configuration (/var/lib/kubelet/config.yaml):
The image shows a diagram of Kubernetes nodes with client certificates for three nodes (node01, node02, node03) under the "KUBECTL NODES (CLIENT CERT)" heading, illustrating their authentication setup.

That completes the Kubernetes PKI certificate generation process. For automation, explore how kubeadm handles this in the docs.

Watch Video