如何使用 Vagrant 虚拟机将 Kubernetes 工作节点加入控制平面节点

如何使用 Vagrant 虚拟机将 Kubernetes 工作节点加入控制平面节点

我正在使用带有 Vagrant 的 Ubuntu 18.04 虚拟机设置 Kubernetes 集群。一切顺利,直到我尝试kubeadm join 10.0.2.15:6443 --token ...在工作节点上运行命令时出现错误:

[preflight] Running pre-flight checks
error execution phase preflight: couldn't validate the identity of the API Server: Get "https://10.0.2.15:6443/api/v1/namespaces/kube-public/configmaps/cluster-info?timeout=10s": dial tcp 10.0.2.15:6443: connect: connection refused

kubeadm token create --print-join-command我的假设是这是一个网络问题,因为控制平面节点中指定的 IP 地址是10.0.2.15:6443,这不是我在 Vagrantfile 中为控制计划节点指定的 IP 地址(172.16.94.10,见下文)。但是,即使我手动更改 kubeadm join 命令,如下所示:sudo kubeadm join 172.16.94.10:6443 --token ...,我也会收到类似的错误。我该如何解决这个问题?

Ubuntu 系统信息:

  System load:  0.22              Users logged in:      0
  Usage of /:   4.4% of 97.23GB   IP address for eth0:  10.0.2.15
  Memory usage: 40%               IP address for eth1:  172.16.94.10
  Swap usage:   0%                IP address for tunl0: 192.168.13.192
  Processes:    144

Vagrant文​​件:

# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
  config.vm.box = "base"

  config.vm.define "c1-cp1" do |c1cp1|
    c1cp1.vm.box = "bento/ubuntu-18.04"
    c1cp1.disksize.size = '100GB'
    c1cp1.vm.network "private_network", ip: "172.16.94.10"
    c1cp1.vm.hostname = "c1-cp1"
    c1cp1.vm.provider "virtualbox" do |vb|
      vb.memory = "2048"
      vb.cpus = "2"
    end
  end

  config.vm.define "c1-node1" do |c1node1|
    c1node1.vm.box = "bento/ubuntu-18.04"
    c1node1.disksize.size = '100GB'
    c1node1.vm.network "private_network", ip: "172.16.94.11"
    c1node1.vm.hostname = "c1-node1"
    c1node1.vm.provider "virtualbox" do |vb|
      vb.memory = "2048"
      vb.cpus = "2"
    end
  end

end

答案1

根据kubeadm init页面上,如果我重新开始设置控制平面节点的过程并使用sudo kubeadm init --apiserver-advertise-address="172.16.94.10" --apiserver-cert-extra-sans="172.16.94.10"而不是普通的sudo kubeadm init,这将配置kubeadm为使用 Vagrantfile 中定义的正确的可路由 IP 地址。

我得到的结果:

This node has joined the cluster:
* Certificate signing request was sent to apiserver and a response was received.
* The Kubelet was informed of the new secure connection details.

Run 'kubectl get nodes' on the control-plane to see this node join the cluster.

相关内容