KB: Fixing Kubernetes Cluster after expired certs
Fixing Kubernetes API Server and Kubelet Issues After Expired Certificates
-
Backup Existing Kubernetes Configuration
- Create a backup of Kubernetes certificates and configuration files
- Copy
/etc/kubernetes/pki/and/etc/kubernetes/*.confto a backup directory
-
Renew Expired Certificates
- Check expired certificates using
kubeadm certs check-expiration - Renew all certificates with
kubeadm certs renew all - Restart kubelet and container runtime using
systemctl restart kubeletandsystemctl restart containerdorsystemctl restart docker
- Check expired certificates using
-
Regenerate
bootstrap-kubelet.confif Missing- Run
kubeadm init phase kubelet-startto regenerate it - If still missing, manually copy
admin.conftokubelet.conf - Restart kubelet using
systemctl restart kubelet
- Run
-
Fix Unauthorized Errors
- Ensure
kubectlis using the correct kubeconfig - Copy
/etc/kubernetes/admin.confto~/.kube/configand set proper ownership and permissions - Check kubelet logs for authentication errors with
journalctl -u kubelet --no-pager | tail -50
- Ensure
-
Use
crictlto Check and Troubleshoot Running Containers- Check running containers:
crictl ps - Check all containers including stopped ones:
crictl ps -a - View logs of a specific container:
crictl logs <container-id> - Inspect a container:
crictl inspect <container-id> - If the API server container is missing, restart kubelet and check logs
- Check running containers:
-
Rejoin the Master Node if Needed
- Create a new bootstrap token using
kubeadm token create --print-join-command - Run the generated
kubeadm joincommand to reconnect the node - Restart kubelet using
systemctl restart kubelet
- Create a new bootstrap token using
-
Final Checks
- Verify Kubernetes nodes are running using
kubectl get nodes - Check API server status with
kubectl get pods -n kube-system - Review kubelet logs with
journalctl -u kubelet --no-pager | tail -50 - Ensure all control plane components are running using
kubectl get componentstatuses
- Verify Kubernetes nodes are running using
This process ensures Kubernetes master nodes recover from expired certificates, missing kubelet configuration, and API server failures.
Comments
Post a Comment