error: couldn't read version from server

后端 未结 6 2161
旧巷少年郎
旧巷少年郎 2021-02-13 13:12

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 tc

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-13 13:47

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


    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.

    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).

    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.

    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.

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

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

    For cluster id run gcloud container clusters list

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

提交回复
热议问题