Reputation: 33881
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.
Upvotes: 2
Views: 2901
Reputation: 96
sudo kubectl
, kubectl will refer to /root/.kube/config .kubectl
without sudo, kubectl will refer to $HOME/.kube/config .<user home dir>/.kube/config
file is not found by the kubectl, it will just call the default kubernetes API server URL localhost:8080 .Upvotes: 0
Reputation: 388
You would have run these commands from the normal user :
sudo cp /etc/kubernetes/admin.conf $HOME/
sudo chown $(id -u):$(id -g) $HOME/admin.conf
export KUBECONFIG=$HOME/admin.conf
which would have copied config file in your normal user home directory and that is why you are able to get to the connection from the normal host and not from sudo.
Upvotes: -1
Reputation: 18111
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
Upvotes: 7