【问题标题】:The connection to the server localhost:8080 was refused when the configuration does not point to localhost当配置不指向 localhost 时,与服务器 localhost:8080 的连接被拒绝
【发布时间】:2021-09-10 23:29:45
【问题描述】:

我无法连接到我们的 Kubernetes 集群。 kubectl 命令似乎没有考虑到配置...

当我发出kubectl cluster-info(或kubectl get pods) 我收到以下错误消息:

与服务器 localhost:8080 的连接被拒绝 - 您是否指定了正确的主机或端口?

我怀疑 ~/.kube/config 指向我的 minikube,但事实并非如此:

apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: LS...==
    server: https://10.95.xx.yy:6443
  name: cluster.local
contexts:
- context:
    cluster: cluster.local
    namespace: xxx-cluster-xxx-xx-username
    user: username
  name: username-context
current-context: ""
kind: Config
preferences: {}
users:
- name: username
  user:
    client-certificate: .certs/username.crt
    client-key: .certs/username.key

令人惊讶的是,$KUBECONFIG 环境变量设置为正确的路径:

KUBECONFIG=/Users/username/.kube/config

kubectl config view 工作正常(又名不是指向localhost,而是指向https://10.95.xx.yy:6443

最后我也尝试在调用kubectl(kubectl get pods --kubeconfig=/Users/username/.kube/config)的时候指定配置文件的路径,但是报错还是一样...

【问题讨论】:

  • 您当前的上下文未设置,如current-context: "" 所示;如果您要使用 kubectl --context username-context get pods,我希望它会做更多您所期望的事情,并且假设我是对的,运行 kubectl config set-context username-context 将继续解决它
  • @mdaniel 如果您将您的评论作为答案,我会接受。谢谢

标签: kubernetes kubectl


【解决方案1】:

您当前的上下文未设置,如current-context: "" 所示;如果您要运行kubectl --context username-context get pods,我希望它可以做更多您想做的事情。如果结果是这样,可以运行kubectl config use-context username-context 来设置current-context 继续前进

【讨论】:

    猜你喜欢
    • 2018-01-25
    • 1970-01-01
    • 2020-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多