kubectl worked yesterday, today it only says Unauthorized. Not a word about an expiry date – this is exactly how an expired client certificate looks, including the one in an expired admin.conf.
Symptom
kubectl --kubeconfig kurz.kubeconfig get nodes error: You must be logged in to the server (Unauthorized)
In the course the user kurz deliberately gets a certificate valid for ten minutes. After it expires, the API server only answers Unauthorized.
Diagnosis
Extract the certificate from the kubeconfig and read its expiry date.
kubectl config view --raw -o jsonpath='{.users[0].user.client-certificate-data}' \
| base64 -d | openssl x509 -noout -enddate
notAfter=Nov 21 19:03:12 2027 GMT
Causes
notAfter in the pastClient certificate expired
The API server checks the certificate during the TLS handshake. If it has expired, the client counts as not logged in – RBAC never gets a say.
kubeadm certificatesOne year of validity
kubeadm issues the certificates for the API server, etcd and admin.conf for one year. They all expire on the same evening – the time of the last kubeadm upgrade.
sudo kubeadm certs check-expiration 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
copied kubeconfig~/.kube/config is an old copy
Renewing on the node does not touch the copy in your home directory. After kubeadm certs renew you have to copy admin.conf again.
Fix
sudo kubeadm certs renew all | grep -i "super-admin\|Done" 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) ' certificate embedded in the kubeconfig file for the super-admin renewed Done renewing certificates. You must restart the kube-apiserver, ... apiserver Nov 22, 2027 09:05 UTC 364d ca no super-admin.conf Nov 22, 2027 09:05 UTC 364d ca no
Don't: Rebuild roles and role bindings on a sudden Unauthorized. Check the certificate's expiry date first – and set up an alert a few weeks before it expires.
Kubernetes Day 2, Day 10: read and renew the certificates in a cluster, and let one expire on purpose.
Go to day 10 →
FAQ
Do the kubelet certificates expire too?
Yes, but the kubelet renews its client certificate automatically. They are missing from kubeadm certs check-expiration; read them directly with openssl under /var/lib/kubelet/pki.
Do I need to restart anything after kubeadm certs renew?
Yes. kubeadm says so itself – kube-apiserver, controller-manager, scheduler and etcd must restart to load the new certificates.