Kubernetes:weave 在其中一个工作节点上选择了 public IP

Kubernetes: weave picked the public IP on one of the worker nodes

我有一个 2 master 和 2 worker kubernetes 集群。每个节点都有 192.168.5.X 和 public IP 范围内的私有 IP。 创建 weave daemonset 后,weave pod 在一个节点上选择了正确的内部 IP,但在另一个节点上它选择了 public IP。有什么方法可以指示 weave pod 在节点上选择私有 IP?

我通过在本地笔记本电脑上的 Virtual Box 上创建的 VM 上手动执行所有操作,从头开始创建集群。我参考下面的 link

https://github.com/mmumshad/kubernetes-the-hard-way

在工作节点上部署 weave pods 后,其中一个工作节点上的 weave pod 使用 NAT ip,如下所示。

10.0.2.15 是 NAT IP,192.168.5.12 是内部 IP

kubectl get pods -n kube-system -o wide
NAME              READY   STATUS    RESTARTS   AGE   IP             NODE      NOMINATED NODE   READINESS GATES
weave-net-p4czj   2/2     Running   2          26h   192.168.5.12   worker1   <none>           <none>
weave-net-pbb86   2/2     Running   8          25h   10.0.2.15      worker2   <none>           <none>
[@master1 ~]$ kubectl describe node
Name:               worker1
Roles:              <none>
Labels:             beta.kubernetes.io/arch=amd64
                    beta.kubernetes.io/os=linux
                    kubernetes.io/hostname=worker1
Annotations:        node.alpha.kubernetes.io/ttl: 0
                    volumes.kubernetes.io/controller-managed-attach-detach: true
CreationTimestamp:  Tue, 10 Dec 2019 02:07:09 -0500
Taints:             <none>
Unschedulable:      false
Conditions:
  Type                 Status  LastHeartbeatTime                 LastTransitionTime                Reason                       Message
  ----                 ------  -----------------                 ------------------                ------                       -------
  NetworkUnavailable   False   Wed, 11 Dec 2019 04:50:15 -0500   Wed, 11 Dec 2019 04:50:15 -0500   WeaveIsUp                    Weave pod has set this
  MemoryPressure       False   Wed, 11 Dec 2019 07:13:43 -0500   Tue, 10 Dec 2019 02:09:09 -0500   KubeletHasSufficientMemory   kubelet has sufficient memory available
  DiskPressure         False   Wed, 11 Dec 2019 07:13:43 -0500   Tue, 10 Dec 2019 02:09:09 -0500   KubeletHasNoDiskPressure     kubelet has no disk pressure
  PIDPressure          False   Wed, 11 Dec 2019 07:13:43 -0500   Tue, 10 Dec 2019 02:09:09 -0500   KubeletHasSufficientPID      kubelet has sufficient PID available
  Ready                True    Wed, 11 Dec 2019 07:13:43 -0500   Tue, 10 Dec 2019 04:16:26 -0500   KubeletReady                 kubelet is posting ready status
Addresses:
  InternalIP:  192.168.5.12
  Hostname:    worker1
Capacity:
 cpu:                1
 ephemeral-storage:  14078Mi
 hugepages-2Mi:      0
 memory:             499552Ki
 pods:               110
Allocatable:
 cpu:                1
 ephemeral-storage:  13285667614
 hugepages-2Mi:      0
 memory:             397152Ki
 pods:               110
System Info:
 Machine ID:                 455146bc2c2f478a859bf39ac2641d79
 System UUID:                D4C6F432-3C7F-4D27-A21B-D78A0D732FB6
 Boot ID:                    25160713-e53e-4a9f-b1f5-eec018996161
 Kernel Version:             4.4.206-1.el7.elrepo.x86_64
 OS Image:                   CentOS Linux 7 (Core)
 Operating System:           linux
 Architecture:               amd64
 Container Runtime Version:  docker://18.6.3
 Kubelet Version:            v1.13.0
 Kube-Proxy Version:         v1.13.0
Non-terminated Pods:         (2 in total)
  Namespace                  Name                   CPU Requests  CPU Limits  Memory Requests  Memory Limits  AGE
  ---------                  ----                   ------------  ----------  ---------------  -------------  ---
  default                    ng1-6677cd8f9-hws8n    0 (0%)        0 (0%)      0 (0%)           0 (0%)         26h
  kube-system                weave-net-p4czj        20m (2%)      0 (0%)      0 (0%)           0 (0%)         26h
