Connection refused error on worker node in kubernetes Connection refused error on worker node in kubernetes kubernetes kubernetes

Connection refused error on worker node in kubernetes


root@kubework:/etc/kubernetes# kubectl get nodes The connection to theserver localhost:8080 was refused - did you specify the right host orport?

Kubcetl is by default configured and working on the master. It requires a kube-apiserver pod and ~/.kube/config.

For worker nodes, we don’t need to use kube-apiserver but what we want is using the master configuration to pass by it.To achieve it we have to copy the ~/.kube/config file from the master to the ~/.kube/config on the worker. Value ~ with the user executing kubcetl on the worker and master (that may be different of course).
Once that done you could use the kubectl command from the worker node exactly as you do that from the master node.


Yes these files needed. Move these files into respective .kube/config folder on worker nodes.


This is expected behavior even using kubectl on master node as non root account, by default this config file is stored for root account in /etc/kubernetes/admin.conf:

To make kubectl work for your non-root user, run these commands, which are also part of the kubeadm init output:

mkdir -p $HOME/.kubesudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/configsudo chown $(id -u):$(id -g) $HOME/.kube/config
  • Alternatively on the master, if you are the root user, you can run:
    export KUBECONFIG=/etc/kubernetes/admin.conf

Optionally Controlling your cluster from machines other than the control-plane node

scp root@<control-plane-host>:/etc/kubernetes/admin.conf .kubectl --kubeconfig ./admin.conf get nodes

Note:

The KUBECONFIG environment variable holds a list of kubeconfig files. For Linux and Mac, the list is colon-delimited. For Windows, the list is semicolon-delimited. The KUBECONFIG environment variable is not required. If the KUBECONFIG environment variable doesn't exist, kubectl uses the default kubeconfig file, $HOME/.kube/config.