Deleted ~/.kube/config

7/7/2021

I accidentally deleted the config file from ~/.kube/config. Every kubectl command fails due to config missing.

Example:

kubectl get nodes

The connection to the server localhost:8080 was refused - did you specify the right host or port?

I have already install k3s using:

export K3S_KUBECONFIG_MODE="644"
curl -sfL https://get.k3s.io | sh -s - --docker

and kubectl using:

snap install kubectl --classic

Does anyone know how to fix this?

-- e7lT2P
devops
k3s
kubectl
kubernetes

1 Answer

7/7/2021

The master copy is available at /etc/rancher/k3s/k3s.yaml. So, copy it back to ~/.kube/config

cp /etc/rancher/k3s/k3s.yaml ~/.kube/config

Reference: https://rancher.com/docs/k3s/latest/en/cluster-access/

-- Rakesh Gupta
Source: StackOverflow