Unable to connect to the server: x509: certificate has expired or is not yet valid
Quote from moshe on 23/10/2020, 5:14 pmProblem
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.1Note:
Replace IP address with your kubernetes master serverbackup and re-generate all kubeconfig files:
cd /etc/kubernetes/
mv {admin.conf,controller-manager.conf,kubelet.conf,scheduler.conf} ~/
kubeadm init phase kubeconfig all
rebootcopy new admin.conf to your home directory:
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
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