A cluster has two kinds of certificates: the TLS Secrets your Ingresses serve, and the control plane's own certificates. Both expire, and kubectl shows neither date by default.
Every TLS Secret in the cluster
kubectl get secrets -A --field-selector type=kubernetes.io/tls \
-o jsonpath='{range .items[*]}{.metadata.namespace}{" "}{.metadata.name}{" "}{.data.tls\.crt}{"\n"}{end}' |
while read -r ns name crt; do
end=$(echo "$crt" | base64 -d | openssl x509 -noout -enddate | cut -d= -f2)
echo "$ns/$name $end"
done
This prints the end date of the first certificate in each Secret, which is the server's own.
One Secret
kubectl get secret example-com-tls -n web -o jsonpath='{.data.tls\.crt}' \
| base64 -d | openssl x509 -noout -subject -enddate
With cert-manager
cert-manager keeps the dates on the Certificate resource:
kubectl get certificate -A \
-o custom-columns=NAMESPACE:.metadata.namespace,NAME:.metadata.name,EXPIRES:.status.notAfter,RENEWAL:.status.renewalTime
A RENEWAL time in the past means it's stuck. cert-manager
certificate not renewing shows how to find out why.
The control plane (kubeadm)
kubeadm issues the API server, etcd and controller certificates for one year:
sudo kubeadm certs check-expiration
They're renewed on each kubeadm upgrade. A cluster that wasn't upgraded for a year stops working when they expire.
To renew by hand:
sudo kubeadm certs renew all
Then restart the API server, controller manager, scheduler and etcd so they load the new files, and copy the new
/etc/kubernetes/admin.conf to wherever your kubeconfig lives. Managed clusters (EKS, GKE, AKS) handle this part.
Check from outside
A Secret can be fine while the Ingress serves something else, for example the controller's fake certificate. Check what clients get:
echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null \
| openssl x509 -noout -subject -enddate
For alerts inside the cluster, see certificate expiry alerts with Prometheus.