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.

CAUTION

Use this plugin only when certificate rotation is required

Kubernetes certificates are valid for 10 years by default. Enabling this plugin changes certificates managed by the plugin to short-lived certificates: 91 days for kubelet certificates and 365 days for control-plane certificates.

Automatic renewal restarts components such as the API server and kubelet, which may affect cluster availability and business workloads. If rotation takes longer than 30 seconds, a node may become NotReady and its pods may be evicted.

If certificate rotation is not required, do not install this plugin.

Installation

See Cluster Plugin for installation instructions.

Note:

  • Currently supported:

    • On-Premises clusters
    • DCS clusters

Configuration

The following are the plugin's default certificate settings. The controller uses the configured renewal threshold for each certificate type and checks certificates at the configured interval.

Certificate settings

CertificateValidity periodDefault renewal thresholdApproximate rotation point
Control plane8760h (365 days)1752h (73 days remaining)About 292 days after issuance
Kubelet2184h (91 days)720h (30 days remaining)About 61 days after issuance

With the default settings, certificates are renewed when the remaining validity is less than 20% or 30 days, whichever threshold is reached first. This corresponds to about 292 days for control-plane certificates and about 61 days for kubelet certificates after issuance. Actual timing can vary by one check interval. If you override the deployment values, the configured renewal thresholds take precedence.

Operation settings

SettingDefaultDescription
Check interval24hInterval between certificate checks.
Renew kubelet client certificateDisabledAlso renew the client certificate referenced by kubelet.conf.

How it works

This plugin handles automatic rotation for the following certificates.

Certificate fileFunctionNode Type
apiserver.crtServer certificate for kube-apiserverControl Plane Node
apiserver-etcd-client.crtClient certificate for kube-apiserver to access etcdControl Plane Node
apiserver-kubelet-client.crtClient certificate for kube-apiserver to access kubeletControl Plane Node
front-proxy-client.crtClient certificate for kube-apiserver to access aggregated API serversControl Plane Node
etcd/server.crtServer certificate for etcdControl Plane Node
etcd/peer.crtPeer communication certificate between etcd membersControl Plane Node
/root/.kube/config, admin.conf, super-admin.confClient certificate in kubeconfig for cluster administrationControl Plane Node
controller-manager.confClient certificate in kubeconfig for kube-controller-managerControl Plane Node
scheduler.confClient certificate in kubeconfig for kube-schedulerControl Plane Node
kubelet.crtServer certificate for kubeletAll Nodes
kubelet-client-current.pemClient certificate for kubelet (referenced by kubelet.conf)All Nodes

Rotation Process

  1. 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 Secret cpaas-system/kubernetes-ca.

  2. Rotation Trigger Condition

    The notBefore and notAfter fields of the certificate indicate the validity period. By default, rotation is triggered when the remaining validity is less than 20% or 30 days, whichever threshold is reached first. The controller applies the configured renewal threshold for each certificate type, so overridden values take precedence. A certificate whose validity period differs from the expected duration is also renewed.

  3. 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.

  4. 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.

  5. 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 true and run "systemctl restart kubelet" in the container.

    Auto-reloading:

    • Etcd can auto-reload the certificates.

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:

cert-renew --ca-cert <ca-cert-path> --ca-key <ca-key-path> --days <days> <certificate or kubeconfig 1> <certificate or kubeconfig 2> ...

For example to renew the kubelet.crt:

cert-renew --ca-cert /etc/kubernetes/pki/ca.crt --ca-key /etc/kubernetes/pki/ca.key --days 91 /etc/kubernetes/pki/kubelet.crt

To download and prepare the cert-renew tool, run:

curl "$(kubectl get services -n cpaas-system frontend -o jsonpath='{.spec.clusterIP}'):8080/cluster-cert-rotator/download/cert-renew" -o ./cert-renew && chmod +x ./cert-renew

Optionally, download renew-all.sh to renew all certificates on the node:

curl "$(kubectl get services -n cpaas-system frontend -o jsonpath='{.spec.clusterIP}'):8080/cluster-cert-rotator/download/renew-all.sh" -o ./renew-all.sh