'GCP GKE Google Kubernetes Engine The connection to the server localhost:8080 was refused

i am trying GCP and GKE google kubernetes engine. 1-)i am create a cluster 2-)i opened cloud shell and used command "kubectl get nodes"

i get this error: "The connection to the server localhost:8080 was refused - did you specify the right host or port?"

how can i solve. thanks.



Solution 1:[1]

You must have a local Kubernetes config file that is used by kubectl to access cluster(s).

Conventionally, the config file is called config (YAML) and is found in ${HOME}/.kube/config.

Google provides a way to generate a config file (and context) for you. To do this run gcloud container clusters get-credentials .... You'll need to fill in the blanks of the cluster name and probably the project, zone/region etc.:

gcloud container clusters get-credentials ${CLUSTER_NAME} \
--project=${PROJECT} \
--region=${REGION}

After running this command, you should be able to more ${HOME}/.kube/config and you should be able to access the cluster using e.g. kubectl get nodes.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 DazWilkin