简体   繁体   中英

Can't connect to K8S cluster from kubectl

I am running kubectl from Mac OS M1 laptop. There is a K8S cluster deployed to gcp and I have logged in from cli gcloud auth login . Then I run below command to authenticate GKS credential

> gcloud container clusters get-credentials gcp-test --zone australia-southeast2-a
Fetching cluster endpoint and auth data.
kubeconfig entry generated for gcp-test.

it looks ok but I got below error when run get pods

> kubectl get pods
Unable to connect to the server: EOF

The version of kubectl I am using is

> kubectl version
Client Version: version.Info{Major:"1", Minor:"23+", GitVersion:"v1.23.13-eks-fb459a0", GitCommit:"55bd5d5cb7d32bc35e4e050f536181196fb8c6f7", GitTreeState:"clean", BuildDate:"2022-10-24T20:38:50Z", GoVersion:"go1.17.13", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"23+", GitVersion:"v1.23.13-eks-fb459a0", GitCommit:"55bd5d5cb7d32bc35e4e050f536181196fb8c6f7", GitTreeState:"clean", BuildDate:"2022-10-24T20:35:40Z", GoVersion:"go1.17.13", Compiler:"gc", Platform:"linux/amd64"}

The K8S cluster version in GCP is 1.24.5-gke.600 . Does anyone know why I get Unable to connect to the server: EOF error? It seems like not able to connect to the server.

It looks like you have already a config for an EKS cluster. Maybe gcloud added a new context to your kubeconfig file, but the old one is still the active one.

Use

kubectl config get-contexts

to check if there are multiple contexts.

Use

kubectl config use-context <context-name>

to set the active context.

You could also examine your kubeconfig file. The default location is

~/.kube/config

but can be overridden by KUBECONFIG environment variable. To find that out, execute

echo $KUBECONFIG

Could also be that gcloud added the context to the default kubeconfig file but you have a different on set with the KUBECONFIG env variable that contains the EKS context.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM