Search code examples
kuberneteskubectl

Why does kubectl have different behavior with sudo?


Running kubectl get pods with sudo:

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

Running as a normal user:

kubectl get pods
No resources found.

Solution

  • By default, kubectl looks in ~/.kube/config (or the file pointed to be $KUBECONFIG) to determine what server to connect to. Your home directory and environment are different when running commands as root. When no connection info is found, kubectl defaults to localhost:8080