Automated Kubernetes Certificate Rotation
This guide helps you install, understand, and operate the Kubernetes Certificate Rotator in to automate the rotation of Kubernetes certificates within your clusters.
TOC
Installation
See Cluster Plugin for installation instructions.
Note:
Currently supported:
- On-Premises clusters
- DCS clusters
How it works
This plugin handles automatic rotation for the following certificates.
Rotation Process
-
Load certificate information
The initial step involves gathering metadata for all target certificates. Since these certificates are stored in different paths on the host, their contents must be read from the respective files. To achieve this, a temporary Pod is created on the target node with the certificate directories mounted, allowing the Pod to read the information. The certificate's information is collected once per day. Certificate details (paths, expiration) are maintained in the ConfigMap
cpaas-system/node-local-certs-<node-name>. The encrypted CA certificate is stored in Secretcpaas-system/kubernetes-ca. -
Rotation Trigger Condition
The
notBeforeandnotAfterfields of the certificate indicate the validity period. Rotation is triggered if the remaining validity period is less than 20% or 30 days. -
Rotation queue
Certificates requiring rotation are placed in a queue for processing. The rotation program evaluates recent rotation activities and the urgency of pending tasks to decide whether to process them immediately. This prevents potential cluster health issues caused by the simultaneous rotation of multiple certificates.
-
Generate new certificates
The rotation program generates new certificates based on internally stored CA information. The rotation process creates a temporary Pod on the target node with the necessary certificate directories mounted, allowing for controlled file modifications.
-
Restart the components
Requiring restart:
kube-apiserver: It needs to be restarted to load the new certificates. During restart, it regenerates its internal loopback certificate (valid for one year, used only internally and can not be externally rotated).kube-controller-manager: It needs to be restarted to reload the kubeconfig file.kube-scheduler: It needs to be restarted to reload the kubeconfig file.kubelet: It needs to be restarted to reload the server certificate.
Restart method: Add annotations to the respective static Pods' YAML files to trigger the kubelet to recreate the Pods. To restart kubelet, mount the host filesystem with
hostPID is trueand run "systemctl restart kubelet" in the container.Auto-reloading:
- Etcd can auto-reload the certificates.
-
Rotation Timelines
kubeletcertificates: Rotate at 61 days (91-day validity)- Control plane certificates: Rotate at 292 days (365-day validity)
Operation Considerations
If kubelet is in an abnormal state during the rotation window and cannot rotate certificates automatically, manual rotation is required:
Operators must manually renew the certificates.
Run the following commands to renew the certificates manually:
For example to renew the kubelet.crt:
To download and prepare the cert-renew tool, run:
Optionally, download renew-all.sh to renew all certificates on the node: