Skip to content

Commit 7961595

Browse files
authored
Merge pull request #48110 from sftim/20240927_tweak_kubeadm_certs
Tweak kubeadm certs advice
2 parents 9a96b8a + e3c1c5b commit 7961595

File tree

3 files changed

+61
-52
lines changed

3 files changed

+61
-52
lines changed

content/en/docs/tasks/administer-cluster/cluster-upgrade.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ weight: 350
88
This page provides an overview of the steps you should follow to upgrade a
99
Kubernetes cluster.
1010

11+
The Kubernetes project recommends upgrading to the latest patch releases promptly, and
12+
to ensure that you are running a supported minor release of Kubernetes.
13+
Following this recommendation helps you to to stay secure.
14+
1115
The way that you upgrade a cluster depends on how you initially deployed it
1216
and on any subsequent changes.
1317

content/en/docs/tasks/administer-cluster/kubeadm/kubeadm-certs.md

Lines changed: 53 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,21 @@ Client certificates generated by [kubeadm](/docs/reference/setup-tools/kubeadm/)
1414
This page explains how to manage certificate renewals with kubeadm. It also covers other tasks related
1515
to kubeadm certificate management.
1616

17+
The Kubernetes project recommends upgrading to the latest patch releases promptly, and
18+
to ensure that you are running a supported minor release of Kubernetes.
19+
Following this recommendation helps you to to stay secure.
20+
21+
1722
## {{% heading "prerequisites" %}}
1823

1924

2025
You should be familiar with [PKI certificates and requirements in Kubernetes](/docs/setup/best-practices/certificates/).
2126

27+
This guide covers the usage of the `openssl` command (used for manual certificate signing,
28+
if you choose that approach), but you can use your preferred tools.
29+
30+
Some of the steps here use `sudo` for administrator access. You can use any equivalent tool.
31+
2232
<!-- steps -->
2333

2434
## Using custom certificates {#custom-certificates}
@@ -53,6 +63,9 @@ There are various ways to prepare the component credentials when using external
5363
[PKI certificates and requirements](/docs/setup/best-practices/certificates/) includes information
5464
on how to prepare all the required by kubeadm component credentials manually.
5565

66+
This guide covers the usage of the `openssl` command (used for manual certificate signing,
67+
if you choose that approach), but you can use your preferred tools.
68+
5669
### Preparation of credentials by signing CSRs generated by kubeadm
5770

