@@ -14,11 +14,21 @@ Client certificates generated by [kubeadm](/docs/reference/setup-tools/kubeadm/)
14
14
This page explains how to manage certificate renewals with kubeadm. It also covers other tasks related
15
15
to kubeadm certificate management.
16
16
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
+
17
22
## {{% heading "prerequisites" %}}
18
23
19
24
20
25
You should be familiar with [ PKI certificates and requirements in Kubernetes] ( /docs/setup/best-practices/certificates/ ) .
21
26
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
+
22
32
<!-- steps -->
23
33
24
34
## Using custom certificates {#custom-certificates}
@@ -53,6 +63,9 @@ There are various ways to prepare the component credentials when using external
53
63
[ PKI certificates and requirements] ( /docs/setup/best-practices/certificates/ ) includes information
54
64
on how to prepare all the required by kubeadm component credentials manually.
55
65
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
+
56
69
### Preparation of credentials by signing CSRs generated by kubeadm
57
70
58
71
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
87
100
join the cluster. kubeadm will use the existing kubeconfig and certificate files under ` /etc/kubernetes/ `
88
101
and its ` pki ` sub directory.
89
102
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 >}}
91
108
92
109
You can use the ` check-expiration ` subcommand to check when certificates expire:
93
110
@@ -123,20 +140,15 @@ by kubeadm (`admin.conf`, `controller-manager.conf` and `scheduler.conf`).
123
140
Additionally, kubeadm informs the user if the certificate is externally managed; in this case, the
124
141
user should take care of managing certificate renewal manually/using other tools.
125
142
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
132
145
for [ automatic certificate renewal] ( /docs/tasks/tls/certificate-rotation/ )
133
146
with rotatable certificates under ` /var/lib/kubelet/pki ` .
134
147
To repair an expired kubelet client certificate see
135
148
[ Kubelet client certificate rotation fails] ( /docs/setup/production-environment/tools/kubeadm/troubleshooting-kubeadm/#kubelet-client-cert ) .
136
- {{< /note >}}
137
149
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
140
152
[ bug] ( https://github.com/kubernetes/kubeadm/issues/1753 ) where you manually have to modify the
141
153
contents of ` kubelet.conf ` . After ` kubeadm init ` finishes, you should update ` kubelet.conf ` to
142
154
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
146
158
client-certificate : /var/lib/kubelet/pki/kubelet-client-current.pem
147
159
client-key : /var/lib/kubelet/pki/kubelet-client-current.pem
148
160
` ` `
149
- {{< /warning >}}
161
+ {{< /note >}}
150
162
151
163
## Automatic certificate renewal
152
164
@@ -158,26 +170,24 @@ if you don't have specific requirements on certificate renewal and perform Kuber
158
170
upgrades regularly (less than 1 year in between each upgrade), kubeadm will take care of keeping
159
171
your cluster up to date and reasonably secure.
160
172
161
- {{< note >}}
162
- It is a best practice to upgrade your cluster frequently in order to stay secure.
163
- {{< /note >}}
164
-
165
173
If you have more complex requirements for certificate renewal, you can opt out from the default
166
174
behavior by passing ` --certificate-renewal=false` to `kubeadm upgrade apply` or to `kubeadm
167
175
upgrade node`.
168
176
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
-
175
177
# # Manual certificate renewal
176
178
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.
178
182
179
183
This command performs the renewal using CA (or front-proxy-CA) certificate and key stored in `/etc/kubernetes/pki`.
180
184
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
+
181
191
After running the command you should restart the control plane Pods. This is required since
182
192
dynamic certificate reload is currently not supported for all components and certificates.
183
193
[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.
188
198
You can then move the file back and after another `fileCheckFrequency` period, the kubelet will recreate
189
199
the Pod and the certificate renewal for the component can complete.
190
200
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 :
202
202
203
203
` ` ` 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.
204
206
kubeadm certs renew all
205
207
` ` `
206
208
207
- {{< note >}}
209
+ # ## Copying the administrator certificate (optional) {#admin-certificate-copy}
210
+
208
211
Clusters built with kubeadm often copy the `admin.conf` certificate into
209
212
` $HOME/.kube/config` , as instructed in [Creating a cluster with kubeadm](/docs/setup/production-environment/tools/kubeadm/create-cluster-kubeadm/).
210
213
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 :
212
215
213
216
` ` ` shell
214
217
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
215
218
sudo chown $(id -u):$(id -g) $HOME/.kube/config
216
219
` ` `
217
- {{< /note >}}
218
220
219
221
# # Renew certificates with the Kubernetes certificates API
220
222
@@ -430,16 +432,13 @@ as extra SANs and custom IP addresses must be stored in the same configuration
430
432
file and used for all relevant kubeadm commands by passing it as `--config`.
431
433
432
434
{{< 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).
436
439
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.
443
442
{{< /note >}}
444
443
445
444
# ## Preparing CA and service account files
@@ -460,8 +459,9 @@ private keys) that kubeadm needs for a control plane node.
460
459
461
460
{{< note >}}
462
461
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
465
465
[External CA mode](#external-ca-mode) section.
466
466
{{< /note >}}
467
467
@@ -500,9 +500,10 @@ That is because the active kube-controller-manager will be responsible
500
500
for signing new kubelet client certificates.
501
501
502
502
{{< 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.
506
507
{{< /note >}}
507
508
508
509
# ### Control plane nodes
@@ -539,8 +540,8 @@ the steps for worker nodes entirely.
539
540
540
541
{{< note >}}
541
542
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`,
544
545
` /etc/kubernetes/pki/front-proxy-ca.srl` and `/etc/kubernetes/pki/etcd/ca.srl`.
545
546
The files can be then moved to a new node where CSR files will be processed.
546
547
0 commit comments