Extend Kubernetes Certificate Expiration to 10 Years with a Simple Script
This guide shows how to check the default 1‑year and 10‑year Kubernetes certificates using OpenSSL, then extend all relevant kubeadm‑issued certificates to a ten‑year lifespan by deploying and running the update‑kubeadm‑cert.sh script on each master node, and finally verify the new validity periods.
Background
When a Kubernetes cluster is initialized with kubeadm, the default CA certificate is valid for 10 years, while the apiserver certificate is valid for only 1 year. After the apiserver certificate expires, API requests fail.
Check Current Certificate Expiration
Use OpenSSL to view the Not Before and Not After fields of the certificates:
openssl x509 -in /etc/kubernetes/pki/ca.crt -noout -text | grep Not Not Before: Apr 22 04:09:07 2020 GMT
Not After : Apr 20 04:09:07 2030 GMT openssl x509 -in /etc/kubernetes/pki/apiserver.crt -noout -text | grep Not Not Before: Apr 22 04:09:07 2020 GMT
Not After : Apr 22 04:09:07 2021 GMTExtend Certificate Validity
1. Obtain the update-kubeadm-cert.sh script from the GitHub repository:
https://github.com/luckylucky421/kubernetes1.17.3
Copy the script to each master node (e.g., master1, master2, master3).
2. On each master node, make the script executable and run it to extend all certificates to ten years:
chmod +x update-kubeadm-cert.sh ./update-kubeadm-cert.sh all3. Verify that control‑plane pods are running after renewal:
kubectl get pods -n kube-system ......
calico-node-b5ks5 1/1 Running 0 157m
calico-node-r6bfr 1/1 Running 0 155m
calico-node-r8qzv 1/1 Running 0 7h1m
coredns-66bff467f8-5vk2q 1/1 Running 0 7h30m
......Verify Extended Expiration
Re‑run the OpenSSL commands to confirm the new validity periods (now 10 years for all certificates):
openssl x509 -in /etc/kubernetes/pki/ca.crt -noout -text | grep Not Not Before: Apr 22 04:09:07 2020 GMT
Not After : Apr 20 04:09:07 2030 GMT openssl x509 -in /etc/kubernetes/pki/apiserver.crt -noout -text | grep Not Not Before: Apr 22 11:15:53 2020 GMT
Not After : Apr 20 11:15:53 2030 GMT openssl x509 -in /etc/kubernetes/pki/apiserver-etcd-client.crt -noout -text | grep Not Not Before: Apr 22 11:32:24 2020 GMT
Not After : Apr 20 11:32:24 2030 GMT openssl x509 -in /etc/kubernetes/pki/front-proxy-ca.crt -noout -text | grep Not Not Before: Apr 22 04:09:08 2020 GMT
Not After : Apr 20 04:09:08 2030 GMTAll certificates now show a ten‑year expiration window, confirming successful renewal.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Full-Stack DevOps & Kubernetes
Focused on sharing DevOps, Kubernetes, Linux, Docker, Istio, microservices, Spring Cloud, Python, Go, databases, Nginx, Tomcat, cloud computing, and related technologies.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
