错误:无法从服务器读取版本 [英] error: couldn't read version from server

查看:206
本文介绍了错误:无法从服务器读取版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试在本地运行kubectl时出现以下错误.

I am getting the following error when trying to run kubectl locally.

error: couldn't read version from server: Get http://localhost:8080/api: dial tcp 127.0.0.1:8080: connection refused

我知道这与kubectl配置有关,但是我对如何解决它感到困惑. 2天前,我正在试验GKE,并确实将配置设置为指向GCE.我尝试删除此配置文件,然后在本地使用 Vagrant本地.此vagrant up抛出类似的错误,抱怨无法连接.

I know this relates to the kubectl config but I'm at a loss in how to resolve it. 2 days ago, I was experimenting with GKE and did set the config to point to GCE. I tried deleting this config file and then getting Vagrant with CoreOS locally. This vagrant up throws a similar error complaining about not being able to connect.

检测kubectl以便可以连接到API并返回信息的合适方法是什么?

What is the appropriate way to instrument kubectl so it can connect to the API and return information?

推荐答案

tl; dr gcloud container get-credentials --cluster=CLUSTER_ID --zone=YOURZONE

有一点背景知识:kubectl工具是由Google开发的,但实际上并没有直接集成到Google Cloud中,当您告诉它安装组件时,Google Cloud只会帮助您获得与其兼容的版本.

So a little background: the kubectl tool is developed by google but isn't actually integrated into google cloud directly, the google cloud just helps you get a compatible version with it when you tell it to install the component.

如果获取Get http://localhost:8080/api: dial tcp 127.0.0.1:8080: connection refused,则可能是由于kubectl工具根本没有配置或配置错误.我相信它正在尝试做的是假设您仅以某种方式在本地设置了kubernetes,在这种情况下您就没有了,因为它全部都在google云上(因此存在隐秘错误).

If you're getting the Get http://localhost:8080/api: dial tcp 127.0.0.1:8080: connection refused it is likely due to the kubectl tool not being configured at all or misconfigured. What I believe it's trying to do is assuming you have kubernetes somehow setup locally only, which you don't in this case since it's all on the google cloud (hence the cryptic error).

您可以通过运行kubectl config view来验证您的kubectl配置错误.如果配置正确,您应该会在群集中看到一些条目,带有ip地址,并且在用户中,您应该会看到每个项目的用户,等等.如果您没有看到任何排序(例如,空群集和空用户)那么您配置错误;如果您没有看到要尝试使用的特定群集的条目,也会遇到加密问题.

You can verify your kubectl is misconfigured by running kubectl config view. If it's correctly configured you should see things like a few entries in cluster, with ip addresses, and in users you should see a user for each project, etc. If you see nothing of the sort (ie. empty clusters, and empty users) then you are misconfigured; you will also encounter cryptic issues if you dont see entries for the specific cluster you are trying to work on.

令人讨厌的是,许多gcloud命令会自动为您自动配置它,因此,如果您遵循类似hello wordpress教程的内容,则看起来您不必这样做,并且kubectl可以与gcloud进行通信,但是什么也没做这种情况发生了.丢失该配置也很容易.

Annoyingly a lot of gcloud commands will silently auto-configure it for you, so if you follow something like a hello wordpress tutorial it will look like you dont have to do this and that somehow kubectl communicates with gcloud, but nothing of the sort happens. It's also very easy to lose that configuration.

要告诉gcloud为您提供kubectl配置,请运行以下命令:

To tell gcloud to give you the kubectl config run the following:

gcloud container get-credentials --cluster=CLUSTER_ID --zone=YOURZONE

对于集群ID,请运行gcloud container clusters list

For cluster id run gcloud container clusters list

区域是"europe-west1-d"或您选择的任何区域.

Zone is "europe-west1-d" or whatever you've chosen.

这篇关于错误:无法从服务器读取版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