[英]Can't connect to K8S cluster from kubectl
I am running kubectl
from Mac OS M1 laptop.我在 Mac OS M1 笔记本电脑上运行
kubectl
。 There is a K8S cluster deployed to gcp and I have logged in from cli gcloud auth login
.有一个部署到 gcp 的 K8S 集群,我已经从 cli
gcloud auth login
。 Then I run below command to authenticate GKS credential然后我运行下面的命令来验证 GKS 凭证
> 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
看起来不错,但运行
get pods
时出现以下错误
> kubectl get pods
Unable to connect to the server: EOF
The version of kubectl
I am using is我使用的
kubectl
版本是
> 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
. GCP 中的 K8S 集群版本为
1.24.5-gke.600
。 Does anyone know why I get Unable to connect to the server: EOF
error?有谁知道为什么我得到
Unable to connect to the server: EOF
错误? It seems like not able to connect to the server.好像无法连接到服务器。
It looks like you have already a config for an EKS cluster.您似乎已经有了 EKS 集群的配置。 Maybe gcloud added a new context to your kubeconfig file, but the old one is still the active one.
也许 gcloud 向您的 kubeconfig 文件添加了一个新的上下文,但旧的仍然是活动的。
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.您还可以检查您的 kubeconfig 文件。 The default location is
默认位置是
~/.kube/config
but can be overridden by KUBECONFIG
environment variable.但可以被
KUBECONFIG
环境变量覆盖。 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.也可能是 gcloud 将上下文添加到默认的 kubeconfig 文件,但您使用包含 EKS 上下文的
KUBECONFIG
env 变量进行了不同的设置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.