Allocated resources:
  (Total limits may be over 100 percent, i.e., overcommitted.)
  Resource           Requests  Limits
  --------           --------  ------
  cpu                20m (2%)  0 (0%)
  memory             0 (0%)    0 (0%)
  ephemeral-storage  0 (0%)    0 (0%)
Events:              <none>


Name:               worker2
Roles:              <none>
Labels:             beta.kubernetes.io/arch=amd64
                    beta.kubernetes.io/os=linux
                    kubernetes.io/hostname=worker2
Annotations:        node.alpha.kubernetes.io/ttl: 0
                    volumes.kubernetes.io/controller-managed-attach-detach: true
CreationTimestamp:  Tue, 10 Dec 2019 03:14:01 -0500
Taints:             <none>
Unschedulable:      false
Conditions:
  Type                 Status  LastHeartbeatTime                 LastTransitionTime                Reason                       Message
  ----                 ------  -----------------                 ------------------                ------                       -------
  NetworkUnavailable   False   Wed, 11 Dec 2019 04:50:32 -0500   Wed, 11 Dec 2019 04:50:32 -0500   WeaveIsUp                    Weave pod has set this
  MemoryPressure       False   Wed, 11 Dec 2019 07:13:43 -0500   Tue, 10 Dec 2019 03:14:03 -0500   KubeletHasSufficientMemory   kubelet has sufficient memory available
  DiskPressure         False   Wed, 11 Dec 2019 07:13:43 -0500   Tue, 10 Dec 2019 03:14:03 -0500   KubeletHasNoDiskPressure     kubelet has no disk pressure
  PIDPressure          False   Wed, 11 Dec 2019 07:13:43 -0500   Tue, 10 Dec 2019 03:14:03 -0500   KubeletHasSufficientPID      kubelet has sufficient PID available
  Ready                True    Wed, 11 Dec 2019 07:13:43 -0500   Tue, 10 Dec 2019 03:56:47 -0500   KubeletReady                 kubelet is posting ready status
Addresses:
  InternalIP:  10.0.2.15
  Hostname:    worker2
Capacity:
 cpu:                1
 ephemeral-storage:  14078Mi
 hugepages-2Mi:      0
 memory:             499552Ki
 pods:               110
Allocatable:
 cpu:                1
 ephemeral-storage:  13285667614
 hugepages-2Mi:      0
 memory:             397152Ki
 pods:               110
System Info:
 Machine ID:                 455146bc2c2f478a859bf39ac2641d79
 System UUID:                68F543D7-EDBF-4AF6-8354-A99D96D994EF
 Boot ID:                    5775abf1-97dc-411f-a5a0-67f51cc8daf3
 Kernel Version:             4.4.206-1.el7.elrepo.x86_64
 OS Image:                   CentOS Linux 7 (Core)
 Operating System:           linux
 Architecture:               amd64
 Container Runtime Version:  docker://18.6.3
 Kubelet Version:            v1.13.0
 Kube-Proxy Version:         v1.13.0
Non-terminated Pods:         (2 in total)
  Namespace                  Name                    CPU Requests  CPU Limits  Memory Requests  Memory Limits  AGE
  ---------                  ----                    ------------  ----------  ---------------  -------------  ---
  default                    ng2-569d45c6b5-ppkwg    0 (0%)        0 (0%)      0 (0%)           0 (0%)         26h
  kube-system                weave-net-pbb86         20m (2%)      0 (0%)      0 (0%)           0 (0%)         26h
Allocated resources:
  (Total limits may be over 100 percent, i.e., overcommitted.)
  Resource           Requests  Limits
  --------           --------  ------
  cpu                20m (2%)  0 (0%)
  memory             0 (0%)    0 (0%)
  ephemeral-storage  0 (0%)    0 (0%)
Events:              <none>

我看到您不仅在 pods 中有不同的 IP,而且在您的节点中也有不同的 IP。

正如您在 kubectl describe node 输出中看到的那样,worker1InternalIP192.168.5.12worker2 的是 10.0.2.15

这不是预期的行为,因此请务必确保将两个 VirtualBox VM 连接到相同的适配器类型。

两者应该在同一个网络中,并且在评论中您确认是这种情况并且解释了这种行为。

这是该配置的示例:

正如您在评论中提到的那样,第一个节点是手动添加的,第二个节点是在 TLS bootstraping 期间添加的,即使使用 "wrong" IP 地址也添加了它。

要解决此问题,您可以做的最好的事情是 bootstrap 您再次从头开始集群,对所有节点在 Virtual Box 上使用相同的适配器设置。