Interview Prep/DevSecOps/Certificates, TLS and security incident response

`kubectl` against a kubeadm cluster fails with `Unable to connect to the server: x509: certificate has expired or is not yet valid`

AdvancedTroubleshootingCertificates, TLS and security incident response
Answer

Likely causes → kubeadm-issued control-plane certificates last one year. They are renewed automatically only during kubeadm upgrade, and this cluster was not upgraded for a year.

Diagnose →

sudo kubeadm certs check-expiration

Fix → On each control-plane node:

sudo kubeadm certs renew all
# restart static pods: move manifests out and back
sudo mkdir -p /tmp/m && sudo mv /etc/kubernetes/manifests/*.yaml /tmp/m/ && sleep 20 && sudo mv /tmp/m/*.yaml /etc/kubernetes/manifests/
sudo cp /etc/kubernetes/admin.conf ~/.kube/config

Check that kubelet client certificate rotation is on (rotateCertificates: true).

Prevent → Upgrade at least yearly, and alert on kubeadm certs check-expiration (or apiserver_client_certificate_expiration_seconds) at 30 days.

All DevSecOps questions

More on Certificates, TLS and security incident response