x509 Certificate Renewal
Renew x509 Certificate for Kubernetes
When your x509 certificate(s) for Kubernetes was expired, following error will be shown
$ kubectl get pods -n saas-beta
Unable to connect to the server: x509: certificate has expired or is not yet valid: current time 2023-07-14T01:22:53Z is after 2023-07-10T11:45:22ZCheck Certificates
$ sudo kubeadm certs check-expiration
[check-expiration] Reading configuration from the cluster...
[check-expiration] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -o yaml'
[check-expiration] Error reading configuration from the Cluster. Falling back to default configuration
CERTIFICATE EXPIRES RESIDUAL TIME CERTIFICATE AUTHORITY EXTERNALLY MANAGED
admin.conf Jul 10, 2023 11:45 UTC <invalid> ca no
apiserver Jul 10, 2023 11:45 UTC <invalid> ca no
apiserver-etcd-client Jul 10, 2023 11:45 UTC <invalid> etcd-ca no
apiserver-kubelet-client Jul 10, 2023 11:45 UTC <invalid> ca no
controller-manager.conf Jul 10, 2023 11:45 UTC <invalid> ca no
etcd-healthcheck-client Jul 10, 2023 11:45 UTC <invalid> etcd-ca no
etcd-peer Jul 10, 2023 11:45 UTC <invalid> etcd-ca no
etcd-server Jul 10, 2023 11:45 UTC <invalid> etcd-ca no
front-proxy-client Jul 10, 2023 11:45 UTC <invalid> front-proxy-ca no
scheduler.conf Jul 10, 2023 11:45 UTC <invalid> ca no
CERTIFICATE AUTHORITY EXPIRES RESIDUAL TIME EXTERNALLY MANAGED
ca Jul 07, 2032 11:45 UTC 8y no
etcd-ca Jul 07, 2032 11:45 UTC 8y no
front-proxy-ca Jul 07, 2032 11:45 UTC 8y noThe current date is Jul 14, 2023 which is after the expiration of cerificate. Therefore, we need to renew certificates.
Renew Certificate
According to https://kubernetes.io/docs/tasks/administer-cluster/kubeadm/kubeadm-certs/ We can use kubeadm to renew certificates with ease.
When it was renewed, check the certificates again.
It has been renewed successfully for another 364 days.
Manage ~/.kube/config
Since the certificates were changed, we need to copy /etc/kubernetes/admin.conf to ~/.kube/config again in order for us to use kubectl commands. This is due to the user not being logged in with the renewed certificates.
Then kubectl commands will work properly.
Propagate config (optional)
Since the master node only has the updated config file, we might also want to propagate the config file to all worker nodes if we want to use kubectl in worker nodes.
This will propagate kube/config to the worker node, change /home/isu and 172.20.41.152 to your username and worker nodes.
Last updated