This article explains how to recover management cluster credentials when ~/.kube/config is deleted.
Most TKG CLI commands fail if the particular kubeconfig file does not exist or is invalid. In the event that the kubeconfig (~/.kube/config) file has been deleted or corrupted, then the following instructions will help in recovering from that problem.
1. ssh into the master VM and become root (sudo -i), then run the following command as root (replace <Management Cluster Name>) to get the secret data of the original admin's kubeconfig. Copy the output. Now log out of the master VM.
$ kubectl --kubeconfig /etc/kubernetes/admin.conf get secret <Management Cluster Name>-kubeconfig -n tkg-system -o jsonpath='{.data.value}'
2. Paste the output from the command above into a file on your computer (e.g., secret-kubeconfig-data.dat)
3. Decode the data using base64 command and save it to the default kubeconfig file.
$ cat secret-kubeconfig-data.dat | base64 -D > ~/.kube/config
4. Finally, set the TKG context using the TKG CLI.
$ tkg set management-cluster <mgmt cluster name>
To get access to the clusters back, just run the following on each cluster:
$ tkg get credentials <cluster name>