【问题标题】:The connection to the server xxxx:6443 was refused - did you specify the right host or port?与服务器 xxxx:6443 的连接被拒绝 - 您是否指定了正确的主机或端口?
【发布时间】:2020-02-25 07:18:47
【问题描述】:

我关注 this 在我的云上安装 kubernetes。 当我运行命令 kubectl get nodes 时,我收到此错误:

The connection to the server localhost:6443 was refused - did you specify the right host or port? 

我该如何解决这个问题?

【问题讨论】:

  • 您至少可以连接到该服务吗? telnet localhost 6443
  • @Lester 是的。我可以

标签: kubernetes


【解决方案1】:

如果您只关注提到的文档,则意味着您只安装了kubeadmkubectlkubelet

如果你想正确运行kubeadm,你需要多做 3 步。

1.安装docker

安装Docker ubuntu version。如果您使用的是其他系统,请从左侧菜单中选择它。

原因:

如果您不安装 docker,您将收到如下错误:

preflight] WARNING: Couldn't create the interface used for talking to the container runtime: docker is required for container runtime: exec: "docker": e
xecutable file not found in $PATH
error execution phase preflight: [preflight] Some fatal errors occurred:
        [ERROR FileContent--proc-sys-net-bridge-bridge-nf-call-iptables]: /proc/sys/net/bridge/bridge-nf-call-iptables does not exist
        [ERROR FileContent--proc-sys-net-ipv4-ip_forward]: /proc/sys/net/ipv4/ip_forward contents are not set to 1
[preflight] If you know what you are doing, you can make a check non-fatal with `--ignore-preflight-errors=...`
To see the stack trace of this error execute with --v=5 or higher

2。 kubeadm的初始化

你已经正确安装了kubeadmdocker,但是现在你需要初始化kubeadm。文档可以找到here

简而言之,您必须运行命令

$ sudo kubeadm init

初始化后,您将收到运行以下命令的信息:

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

和令牌以将另一个 VM 加入集群。好像

kubeadm join 10.166.XX.XXX:6443 --token XXXX.XXXXXXXXXXXX \
    --discovery-token-ca-cert-hash sha256:aXXXXXXXXXXXXXXXXXXXXXXXX166b0b446986dd05c1334626aa82355e7 

如果您想在初始化阶段运行一些特殊操作,请查看this docs

3。将节点状态更改为Ready

上一步之后就可以执行了

$ kubectl get nodes
NAME           STATUS     ROLES    AGE     VERSION
ubuntu-kubeadm   NotReady   master   4m29s   v1.16.2

但是您的节点将处于NotReady 状态。如果您将其描述为$ kubectl describe node,您将看到错误:

Ready            False   Wed, 30 Oct 2019 09:55:09 +0000   Wed, 30 Oct 2019 09:50:03 +0000   KubeletNotReady              runtime network not ready: Ne
tworkReady=false reason:NetworkPluginNotReady message:docker: network plugin is not ready: cni config uninitialized

这意味着您必须安装一个 CNI。他们的名单可以在here找到。

编辑

我还想到一件事。

有时当您关闭并打开虚拟机时,您需要重新启动 kubelet 和 docker 服务。您可以使用

$ service docker restart
$ systemctl restart kubelet

希望对你有帮助。

【讨论】:

    【解决方案2】:

    看起来 kubeconfig 文件丢失了。您是否将 admin.conf 文件复制到 ~/.kube/config ?

    【讨论】:

      【解决方案3】:

      验证是否有任何代理设置,如“http_proxy”或“https_proxy”,主要是我们将其设置为环境变量。如果是,则删除代理,它应该适合您。

      【讨论】:

        【解决方案4】:

        我做了以下两个步骤。 kubectl 现在可以工作了。

        $ service docker restart
        $ systemctl restart kubelet
        

        【讨论】:

          猜你喜欢
          • 2022-10-13
          • 2022-11-17
          • 2019-11-06
          • 2019-07-17
          • 1970-01-01
          • 2018-12-03
          • 2019-09-25
          • 2021-03-16
          • 2018-12-09
          相关资源
          最近更新 更多