TLS basics
TLS uses a public/private key pair: the public key encrypts data, the private key decrypts it.
Generating keys and certificates
| Public key files | Private key files |
|---|---|
*.crt, *.pem | *.key, *-key.pem |
| Term | Meaning |
|---|---|
| CA | Certificate Authority |
| CSR | Certificate Signing Request |
| CRT | Certificate |
| PEM | Privacy Enhanced Mail — a Base64-encoded format that can hold certificates, private keys, certificate chains, and public keys |
| KEY | Private key |
TLS in Kubernetes
All communication between Kubernetes components must be encrypted and secure. Kubernetes uses server certificates to secure inter-component communication and client certificates to authenticate users and applications. All certificates must be signed by a Certificate Authority. Kubernetes requires at least one CA, but you can configure multiple.Server certificates
Components acting as servers need server certificates:| Component | Example certificate files |
|---|---|
| kube-apiserver | kube-apiserver.crt, kube-apiserver.key |
| etcd | etcd.crt, etcd.key |
| kubelet | kubelet.crt, kubelet.key |
Client certificates
Components and users accessing the kube-apiserver need client certificates:| Client | Example certificate files |
|---|---|
| kube-scheduler | kube-scheduler.crt, kube-scheduler.key |
| kube-controller-manager | kube-controller-manager.crt, kube-controller-manager.key |
| kube-proxy | kube-proxy.crt, kube-proxy.key |
| Admin (kubectl) | admin.crt, admin.key |
| kube-apiserver (as client to etcd/kubelet) | reuse kube-apiserver.crt or create new |
Manually creating certificates
Generate the CA certificate
ca.key) and root certificate (ca.crt).Generate client certificates
The following example creates a certificate for the admin user. Repeat for other clients that need access to the kube-apiserver.To differentiate between the admin user and regular users (e.g.,
john), specify the group in the CSR subject:system:masters is a predefined Kubernetes group with admin privileges.kubelet client certificates use the naming format
system:node:<node-name> and the group system:nodes. This allows the kube-apiserver to identify which node is authenticating and apply the correct node authorizer permissions. After generating kubelet certificates, configure them in kubeconfig files.Generate server certificates
Server components (kube-apiserver, etcd, kubelet) may be deployed in high-availability configurations and need peer certificates for inter-instance communication.etcd — configure server, peer, and CA certificates:kube-apiserver — because many names and aliases are used to reach it, all must be embedded in the certificate as Subject Alternative Names (SANs):Reference kube-apiserver certificate flags:kubelet — generate a certificate per worker node, named after the node. Configure them in the kubelet config file:
etcd.yaml
kuberneteskubernetes.defaultkubernetes.default.svckubernetes.default.svc.cluster.local- IP addresses (e.g.,
10.89.0.2)
openssl.cnf
kube-apiserver.yaml
kubelet-config.yaml
Inspecting certificate details
When Kubernetes components are deployed as pods (the most common approach), inspect certificates directly from the pod manifest.| Field | Meaning |
|---|---|
Issuer: CN = kubernetes | The CA that signed the certificate |
Not After | The certificate expiry date |
Subject: CN = kube-apiserver | The common name of the certificate |
X509v3 Subject Alternative Name | All valid aliases and IPs for this certificate |