Unfortunately I lost my local
~/.kube/config
where I had configuration for my namespace.
Is there a way to get this config if I have access to master nodes?
Thanks in advance
I believe you're using kubeadm to start your kubernetes cluster, you can generate the new kubeconfig file using following command:
kubeadm alpha phase kubeconfig admin --kubeconfig-dir /etc/kubernetes --cert-dir /etc/kubernetes/pki
This will generate a new config file in /etc/kubernetes/admin.conf
. Then you can copy the file in following way:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
Thanks to @PrafullLadha, there's a similar solution for OpenShift:
Install kubeadm with snap: sudo snap install kubeadm --classic
cd
to your openshift cluster installation directory.
Make a copy of your TLS certificate: cp ./tls/journal-gatewayd.crt ./tls/ca.crt
Make a copy of your TLS key: cp ./tls/journal-gatewayd.key ./tls/ca.key
Run kubeadm as follow:
kubeadm init phase kubeconfig admin --kubeconfig-dir ./auth --cert-dir "${PWD}/tls"
It should output: [kubeconfig] Writing "admin.conf" kubeconfig file
vi ./auth/admin.conf
- see that the certificates were added, and make sure the server address (https://api.your-cluster:6443
) is correct.
Rename: mv ./auth/admin.conf ./auth/kubeconfig
and you're all set.