如何使用 Vagrant 虛擬機器將 Kubernetes 工作節點加入到控制平面節點

如何使用 Vagrant 虛擬機器將 Kubernetes 工作節點加入到控制平面節點

我正在使用 Ubuntu 18.04 虛擬機器和 Vagrant 設定 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

流浪文件:

# -*- 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 初始化頁面上,如果我重新開始設定控制平面節點的過程並使用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.

相關內容