did you specify the right host or port? error on Kubernetes did you specify the right host or port? error on Kubernetes kubernetes kubernetes

did you specify the right host or port? error on Kubernetes


The issue is that your kubeconfig is not right.To auto-generate it run:

gcloud container clusters get-credentials "CLUSTER NAME"

This worked for me.


Make sure your config is set to the project -

gcloud config set project [PROJECT_ID]
  1. Run a checklist of the Clusters in the account:
gcloud container clusters list
  1. Check the output :
NAME           LOCATION       MASTER_VERSION  MASTER_IP      MACHINE_TYPE  NODE_VE.      NUM_NODES  STATUSalpha-cluster  asia-south1-a  1.9.7-gke.6     35.200.254.78  f1-micro      1.9.7-gke.6   3          RUNNING
  1. Run the following cmd to fetch credentials for your running cluster:
gcloud container clusters get-credentials your-cluster-name --zone your-zone       --project your-project
  1. The following output follows:
Fetching cluster endpoint and auth data.kubeconfig entry generated for alpha-cluster.
  1. Try checking details of the node running kubectl such as below to list all pods in the current namespace, with more details:
kubectl get nodes -o wide

Should be good to go.


After running "kubeinit" command, kubernetes asks you to run following as regular user

mkdir -p $HOME/.kube

sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config

sudo chown $(id -u):$(id -g) $HOME/.kube/config

But if you run this as a regular user, you will get "The connection to the server localhost:8080 was refused - did you specify the right host or port?" when trying to access as a root user and vice versa. So try accessing "kubectl" as the user who executed the above commands.