Skip to content

Instantly share code, notes, and snippets.

@xhoong
Created May 20, 2023 09:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xhoong/e6255e687f3ea54b240da296b019cb31 to your computer and use it in GitHub Desktop.
Save xhoong/e6255e687f3ea54b240da296b019cb31 to your computer and use it in GitHub Desktop.
#### Reference: https://raynix.info/archives/4296
# in the master node, run as root
kubeadm certs renew all
[renew] Reading configuration from the cluster...
[renew] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -o yaml'
[renew] Error reading configuration from the Cluster. Falling back to default configuration
certificate embedded in the kubeconfig file for the admin to use and for kubeadm itself renewed
...
Done renewing certificates. You must restart the kube-apiserver, kube-controller-manager, kube-scheduler and etcd, so that they can use the new certificates.
# it's easier to restart the kubelet service which runs those static pods
systemctl restart kubelet.service
...
# copy the updated kubeconfig from the master node
ssh ubuntu@kmaster -- sudo cat /etc/kubernetes/admin.conf > /tmp/admin.conf
# delete current cluster, user, context from local kubeconfig
# by default, the kubeadm cluster is named kubernetes
k config delete-context kubernetes
k config delete-cluster kubernetes
k config delete-user kubernetes-admin
# merge the new admin.conf with current kubeconfig
KUBECONFIG=~/.kube/config:/tmp/admin.conf k config view --flatten > /tmp/config
# test the new kubeconfig
k --kubeconfig=/tmp/config get nodes
NAME STATUS ROLES AGE VERSION
kmaster1 Ready control-plane,master 376d v1.21.0
...
# replace the current kubeconfig
mv /tmp/config ~/.kube/config
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment