|
| 1 | +## Automatically rotating certificates using Kubeadm Control Plane provider |
| 2 | + |
| 3 | +When using Kubeadm Control Plane provider (KCP) it is possible to configure automatic certificate rotations. KCP does this by triggering a rollout when the certificates on the control plane machines are about to expire. |
| 4 | + |
| 5 | +If configured, rollout for certificate expiry is enabled for all new machines created using ClusterAPI v1.3 and above. To enable it for existing machines see [Enabling Certificate Expiry Rollout for Existing Machines](#enabling-certificate-expiry-rollout-for-existing-clusters)(#enabling-certificate-expiry-rollout-for-existing-clusters) |
| 6 | + |
| 7 | +### Configuring Machine Rollout |
| 8 | + |
| 9 | +To configure a rollout on the KCP machines you need to set `.rolloutBefore.certificatesExpiryDays` (minimum of 7 days). |
| 10 | + |
| 11 | +Example: |
| 12 | +```yaml |
| 13 | +apiVersion: controlplane.cluster.x-k8s.io/v1beta1 |
| 14 | +kind: KubeadmControlPlane |
| 15 | +metadata: |
| 16 | + name: example-control-plane |
| 17 | +spec: |
| 18 | + rolloutBefore: |
| 19 | + certificatesExpiryDays: 21 # trigger a rollout if certificates expire within 21 days |
| 20 | + kubeadmConfigSpec: |
| 21 | + clusterConfiguration: |
| 22 | + ... |
| 23 | + initConfiguration: |
| 24 | + ... |
| 25 | + joinConfiguration: |
| 26 | + ... |
| 27 | + machineTemplate: |
| 28 | + infrastructureRef: |
| 29 | + ... |
| 30 | + replicas: 1 |
| 31 | + version: v1.23.3 |
| 32 | +``` |
| 33 | +
|
| 34 | +It is strongly recommended to set the `certificatesExpiryDays` to a large enough value so that all the machines will have time to complete rollout well in advance before the certificates expire. |
| 35 | + |
| 36 | +### Triggering Machine Rollout for Certificate Expiry |
| 37 | + |
| 38 | +KCP uses the value in the corresponding Control Plane machine's `Machine.Status.CertificatesExpiryDate` to check if a machine's certificates are going to expire and if it needs to be rolled out. |
| 39 | + |
| 40 | +`Machine.Status.CertificatesExpiryDate` gets its value from one of the following 2 places: |
| 41 | + |
| 42 | +* `machine.cluster.x-k8s.io/certificates-expiry` annotation value on the Machine object. This annotation is not applied by default and it can be set by users to opt-in in this feature for existing control plane machines (see instructions below). |
| 43 | +* `machine.cluster.x-k8s.io/certificates-expiry` annotation value on the Bootstrap Config object referenced by the machine. This value is automatically set for machines bootstrapped with CABPK with CAPI >= v1.3. |
| 44 | + |
| 45 | +The annotation value is a [RFC3339] format timestamp. The annotation value on the machine object, if provided, will take precedence. |
| 46 | + |
| 47 | +<aside class="note warning"> |
| 48 | + |
| 49 | +<h1> Approximate Certificate Expiry Time </h1> |
| 50 | + |
| 51 | +The time captured in the Bootstrap Config annotation is an approximate time at which the machine certificates will expire (1 year from creation). The time captured in the annotation will be a little earlier than the actual certificate expiry time. |
| 52 | + |
| 53 | +</aside> |
| 54 | + |
| 55 | +### Enabling Certificate Expiry Rollout for Existing Machines |
| 56 | + |
| 57 | +For rollout for certificate expiry to work on existing machines we need to update existing control plane machines with the current certificate expiry time. To do this do the following for each of the control plane machines: |
| 58 | + |
| 59 | +* SSH into the control plane node and get the current certificate expiry time using `kubeadm certs check-expiration`. From the output note the certificate expiry time of the `apiserver` certificate. |
| 60 | +* Add the certificate expiry time as the `machine.cluster.x-k8s.io/certificates-expiry` annotation value on the control plane machine object. The value should be a [RFC3339] format timestamp. |
| 61 | +Example: If the certificate expiry time is `Sep 29, 2023 02:08 UTC` add `machine.cluster.x-k8s.io/certificates-expiry: 2023-09-29T02:08:00Z` as an annotation on the control plane machine object. |
| 62 | + |
| 63 | +<!-- links --> |
| 64 | +[RFC3339]: https://www.ietf.org/rfc/rfc3339.txt |
0 commit comments