kubernetes – kubectl get node is returning connection refused
As per this doc
kubectl get nodes The connection to the server localhost:8080 was refused – did you specify the right host or port?
When you run the kubectl or a similar command, this is a common problem. Kubernetes lacks the proper credentials to access the cluster most of the time.
Resolution steps
1.Check if the kubeconfig environment variable is exported if not exported
export KUBECONFIG=/etc/kubernetes/admin.conf or $HOME/.kube/config
2.Check the home directory file or your.kube configuration. You need to move that to the home directory if you didn’t find it. using the command that follows
cp /etc/kubernetes/admin.conf $HOME/
chown $(id -u):$(id -g) $HOME/admin.conf
export KUBECONFIG=$HOME/admin.conf
Whenever you are starting Master Node you may require to set the environment variable. Hence it’s a repetitive task for you. It can be set permanently using the following command.
echo 'export KUBECONFIG=$HOME/admin.conf' >> $HOME/.bashrc
A Kubernetes form discussion thread can also be found here.
Read more here: Source link
