Forum Navigation
You need to log in to create posts and topics.

Unable to connect to the server: x509: certificate has expired or is not yet valid

Problem

User is getting the following error when trying to execute kubectl commands: Unable to connect to the server: x509: certificate has expired or is not yet valid

Solution

Certificate has expired and needs to regenerate backup and re-generate all certs

cd /etc/kubernetes/pki/
mkdir ~/old.certs
mv {apiserver.crt,apiserver-etcd-client.key,apiserver-kubelet-client.crt,front-proxy-ca.crt,front-proxy-client.crt,front-proxy-client.key,front-proxy-ca.key,apiserver-kubelet-client.key,apiserver.key,apiserver-etcd-client.crt} ~/old.certs
kubeadm init phase certs all –apiserver-advertise-address 192.168.1.1

Note:
Replace IP address with your kubernetes master server

backup and re-generate all kubeconfig files:

cd /etc/kubernetes/
mv {admin.conf,controller-manager.conf,kubelet.conf,scheduler.conf} ~/
kubeadm init phase kubeconfig all
reboot

copy new admin.conf to your home directory:

cp -i /etc/kubernetes/admin.conf $HOME/.kube/config