英文:
calling kubectl version on Google Cloud Terminal takes ~30 seconds and returns "Unable to connect to the server: dial tcp ... timeout"
问题
我正在从https://codelabs.developers.google.com/codelabs/cloud-springboot-kubernetes?continue=https%3A%2F%2Fdevelopers.google.com%2Flearn%2Fpathways%2Fjava-cloud-fundamentals%23codelab-https%3A%2F%2Fcodelabs.developers.google.com%2Fcodelabs%2Fcloud-springboot-kubernetes#5上进行一些教程。我正在使用Google Cloud Console。当我键入:
kubectl version
我得到一个响应:
警告:此版本信息已过时,将替换为kubectl version --short的输出。使用--output=yaml|json获取完整版本。
客户端版本:version.Info{Major:"1", Minor:"27", GitVersion:"v1.27.2", GitCommit:"7f6f68fdabc4df88cfea2dcf9a19b2b830f1e647", GitTreeState:"clean", BuildDate:"2023-05-17T14:20:07Z", GoVersion:"go1.20.4", Compiler:"gc", Platform:"linux/amd64"}
Kustomize版本:v5.0.1
无法连接到服务器:拨号tcp 34.135.56.138:443:i/o超时
我不喜欢的是
无法连接到服务器:拨号tcp 34.135.56.138:443:i/o超时
当运行其他kubectl命令时,我也遇到了这个错误,这阻碍了我的进度。我只使用Google Cloud提供的开箱即用工具。在Google Cloud Console中,是什么导致了这个错误?我是否需要进行额外的Kubernetes配置?(教程没有提到类似的内容)
运行评论中建议的命令:
gcloud container clusters get-credentials hello-java-cluster --zone=us-central1-c
我得到了一个错误:
获取集群端点和授权数据。
错误:(gcloud.container.clusters.get-credentials) ResponseError:code=404,message=Not found:projects/question-tracker/zones/us-central1-c/clusters/hello-java-cluster。
在question-tracker中没有名为'hello-java-cluster'的集群。
编辑:
我运行了以下命令:(与hello-java-cluster不同,我使用了先前创建的questy-java-cluster)
(quizdev)$ gcloud container clusters get-credentials questy-java-cluster --zone=us-central1-c
这次没有出错,并且得到了以下结果:
获取集群端点和授权数据。
为questy-java-cluster生成了kubeconfig条目。
在此操作之后,kubectl version在1秒内运行,不再报错。
英文:
I am doing some tutorials from https://codelabs.developers.google.com/codelabs/cloud-springboot-kubernetes?continue=https%3A%2F%2Fdevelopers.google.com%2Flearn%2Fpathways%2Fjava-cloud-fundamentals%23codelab-https%3A%2F%2Fcodelabs.developers.google.com%2Fcodelabs%2Fcloud-springboot-kubernetes#5. I am using Google Cloud Console. When I type:
kubectl version
I am getting an response:
WARNING: This version information is deprecated and will be replaced with the output from kubectl version --short. Use --output=yaml|json to get the full version.
Client Version: version.Info{Major:"1", Minor:"27", GitVersion:"v1.27.2", GitCommit:"7f6f68fdabc4df88cfea2dcf9a19b2b830f1e647", GitTreeState:"clean", BuildDate:"2023-05-17T14:20:07Z", GoVersion:"go1.20.4", Compiler:"gc", Platform:"linux/amd64"}
Kustomize Version: v5.0.1
Unable to connect to the server: dial tcp 34.135.56.138:443: i/o timeout
What I do not like is the
Unable to connect to the server: dial tcp 34.135.56.138:443: i/o timeout
I am getting this error also when running other kubectl commands, which stops my progress.
I am using only out of the box tools provided by Google Cloud.
What is causing this error in Google Cloud Console? Do I need to make additional Kubernetes configuration? (The tutorial did not mention anything like that)
Running the command as suggested in the comments:
gcloud container clusters get-credentials hello-java-cluster --zone=us-central1-c
I am getting an error:
Fetching cluster endpoint and auth data.
ERROR: (gcloud.container.clusters.get-credentials) ResponseError: code=404, message=Not found: projects/question-tracker/zones/us-central1-c/clusters/hello-java-cluster.
No cluster named 'hello-java-cluster' in question-tracker.
EDIT:
I have run the command: (instead of hello-java-cluster I ran it with previously created questy-java-cluster)
(quizdev)$ gcloud container clusters get-credentials questy-java-cluster --zone=us-central1-c
And it ran without error giving result:
Fetching cluster endpoint and auth data.
kubeconfig entry generated for questy-java-cluster.
After this operation kubectl version runs in 1 second and does not give the error.
答案1
得分: 1
有2个步骤被gcloud
模糊成一个步骤。
gcloud container clusters create
命令不仅创建集群,还通过kubeconfig (~/.kube/config
)配置kubectl
以访问该集群。
如果在gcloud container clusters create
之后无法执行例如kubectl get nodes
,并且您确信集群已成功创建(通过Cloud Console进行检查),则可能是kubeconfig文件配置不正确。
请确认默认位置的kubeconfig文件(~/.kube/config)存在并包含与您的集群对应的数据(cluster
、server
、user
)条目。
如果一切正常,您可以尝试重复配置kubeconfig的步骤:gcloud container clusters get-credentials hello-java-cluster --zone=us-central1-c
。如果运行这些命令时出现任何其他错误,请编辑您的问题并包含错误信息。
如果您已更改集群的 {NAME}
、{LOCATION}
或使用不同的Google Cloud {PROJECT}
,请在上述命令中使用这些值(替换为正确的值):
gcloud container clusters get-credentials ${NAME} \
--location=${LOCATION} \
--project=${PROJECT}
英文:
There are 2 steps that get blurred by gcloud
into one.
The gcloud container clusters create
command not only creates the cluster but it also configures kubectl
via kubeconfig (~/.kube/config
) to access the cluster.
If you're unable to e.g. kubectl get nodes
after gcloud container clusters create
and you're confident the cluster created successfully (i.e. by checking Cloud Console), it may be that the kubeconfig file was not correctly configured.
Please confirm that the kubeconfig file in the default location (~/.kube/config) exists and contains data (cluster
, server
, user
) entries correspondonging to your cluster.
If that all looks good, you can try repeating the step that configures kubeconfig: gcloud container clusters get-credentials hello-java-cluster --zone=us-central1-c
. If there are any other errors running these commands, please edit your question and include the errors.
If you've changed the cluster's {NAME}
, {LOCATION}
or are using a different Google Cloud {PROJECT}
, please use these (replacing with the correct values) in the above command:
gcloud container clusters get-credentials ${NAME} \
--location=${LOCATION} \
--project=${PROJECT}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论