Day 10: Certificates, before they expire
Goal: Find all certificates of the cluster, give the kubelets real serving certificates, get rid of
--kubelet-insecure-tls, and renew the control plane by hand without an outage · Duration: approx. 75 min · Prerequisite: Day 9
Briefing
- kubeadm issues the control plane certificates for one
year, and the three certificate authorities (CAs) for ten
years. Every
kubeadm upgraderenews the certificates along the way. If you upgrade at least once a year, you never notice. If you skip upgrades for a year, one morning you have a cluster that no longer lets anyone in. - The kubelets have two certificates: a client
certificate (the kubelet authenticates to the API server) and a
serving certificate (the API server and metrics-server
call the kubelet on port 10250). The kubelet renews the client
certificate itself. With kubeadm, the serving certificate is
self-signed by default. That is why metrics-server has
needed
--kubelet-insecure-tlssince Day 0. - Today you clean up both: real serving certificates through the CSR API, then a manual renewal, node by node, under load.
| Certificate | Issuer | Renewed by |
|---|---|---|
| API server, etcd, front proxy, kubeconfigs | kubeadm | kubeadm upgrade or
kubeadm certs renew |
| kubelet client | cluster CA via CSR | the kubelet itself (rotateCertificates) |
| kubelet serving | self-signed → cluster CA from today | kubelet via CSR, approval required |
| CAs | kubeadm | nobody automatically (10 years) |
Drill 1: Inventory of expiry dates
mkdir -p ~/day2/tag10 && cd ~/day2/tag10
sudo kubeadm certs check-expirationExpected (abridged):
CERTIFICATE EXPIRES RESIDUAL TIME CERTIFICATE AUTHORITY
admin.conf Nov 21, 2027 21:42 UTC 364d ca
apiserver Nov 21, 2027 21:42 UTC 364d ca
apiserver-etcd-client Nov 21, 2027 21:42 UTC 364d etcd-ca
...
super-admin.conf Nov 21, 2027 21:42 UTC 364d ca
CERTIFICATE AUTHORITY EXPIRES RESIDUAL TIME EXTERNALLY MANAGED
ca Nov 18, 2036 19:03 UTC 9y no
etcd-ca Nov 18, 2036 19:03 UTC 9y no
front-proxy-ca Nov 18, 2036 19:03 UTC 9y no
All certificates expire on the same evening: the time of the last
kubeadm upgrade apply on Day 9. The kubelet certificates
are missing from this list. You only see them directly:
sudo openssl x509 -in /var/lib/kubelet/pki/kubelet-client-current.pem -noout \
-subject -issuer -enddate
sudo openssl x509 -in /var/lib/kubelet/pki/kubelet.crt -noout -subject -issuer -enddateExpected:
subject=O = system:nodes, CN = system:node:cp1
issuer=CN = kubernetes
notAfter=Nov 21 19:03:12 2027 GMT
subject=CN = cp1@1795287825
issuer=CN = cp1-ca@1795287825
notAfter=Nov 21 18:03:44 2027 GMT
The client certificate comes from the cluster CA
(kubernetes). The kubelet issued the serving certificate to
itself, from its own mini CA cp1-ca that nobody except cp1
knows. kubelet-client-current.pem is a symlink. On renewal,
the kubelet creates a new file and repoints the link:
sudo ls -l /var/lib/kubelet/pki/ | cut -c1-100
sudo grep -n client-certificate /etc/kubernetes/kubelet.confExpected:
-rw------- 1 root root 2818 Nov 21 19:03 kubelet-client-2026-11-21-19-03-45.pem
lrwxrwxrwx 1 root root 59 Nov 21 19:03 kubelet-client-current.pem -> /var/lib/kubelet/pki/
-rw-r--r-- 1 root root 2233 Nov 21 19:03 kubelet.crt
-rw------- 1 root root 1675 Nov 21 19:03 kubelet.key
17: client-certificate: /var/lib/kubelet/pki/kubelet-client-current.pem
Save your progress? Sign up for free
Drill 2: Why metrics-server does not trust
A call to the kubelet on cp2, verified against the cluster CA:
curl -sS --cacert /etc/kubernetes/pki/ca.crt https://172.16.0.228:10250/healthz
echo | openssl s_client -connect 172.16.0.228:10250 2>/dev/null \
| openssl x509 -noout -subject -issuerExpected:
curl: (60) SSL certificate problem: self-signed certificate in certificate chain
...
subject=CN = cp2@1795287932
issuer=CN = cp2-ca@1795287932
This is exactly what metrics-server sees on every scrape. The
convenient solution from Day 0 was --kubelet-insecure-tls:
metrics-server no longer checks the certificate at all. That means
anyone who gets between metrics-server and the kubelet can pretend to be
the kubelet. The right solution is a serving certificate from the
cluster CA.
Save your progress? Sign up for free
Drill 3: Turn on serverTLSBootstrap
kubeadm manages the kubelet configuration in the
kubelet-config ConfigMap. The setting goes there, so that
future nodes and upgrades pick it up as well:
kubectl -n kube-system get cm kubelet-config -o yaml > kubelet-config.yaml
sed -i "s/^ rotateCertificates: true$/&\n serverTLSBootstrap: true/" kubelet-config.yaml
grep -n -A1 rotateCertificates kubelet-config.yaml
kubectl replace -f kubelet-config.yamlExpected:
44: rotateCertificates: true
45- serverTLSBootstrap: true
configmap/kubelet-config replaced
replace instead of apply: kubeadm created
the ConfigMap, not kubectl apply. apply works
too, but complains about the missing
last-applied-configuration annotation.
The load generator runs against shop again:
kubectl -n demo delete pod last
sed "s#http://web.demo#http://shop.demo#" ~/day2/tag00/last.yaml | kubectl apply -f -
kubectl -n demo wait --for=condition=Ready pod/lastNow cp1 fetches the new configuration from the ConfigMap and restarts the kubelet:
Warning: The kubelet restarts. Running Pods stay, but for a few seconds the node reports no status. Only one node at a time.
sudo kubeadm upgrade node phase kubelet-config
sudo grep -n serverTLS /var/lib/kubelet/config.yaml
sudo systemctl restart kubelet
sleep 15
kubectl get csrExpected (abridged):
[upgrade] Backing up kubelet config file to /etc/kubernetes/tmp/kubeadm-kubelet-config-
2026-11-22-08-58-22/config.yaml
[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[upgrade/kubelet-config] The kubelet configuration for this node was successfully upgraded!
44:serverTLSBootstrap: true
NAME AGE SIGNERNAME REQUESTOR REQUESTEDDURATION CONDITION
csr-dbdv8 15s kubernetes.io/kubelet-serving system:node:cp1 <none> Pending
The kubelet has submitted a certificate signing request (CSR), and it stays pending. The controller manager approves kubelet client certificates automatically, but serving certificates not: a serving certificate vouches for names and IP addresses, and no controller can check whether a node really owns these addresses. That is your job.
Save your progress? Sign up for free
Drill 4: Check and approve the request
Look inside before you sign:
C=$(kubectl get csr -o name | head -1)
kubectl get $C -o jsonpath='{.spec.request}' | base64 -d \
| openssl req -noout -subject -text | grep -E 'subject=|DNS:'
kubectl get $C -o jsonpath='{.spec.usages}{"\n"}'Expected:
DNS:cp1, IP Address:172.16.0.126
subject=O = system:nodes, CN = system:node:cp1
["digital signature","server auth"]
Name cp1, address 172.16.0.126, requested
by system:node:cp1 and only for server auth.
Everything fits together. If a node requested names or addresses that
are not its own, you would deny it
(kubectl certificate deny).
kubectl certificate approve ${C#*/}
sleep 5
kubectl get csr
sudo ls /var/lib/kubelet/pki/Expected:
certificatesigningrequest.certificates.k8s.io/csr-dbdv8 approved
NAME AGE SIGNERNAME REQUESTOR REQUESTEDDURATION CONDITION
csr-dbdv8 31s kubernetes.io/kubelet-serving system:node:cp1 <none> Approved,Issued
kubelet-client-2026-11-21-19-03-45.pem
kubelet-client-current.pem
kubelet-server-2026-11-22-08-58-48.pem
kubelet-server-current.pem
kubelet.crt
kubelet.key
The kubelet has picked up the certificate and uses it immediately, without a restart:
curl -sS --cacert /etc/kubernetes/pki/ca.crt https://172.16.0.126:10250/healthz; echo
echo | openssl s_client -connect 172.16.0.126:10250 2>/dev/null \
| openssl x509 -noout -issuer -enddate -ext subjectAltNameExpected:
Unauthorized
issuer=CN = kubernetes
notAfter=Nov 22 08:53:48 2027 GMT
X509v3 Subject Alternative Name:
DNS:cp1, IP Address:172.16.0.126
Unauthorized is the good news here: the TLS connection
is established, and curl trusts the certificate. curl is just not
allowed to log in. The same on cp2 and cp3:
# on cp2, then on cp3
sudo kubeadm upgrade node phase kubelet-config | tail -1
sudo systemctl restart kubeletkubectl get csr --field-selector spec.signerName=kubernetes.io/kubelet-servingExpected:
NAME AGE SIGNERNAME REQUESTOR REQUESTEDDURATION CONDITION
csr-dbdv8 71s kubernetes.io/kubelet-serving system:node:cp1 <none> Approved,Issued
csr-m48tl 15s kubernetes.io/kubelet-serving system:node:cp3 <none> Pending
csr-wg684 25s kubernetes.io/kubelet-serving system:node:cp2 <none> Pending
Check as above, then approve:
for c in csr-m48tl csr-wg684; do kubectl get csr $c -o jsonpath='{.spec.request}' \
| base64 -d | openssl req -noout -text | grep DNS:; done
kubectl certificate approve csr-m48tl csr-wg684
for ip in 172.16.0.228 172.16.0.83; do
curl -sS --cacert /etc/kubernetes/pki/ca.crt https://$ip:10250/healthz; echo " $ip"
doneExpected:
DNS:cp3, IP Address:172.16.0.83
DNS:cp2, IP Address:172.16.0.228
certificatesigningrequest.certificates.k8s.io/csr-m48tl approved
certificatesigningrequest.certificates.k8s.io/csr-wg684 approved
Unauthorized 172.16.0.228
Unauthorized 172.16.0.83
The CSR names are random. Use your own.
Save your progress? Sign up for free
Drill 5: metrics-server without an exception
kubectl -n kube-system get deploy metrics-server -o json \
| jq -r '.spec.template.spec.containers[0].args | index("--kubelet-insecure-tls")'Expected:
5
The argument is at position 5 (counting from 0). A JSON patch removes exactly that position:
kubectl -n kube-system patch deploy metrics-server --type=json \
-p='[{"op":"remove","path":"/spec/template/spec/containers/0/args/5"}]'
kubectl -n kube-system rollout status deploy/metrics-server --timeout=120s
sleep 20
kubectl top nodes
kubectl -n kube-system logs deploy/metrics-server --since=60s | grep -ci x509Expected:
deployment.apps/metrics-server patched
...
deployment "metrics-server" successfully rolled out
NAME CPU(cores) CPU(%) MEMORY(bytes) MEMORY(%)
cp1 1109m 27% 1254Mi 10%
cp2 541m 27% 1904Mi 49%
cp3 461m 23% 1783Mi 46%
0
No x509 errors. metrics-server now verifies the kubelets against the
cluster CA, which it knows from its ServiceAccount. And
shop noticed nothing of the three kubelet restarts:
kubectl -n demo logs last | wc -l
kubectl -n demo logs last | awk '$2 != 200' | wc -lExpected:
594
0
One catch remains: the serving certificate expires in one year. Then every kubelet submits a new request, and it waits for you again. See the Enterprise Note.
Save your progress? Sign up for free
Drill 6: Renew the control plane by hand
Suppose the next upgrade is delayed. Then you renew the certificates yourself. The API probe on cp3 runs again, as on Day 6:
# on cp3
mkdir -p ~/day2/tag10
nohup sh -c 'while true; do echo "$(date +%T) $(curl -sk -m 2 -o /dev/null \
-w %{http_code} https://172.16.0.100:6443/readyz)"; sleep 1; done' \
> ~/day2/tag10/api.log 2>&1 &You start with cp2, because cp2 does not hold the virtual address:
kubectl -n kube-system get lease plndr-cp-lock -o jsonpath='{.spec.holderIdentity}{"\n"}'Expected:
cp1
Warning: New certificates are only fully used after a restart of the API server, etcd, controller manager and scheduler. One node at a time, otherwise etcd loses quorum.
# on cp2
sudo kubeadm certs renew allExpected (abridged):
certificate embedded in the kubeconfig file for the admin to use and for kubeadm itself renewed
certificate for serving the Kubernetes API renewed
...
certificate embedded in the kubeconfig file for the scheduler manager to use renewed
MISSING! certificate embedded in the kubeconfig file for the super-admin
Done renewing certificates. You must restart the kube-apiserver, kube-controller-manager,
kube-scheduler and etcd, so that they can use the new certificates.
MISSING! is harmless: super-admin.conf only
exists on the node where kubeadm init ran, that is, on
cp1.
Now a surprise. Which certificate do the API server and etcd on cp2 serve before the restart?
# on cp2
for p in 6443 2379; do echo | openssl s_client -connect 172.16.0.228:$p 2>/dev/null \
| openssl x509 -noout -startdate; done
sudo crictl ps --name 'kube-apiserver|etcd' -o table | cut -c1-90Expected:
notBefore=Nov 22 08:56:38 2026 GMT
notBefore=Nov 22 08:56:38 2026 GMT
CONTAINER IMAGE CREATED STATE NAME
1bfba013ba507 7a918dfe48696 8 hours ago Running kube-apiserver
6780db3826e6a 270fbeb697171 8 hours ago Running etcd
Already the new one (issued at 09:01; kubeadm backdates by five minutes), even though the containers have been running for eight hours. The API server and etcd reload their serving certificate when it changes. But not the client certificates: the certificate the API server uses to authenticate to etcd, or that the controller manager and scheduler use to authenticate to the API server, has been held in memory since startup. So restart anyway:
# on cp2
sudo crictl stop $(sudo crictl ps -q \
--name 'kube-apiserver|etcd|kube-controller-manager|kube-scheduler')
sleep 60
sudo crictl ps --name 'kube-apiserver|etcd|kube-controller|kube-scheduler' -o table \
| cut -c1-90
curl -sk https://172.16.0.228:6443/readyz; echoExpected:
CONTAINER IMAGE CREATED STATE NAME
aecc697ced99a 270fbeb697171 59 seconds ago Running etcd
3830db17e2945 2db038c9db509 59 seconds ago Running kube-controller-manager
7333548196e5f 7a918dfe48696 About a minute ago Running kube-apiserver
3c4b682048529 20824b0c11f7d About a minute ago Running kube-scheduler
ok
The kubelet restarts stopped static Pods immediately, with the new files. Is etcd complete again?
kubectl -n kube-system exec etcd-cp1 -- etcdctl \
--endpoints=https://172.16.0.126:2379,https://172.16.0.228:2379,https://172.16.0.83:2379 \
--cacert /etc/kubernetes/pki/etcd/ca.crt \
--cert /etc/kubernetes/pki/etcd/healthcheck-client.crt \
--key /etc/kubernetes/pki/etcd/healthcheck-client.key endpoint healthExpected:
https://172.16.0.126:2379 is healthy: successfully committed proposal: took = 35.087941ms
https://172.16.0.83:2379 is healthy: successfully committed proposal: took = 40.77426ms
https://172.16.0.228:2379 is healthy: successfully committed proposal: took = 86.431929ms
Save your progress? Sign up for free
Drill 7: A certificate expires
What does an expired certificate look like? You do not have to wait a year to find out. The CSR API also issues certificates for users, with a lifetime of your choice. The minimum is ten minutes:
openssl genrsa -out kurz.key 2048 2>/dev/null
openssl req -new -key kurz.key -subj "/CN=kurz" -out kurz.csr
cat <<EOF | kubectl apply -f -
apiVersion: certificates.k8s.io/v1
kind: CertificateSigningRequest
metadata:
name: kurz
spec:
request: $(base64 -w0 kurz.csr)
signerName: kubernetes.io/kube-apiserver-client
expirationSeconds: 600
usages: [client auth]
EOF
kubectl certificate approve kurz
kubectl get csr kurz -o jsonpath='{.status.certificate}' | base64 -d > kurz.crt
openssl x509 -in kurz.crt -noout -subject -startdate -enddateExpected:
certificatesigningrequest.certificates.k8s.io/kurz created
certificatesigningrequest.certificates.k8s.io/kurz approved
subject=CN = kurz
notBefore=Nov 22 08:58:31 2026 GMT
notAfter=Nov 22 09:13:31 2026 GMT
Ten minutes of lifetime, backdated by five minutes against clock skew. From this, a kubeconfig of its own:
kubectl config view --raw --minify > kurz.kubeconfig
kubectl --kubeconfig kurz.kubeconfig config set-credentials kurz \
--client-certificate kurz.crt --client-key kurz.key --embed-certs
kubectl --kubeconfig kurz.kubeconfig config set-context --current --user kurz
kubectl --kubeconfig kurz.kubeconfig auth whoamiExpected (abridged):
User "kurz" set.
Context "kubernetes-admin@kubernetes" modified.
ATTRIBUTE VALUE
Username kurz
Groups [system:authenticated]
After expiry (here after 09:13:31 UTC), the same call:
kubectl --kubeconfig kurz.kubeconfig get nodesExpected:
error: You must be logged in to the server (Unauthorized)
No hint of an expiry date, only Unauthorized. A cluster
whose admin.conf has expired reports exactly the same way.
If you do not know that, you look at RBAC first. Remember: on a sudden
Unauthorized, check the certificate’s expiry date
first.
Speaking of admin.conf: your ~/.kube/config
is a copy from Day 0. The renewal did not touch it:
kubectl config view --raw -o jsonpath='{.users[0].user.client-certificate-data}' \
| base64 -d | openssl x509 -noout -enddateExpected:
notAfter=Nov 21 19:03:12 2027 GMT
After the renewal on cp1 (Challenge), you copy it again.
Save your progress? Sign up for free
Exercise: Speed Drills
- Show the issuer and expiry date of the kubelet serving certificate of cp3 without logging in to cp3. Target time: 1 min
- Show all CSRs waiting for approval. Target time: 1 min
- Show the residual time of the API server certificate on cp1. Target time: 1 min
Solution
echo | openssl s_client -connect 172.16.0.83:10250 2>/dev/null \
| openssl x509 -noout -issuer -enddate
kubectl get csr | grep Pending
sudo kubeadm certs check-expiration 2>/dev/null | grep '^apiserver 'If no requests are waiting, the second command prints nothing.
Save your progress? Sign up for free
Checkpoint
kubectl -n kube-system get cm kubelet-config -o jsonpath='{.data.kubelet}' \
| grep serverTLSExpected: serverTLSBootstrap: true
for ip in 172.16.0.126 172.16.0.228 172.16.0.83; do
curl -sS --cacert /etc/kubernetes/pki/ca.crt https://$ip:10250/healthz; echo " $ip"
doneExpected: Unauthorized three times, no
certificate errors.
kubectl -n kube-system get deploy metrics-server \
-o jsonpath='{.spec.template.spec.containers[0].args}' | grep -c insecure
kubectl top nodes | head -2Expected: 0 and values for the
nodes.
Challenge
Renew the certificates on cp3 and cp1 as well, under load and with the API probe running. cp1 holds the virtual address. Remember Day 6.
Hint: Hand over the address in an orderly way before the API server on cp1 restarts.
Solution
# on cp3
sudo kubeadm certs renew all | tail -1
sudo crictl stop $(sudo crictl ps -q \
--name 'kube-apiserver|etcd|kube-controller-manager|kube-scheduler')
sleep 60
curl -sk https://172.16.0.83:6443/readyz; echoOn cp1, first hand over the virtual address, then renew, then take it back:
sudo mv /etc/kubernetes/manifests/kube-vip.yaml /etc/kubernetes/kube-vip.yaml.pausiert
sleep 30
kubectl -n kube-system get lease plndr-cp-lock -o jsonpath='{.spec.holderIdentity}{"\n"}'
sudo kubeadm certs renew all | grep -i "super-admin\|Done"
sudo crictl stop $(sudo crictl ps -q \
--name 'kube-apiserver|etcd|kube-controller-manager|kube-scheduler')
sleep 60
curl -sk https://172.16.0.126:6443/readyz; echo
sudo mv /etc/kubernetes/kube-vip.yaml.pausiert /etc/kubernetes/manifests/kube-vip.yaml
sudo cp /etc/kubernetes/admin.conf ~/.kube/config
sudo chown $(id -u):$(id -g) ~/.kube/config
sudo kubeadm certs check-expiration 2>/dev/null | grep -E '^(apiserver|super-admin.conf) 'Expected (abridged):
Done renewing certificates. You must restart the kube-apiserver, ...
ok
cp2
certificate embedded in the kubeconfig file for the super-admin renewed
Done renewing certificates. You must restart the kube-apiserver, ...
ok
apiserver Nov 22, 2027 09:05 UTC 364d ca no
super-admin.conf Nov 22, 2027 09:05 UTC 364d ca no
The results:
# on cp3
pkill -f readyz
wc -l < ~/day2/tag10/api.log
awk '$2 != 200' ~/day2/tag10/api.logkubectl -n demo logs last | wc -l
kubectl -n demo logs last | awk '$2 != 200' | wc -lExpected:
1271
09:04:54 000
6659
0
0 errors in 6,659 requests to shop,
across three kubelet restarts and three control plane restarts. In 1,271
seconds, the API was unreachable exactly once: in the second when the
virtual address moved from cp1 to cp2. The orderly handover is not
interruption-free, but it is short. The restart of the control plane
itself was not visible on any node.
Save your progress? Sign up for free
Cleanup
kubectl delete csr kurz
rm -f ~/day2/tag10/kurz.*The controller manager deletes approved CSRs by itself after one hour anyway. The certificates are not affected by that.
Interview Note
- What happens when the certificates of a kubeadm cluster
expire? The components can no longer authenticate to each
other. kubectl reports
Unauthorized, and the controller manager and scheduler lose the API server. Running Pods keep running, but nothing new happens. The rescue:kubeadm certs renew allon every control plane node, then restart the static Pods. - Why does metrics-server often need
--kubelet-insecure-tls? Because kubeadm lets the kubelets self-sign their serving certificates. WithserverTLSBootstrap: true, the kubelets get certificates from the cluster CA, and the exception is no longer needed. - Why are kubelet serving CSRs not approved automatically? Because they vouch for names and IP addresses that no controller can verify. Otherwise a malicious node could get certificates for addresses that are not its own.
- Who renews the CAs? Nobody, automatically. After ten years, that is a project of its own, involving all nodes and all kubeconfigs.
Enterprise Note
- In production, the yearly approval of kubelet serving CSRs is handled by an approver with fixed rules (for example the kubelet-csr-approver project): it only approves if the name and IP address match the Node object.
- Expiry dates belong in monitoring, not in the calendar. A typical
setup is an alert 30 days before expiry, fed from
kubeadm certs check-expiration -o jsonor an exporter that reads certificate files. - Copies of
admin.confon workstations are a risk: they are valid for a year and cannot be revoked individually. People are better off logging in through OIDC. Certificates remain for machines and for emergencies.