Search code examples
kubernetesdevopskubectlk3s

Deleted ~/.kube/config


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?


Solution

  • 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/