• Kubernetes
  • 在本地配置kubectl 连接远程集群

我在本地通过scp复制了集群的.kube文件夹,config文件如下:

apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: {xxxxxxxx}
    server: https://192.168.1.15:6443
  name: cluster.local
contexts:
- context:
    cluster: cluster.local
    user: kubernetes-admin
  name: kubernetes-admin@cluster.local
current-context: kubernetes-admin@cluster.local
kind: Config
preferences: {}
users:
- name: kubernetes-admin
  user:
    client-certificate-data: {xxxxxxxx}
    client-key-data: {xxxx}

我把master节点的内网地址192.168.1.15改称了公网地址,并开放了6443端口,但本地执行 kubectl 仍然报错:

Client Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.2", GitCommit:"52c56ce7a8272c798dbc29846288d7cd9fbae032", GitTreeState:"clean", BuildDate:"2020-04-16T11:56:40Z", GoVersion:"go1.13.9", Compiler:"gc", Platform:"windows/amd64"}
Unable to connect to the server: x509: certificate is valid for 10.233.0.1, 192.168.1.15, 192.168.1.15, 10.233.0.1, 127.0.0.1, 192.168.1.15, not [master公网地址]

是什么原因呢?

试过降低本地的kubectl版本但没用

    xiaofine master改成公网地址应该有问题,可以在原环境看下,公网ip是否显示。

      Forest-L
      我在config改的:

      ...
      clusters:
      - cluster:
          certificate-authority-data: {xxxxxxxx}
          server: https://[公网地址]:6443
        name: cluster.local
      ...

      这个地址是我申请的弹性IP绑定到master主机上,集群本身可能不知道这个地址

      • Jeff 回复了此帖

        xiaofine 公网IP地址需要添加到生成的集群apiserver证书里的,你找下相应的资料,网上应该有的

        1 年 后

        同问,我配置本地 IP 后,切换至 admin 用户然后执行:
        kubectl config use-context kubernetes-admin@cluster.local
        然后再:
        kubectl get pods –all-namespaces
        提示:
        Unable to connect to the server: dial tcp: lookup :192.168.178.34: no such host

        但我 /etc/hosts 中 已经配置 192.168.178.34 的 dns 了。

        jessechan
        你这个是证书的问题。 member集群的kube-apiserver集群的证书里面不包含1.14.138.84. 你需要更新一下证书