Kubernetes 101 : Troubleshooting "The connection to the server api_server_ip:8080 was refused"
Sometimes when trying to run "kubectl" command, we receive the below error message:
The connection to the server api_server_ip:8080 was refused - did you specify the right host or port?
We try to read the configuration using the below command that displays the cluster settings:
The above command shows empty settings, and on closer inspection we notice that the "~/.kube/config" file is missing.
This file contains different parameters for accessing the kubernetes cluster.
The "~" sign referes to the home directory.
If we use the "kubectl" command while explicitly mentioning the path to the configuration file, we don't get an error anymore:
Another option is to set the KUBECONFIG environment variable with the path of the config file and to use the normal command "kubectl get nodes" without any added arguments.
A better alternative would be to copy the "admin.conf" file to the "~/.kube/config" file and give it the ownership or the user we are connected as so we could use it:
On worker nodes, we might have to copy "/etc/kubernetes/kubelet.conf" to the "~/.kube/config" file.