如何修复 kubectl 'The connection to the server localhost:8080 was refused - did you specify the right host or port?'
问题:
你想使用 kubectl 通过类似这样的命令配置 Kubernetes 服务
kubectl_patch_example.sh
kubectl patch service/"my-elasticsearch-svc" --namespace "default" --patch '{"spec": {"type": "LoadBalancer"}}'但你只看到此错误消息:
kubectl_error_message.txt
The connection to the server localhost:8080 was refused - did you specify the right host or port?解决方案
Kubernetes 没有访问集群的正确凭据。
使用以下命令将正确的凭据添加到 kubectl 配置
gcloud_get_credentials.sh
gcloud container clusters get-credentials [cluster name] --zone [cluster zone]例如
gcloud_container_list.sh
gcloud container clusters get-credentials cluster-1 --zone europe-west3-c之后,重试你的原始命令。
如果你不知道你的集群名称或区域,使用
gcloud_container_clusters_list.sh
gcloud container clusters list以显示集群元数据。
感谢此 StackOverflow 回答提供的原始解决方案。
Check out similar posts by category:
Allgemein, Cloud, Container, Kubernetes
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow