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

I have followed the helloword tutorial on http://kubernetes.io/docs/hellonode/.

When I run:

kubectl run hello-node --image=gcr.io/PROJECT_ID/hello-node:v1 --port=8080

I get:

The connection to the server localhost:8080 was refused - did you specify the right host or port?

Why does the command line try to connect to the localhost?


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  STATUS
alpha-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.