5871
kubeadm can [generate CSR files](#signing-csr) that you can sign manually with tools like
@@ -87,7 +100,11 @@ Once the credentials are prepared on all nodes, call `kubeadm init` and `kubeadm
87100
join the cluster. kubeadm will use the existing kubeconfig and certificate files under `/etc/kubernetes/`
88101
and its `pki` sub directory.
89102

90-
## Check certificate expiration
103+
## Certificate expiry and management {#check-certificate-expiration}
104+
105+
{{< note >}}
106+
`kubeadm` cannot manage certificates signed by an external CA.
107+
{{< /note >}}
91108

92109
You can use the `check-expiration` subcommand to check when certificates expire:
93110

@@ -123,20 +140,15 @@ by kubeadm (`admin.conf`, `controller-manager.conf` and `scheduler.conf`).
123140
Additionally, kubeadm informs the user if the certificate is externally managed; in this case, the
124141
user should take care of managing certificate renewal manually/using other tools.
125142

126-
{{< warning >}}
127-
`kubeadm` cannot manage certificates signed by an external CA.
128-
{{< /warning >}}
129-
130-
{{< note >}}
131-
`kubelet.conf` is not included in the list above because kubeadm configures kubelet
143+
The `kubelet.conf` configuration file is not included in the list above because kubeadm
144+
configures kubelet
132145
for [automatic certificate renewal](/docs/tasks/tls/certificate-rotation/)
133146
with rotatable certificates under `/var/lib/kubelet/pki`.
134147
To repair an expired kubelet client certificate see
135148
[Kubelet client certificate rotation fails](/docs/setup/production-environment/tools/kubeadm/troubleshooting-kubeadm/#kubelet-client-cert).
136-
{{< /note >}}
137149

138-
{{< warning >}}
139-
On nodes created with `kubeadm init`, prior to kubeadm version 1.17, there is a
150+
{{< note >}}
151+
On nodes created with `kubeadm init` from versions prior to kubeadm version 1.17, there is a
140152
[bug](https://github.com/kubernetes/kubeadm/issues/1753) where you manually have to modify the
141153
contents of `kubelet.conf`. After `kubeadm init` finishes, you should update `kubelet.conf` to
142154
point to the rotated kubelet client certificates, by replacing `client-certificate-data` and
@@ -146,7 +158,7 @@ point to the rotated kubelet client certificates, by replacing `client-certifica
146158
client-certificate: /var/lib/kubelet/pki/kubelet-client-current.pem
147159
client-key: /var/lib/kubelet/pki/kubelet-client-current.pem
148160
```
149-
{{< /warning >}}
161+
{{< /note >}}
150162
151163
## Automatic certificate renewal
152164
@@ -158,26 +170,24 @@ if you don't have specific requirements on certificate renewal and perform Kuber
158170
upgrades regularly (less than 1 year in between each upgrade), kubeadm will take care of keeping
159171
your cluster up to date and reasonably secure.
160172
161-
{{< note >}}
162-
It is a best practice to upgrade your cluster frequently in order to stay secure.
163-
{{< /note >}}
164-
165173
If you have more complex requirements for certificate renewal, you can opt out from the default
166174
behavior by passing `--certificate-renewal=false` to `kubeadm upgrade apply` or to `kubeadm
167175
upgrade node`.
168176

169-
{{< warning >}}
170-
Prior to kubeadm version 1.17 there is a [bug](https://github.com/kubernetes/kubeadm/issues/1818)
171-
where the default value for `--certificate-renewal` is `false` for the `kubeadm upgrade node`
172-
command. In that case, you should explicitly set `--certificate-renewal=true`.
173-
{{< /warning >}}
174-
175177
## Manual certificate renewal
176178

177-
You can renew your certificates manually at any time with the `kubeadm certs renew` command, with the appropriate command line options.
179+
You can renew your certificates manually at any time with the `kubeadm certs renew` command,
180+
with the appropriate command line options. If you are running cluster with a replicated control
181+
plane, this command needs to be executed on all the control-plane nodes.
178182

179183
This command performs the renewal using CA (or front-proxy-CA) certificate and key stored in `/etc/kubernetes/pki`.
180184

185+
`kubeadm certs renew` uses the existing certificates as the authoritative source for attributes
186+
(Common Name, Organization, subject alternative name) and does not rely on the `kubeadm-config`
187+
ConfigMap.
188+
Even so, the Kubernetes project recommends keeping the served certificate and the associated
189+
values in that ConfigMap synchronized, to avoid any risk of confusion.
190+
181191
After running the command you should restart the control plane Pods. This is required since
182192
dynamic certificate reload is currently not supported for all components and certificates.
183193
[Static Pods](/docs/tasks/configure-pod-container/static-pod/) are managed by the local kubelet
@@ -188,33 +198,25 @@ The kubelet will terminate the Pod if it's no longer in the manifest directory.
188198
You can then move the file back and after another `fileCheckFrequency` period, the kubelet will recreate
189199
the Pod and the certificate renewal for the component can complete.
190200

191-
{{< warning >}}
192-
If you are running an HA cluster, this command needs to be executed on all the control-plane nodes.
193-
{{< /warning >}}
194-
195-
{{< note >}}
196-
`certs renew` uses the existing certificates as the authoritative source for attributes (Common
197-
Name, Organization, SAN, etc.) instead of the `kubeadm-config` ConfigMap. It is strongly recommended
198-
to keep them both in sync.
199-
{{< /note >}}
200-
201-
`kubeadm certs renew` can renew any specific certificate or, with the subcommand `all`, it can renew all of them, as shown below:
201+
`kubeadm certs renew` can renew any specific certificate or, with the subcommand `all`, it can renew all of them:
202202

203203
```shell
204+
# If you are running cluster with a replicated control plane, this command
205+
# needs to be executed on all the control-plane nodes.
204206
kubeadm certs renew all
205207
```
206208

207-
{{< note >}}
209+
### Copying the administrator certificate (optional) {#admin-certificate-copy}
210+
208211
Clusters built with kubeadm often copy the `admin.conf` certificate into
209212
`$HOME/.kube/config`, as instructed in [Creating a cluster with kubeadm](/docs/setup/production-environment/tools/kubeadm/create-cluster-kubeadm/).
210213
On such a system, to update the contents of `$HOME/.kube/config`
211-
after renewing the `admin.conf`, you must run the following commands:
214+
after renewing the `admin.conf`, you could run the following commands:
212215

213216
```shell
214217
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
215218
sudo chown $(id -u):$(id -g) $HOME/.kube/config
216219
```
217-
{{< /note >}}
218220

219221
## Renew certificates with the Kubernetes certificates API
220222

@@ -430,16 +432,13 @@ as extra SANs and custom IP addresses must be stored in the same configuration
430432
file and used for all relevant kubeadm commands by passing it as `--config`.
431433

432434
{{< note >}}
433-
This guide will cover the usage of the `openssl` command for singing the CSRs,
434-
but you can use your preferred tools.
435-
{{< /note >}}
435+
This guide uses the default Kubernetes directory `/etc/kubernetes`, which requires
436+
a super user. If you are following this guide and are using directories that you can
437+
write to (typically, this means running `kubeadm` with `--cert-dir` and `--kubeconfig-dir`)
438+
then you can omit the `sudo` command).
436439

437-
{{< note >}}
438-
This guide will use the default Kubernetes directory `/etc/kubernetes`, which requires
439-
a super user. If you are following this guide with permissive directories
440-
(by passing `--cert-dir` and `--kubeconfig-dir`) you can omit the `sudo` command).
441-
But note that the resulted files must be copied to the `/etc/kubernetes` tree,
442-
so that `kubeadm init` or `kubeadm join` will find them.
440+
You must then copy the files that you produced over to within the `/etc/kubernetes`
441+
directory so that `kubeadm init` or `kubeadm join` will find them.
443442
{{< /note >}}
444443

445444
### Preparing CA and service account files
@@ -460,8 +459,9 @@ private keys) that kubeadm needs for a control plane node.
460459

461460
{{< note >}}
462461
If you are using an external CA, you must generate the same files out of band and manually
463-
copy them to the primary control plane node in `/etc/kubernetes`. Once all CSRs
464-
are signed, you can delete the root CA key (`ca.key`) as noted in the
462+
copy them to the primary control plane node in `/etc/kubernetes`.
463+
464+
Once all CSRs are signed, you can delete the root CA key (`ca.key`) as noted in the
465465
[External CA mode](#external-ca-mode) section.
466466
{{< /note >}}
467467

@@ -500,9 +500,10 @@ That is because the active kube-controller-manager will be responsible
500500
for signing new kubelet client certificates.
501501

502502
{{< note >}}
503-
Processing the `kubelet.conf.csr` on the primary control plane node
504-
(`kubeadm init`) is required, because that is considered the node that
505-
bootstraps the cluster and a pre-populated `kubelet.conf` is needed.
503+
You must process the `kubelet.conf.csr` file on the primary control plane node
504+
(the host where you originally ran `kubeadm init`). This is because `kubeadm`
505+
considers that as the node that bootstraps the cluster, and a pre-populated
506+
`kubelet.conf` is needed.
506507
{{< /note >}}
507508

508509
#### Control plane nodes
@@ -539,8 +540,8 @@ the steps for worker nodes entirely.
539540

540541
{{< note >}}
541542
If you are using external CA and already have CA serial number files (`.srl`) for
542-
`openssl` you can copy such files to a kubeadm node where CSRs will be processed.
543-
`.srl` files to copy are `/etc/kubernetes/pki/ca.srl`,
543+
`openssl`, you can copy such files to a kubeadm node where CSRs will be processed.
544+
The `.srl` files to copy are `/etc/kubernetes/pki/ca.srl`,
544545
`/etc/kubernetes/pki/front-proxy-ca.srl` and `/etc/kubernetes/pki/etcd/ca.srl`.
545546
The files can be then moved to a new node where CSR files will be processed.
546547

content/en/docs/tasks/administer-cluster/kubeadm/kubeadm-upgrade.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ please refer to following pages instead:
2121
- [Upgrading a kubeadm cluster from {{< skew currentVersionAddMinor -4 >}} to {{< skew currentVersionAddMinor -3 >}}](https://v{{< skew currentVersionAddMinor -3 "-" >}}.docs.kubernetes.io/docs/tasks/administer-cluster/kubeadm/kubeadm-upgrade/)
2222
- [Upgrading a kubeadm cluster from {{< skew currentVersionAddMinor -5 >}} to {{< skew currentVersionAddMinor -4 >}}](https://v{{< skew currentVersionAddMinor -4 "-" >}}.docs.kubernetes.io/docs/tasks/administer-cluster/kubeadm/kubeadm-upgrade/)
2323

24+
The Kubernetes project recommends upgrading to the latest patch releases promptly, and
25+
to ensure that you are running a supported minor release of Kubernetes.
26+
Following this recommendation helps you to to stay secure.
27+
2428
The upgrade workflow at high level is the following:
2529

2630
1. Upgrade a primary control plane node.

0 commit comments

Comments
 (0)