【问题标题】:Kubernetes with multus, and macvlan selecting the wrong interface eth0具有 multus 的 Kubernetes 和 macvlan 选择了错误的接口 eth0
【发布时间】:2022-10-25 14:28:06
【问题描述】:

我正在接受一些关于 kubernetes 的培训,并有以下配置。 4 个 vm 运行 ubuntu 20.04,一个主节点和 3 个节点和 calico CNI。 我设法部署了一些 nginx pod 并让连接按预期工作/

我正在尝试使用 multus 添加一个 macvlan 并一直按照此处的说明进行操作 https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/docs/quickstart.md

主服务器上显示 ip ad 的服务器输出(节点仅显示前 3 个接口)

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
   valid_lft forever preferred_lft forever
inet6 ::1/128 scope host 
   valid_lft forever preferred_lft forever
2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 52:54:00:de:3a:e5 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.230/24 brd 192.168.1.255 scope global enp1s0
   valid_lft forever preferred_lft forever
inet6 fe80::5054:ff:fede:3ae5/64 scope link 
   valid_lft forever preferred_lft forever
3: tunl0@NONE: <NOARP,UP,LOWER_UP> mtu 1480 qdisc noqueue state UNKNOWN group default qlen 1000
link/ipip 0.0.0.0 brd 0.0.0.0
inet 172.16.255.128/32 scope global tunl0
   valid_lft forever preferred_lft forever
6: calif1302e6e8bf@if4: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1480 qdisc noqueue state UP group default 
link/ether ee:ee:ee:ee:ee:ee brd ff:ff:ff:ff:ff:ff link-netns cni-93b9a0fa-78e3-34fa-f5e4-75b8c8b9f760
inet6 fe80::ecee:eeff:feee:eeee/64 scope link 
   valid_lft forever preferred_lft forever
7: cali8475067f6cf@if4: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1480 qdisc noqueue state UP group default 
link/ether ee:ee:ee:ee:ee:ee brd ff:ff:ff:ff:ff:ff link-netns cni-255cc6e9-b83e-ed27-8487-9b957f83520d
inet6 fe80::ecee:eeff:feee:eeee/64 scope link 
   valid_lft forever preferred_lft forever
8: cali2b9e0768962@if4: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1480 qdisc noqueue state UP group default 
link/ether ee:ee:ee:ee:ee:ee brd ff:ff:ff:ff:ff:ff link-netns cni-0826376f-5aea-ae7e-f10f-ae5aa6d0363a
inet6 fe80::ecee:eeff:feee:eeee/64 scope link 
   valid_lft forever preferred_lft forever

kubectl 的输出描述网络附件定义 macvlan-conf

Name:         macvlan-conf
Namespace:    default
Labels:       <none>
Annotations:  <none>
API Version:  k8s.cni.cncf.io/v1
Kind:         NetworkAttachmentDefinition
Metadata:
  Creation Timestamp:  2022-10-21T00:35:01Z
  Generation:          1
  Managed Fields:
    API Version:  k8s.cni.cncf.io/v1
    Fields Type:  FieldsV1
    fieldsV1:
      f:metadata:
        f:annotations:
          .:
          f:kubectl.kubernetes.io/last-applied-configuration:
      f:spec:
        .:
        f:config:
    Manager:         kubectl-client-side-apply
    Operation:       Update
    Time:            2022-10-21T00:35:01Z
  Resource Version:  491066
  UID:               a3d7f621-4ded-4987-ac65-250904528414
Spec:
  Config:  { "cniVersion": "0.3.0", "type": "macvlan", "master": "enp1s0", "mode": "bridge", "ipam": { "type": "host-local", "subnet": "192.168.100.0/24", "rangeStart": "192.168.100.200", "rangeEnd": "192.168.100.216", "routes": [ { "dst": "0.0.0.0/0" } ], "gateway": "192.168.1.254" } }
Events:    <none>

并从 kubectl 描述 daemonsets.apps -n kube-system kube-multus-ds

Name:           kube-multus-ds
Selector:       name=multus
Node-Selector:  <none>
Labels:         app=multus
                name=multus
                tier=node
Annotations:    deprecated.daemonset.template.generation: 1
Desired Number of Nodes Scheduled: 4
Current Number of Nodes Scheduled: 4
Number of Nodes Scheduled with Up-to-date Pods: 4
Number of Nodes Scheduled with Available Pods: 4
Number of Nodes Misscheduled: 0
Pods Status:  4 Running / 0 Waiting / 0 Succeeded / 0 Failed
Pod Template:
  Labels:           app=multus
                    name=multus
                    tier=node
  Service Account:  multus
  Init Containers:
   install-multus-binary:
    Image:      ghcr.io/k8snetworkplumbingwg/multus-cni:snapshot-thick
    Port:       <none>
    Host Port:  <none>
    Command:
      cp
      /usr/src/multus-cni/bin/multus-shim
      /host/opt/cni/bin/multus-shim
    Requests:
      cpu:        10m
      memory:     15Mi
    Environment:  <none>
    Mounts:
      /host/opt/cni/bin from cnibin (rw)
  Containers:
   kube-multus:
    Image:      ghcr.io/k8snetworkplumbingwg/multus-cni:snapshot-thick
    Port:       <none>
    Host Port:  <none>
    Command:
      /usr/src/multus-cni/bin/multus-daemon
    Args:
      -cni-version=0.3.1
      -cni-config-dir=/host/etc/cni/net.d
      -multus-autoconfig-dir=/host/etc/cni/net.d
      -multus-log-to-stderr=true
      -multus-log-level=verbose
    Limits:
      cpu:     100m
      memory:  50Mi
    Requests:
      cpu:        100m
      memory:     50Mi
    Environment:  <none>
    Mounts:
      /etc/cni/net.d/multus.d from multus-daemon-config (ro)
      /host/etc/cni/net.d from cni (rw)
      /host/run from host-run (rw)
      /hostroot from hostroot (rw)
      /run/k8s.cni.cncf.io from host-run-k8s-cni-cncf-io (rw)
      /run/netns from host-run-netns (rw)
      /var/lib/cni/multus from host-var-lib-cni-multus (rw)
      /var/lib/kubelet from host-var-lib-kubelet (rw)
  Volumes:
   cni:
    Type:          HostPath (bare host directory volume)
    Path:          /etc/cni/net.d
    HostPathType:  
   cnibin:
    Type:          HostPath (bare host directory volume)
    Path:          /opt/cni/bin
    HostPathType:  
   hostroot:
    Type:          HostPath (bare host directory volume)
    Path:          /
    HostPathType:  
   multus-daemon-config:
    Type:      ConfigMap (a volume populated by a ConfigMap)
    Name:      multus-daemon-config
    Optional:  false
   host-run:
    Type:          HostPath (bare host directory volume)
    Path:          /run
    HostPathType:  
   host-var-lib-cni-multus:
    Type:          HostPath (bare host directory volume)
    Path:          /var/lib/cni/multus
    HostPathType:  
   host-var-lib-kubelet:
    Type:          HostPath (bare host directory volume)
    Path:          /var/lib/kubelet
    HostPathType:  
   host-run-k8s-cni-cncf-io:
    Type:          HostPath (bare host directory volume)
    Path:          /run/k8s.cni.cncf.io
    HostPathType:  
   host-run-netns:
    Type:          HostPath (bare host directory volume)
    Path:          /run/netns/
    HostPathType:  
Events:            <none>

当我根据说明创建 samplepod 时,它保留在 默认 samplepod 0/1 ContainerCreating 0 40m

一个描述显示以下

 Normal   AddedInterface          31m                  multus   Add eth0 [172.16.169.153/32] from k8s-pod-network
  Normal   AddedInterface          78s (x269 over 40m)  multus   (combined from similar events): Add eth0 [172.16.169.177/32] from k8s-pod-network
  Warning  FailedCreatePodSandBox  73s (x278 over 40m)  kubelet  (combined from similar events): Failed to create pod sandbox: rpc error: code = Unknown desc = failed to setup network for sandbox "0eb93b24a13b6330323d061f818e15b0086707d1a853a9b4df823a52e31ab059": CNI request failed with status 400: '&{ContainerID:0eb93b24a13b6330323d061f818e15b0086707d1a853a9b4df823a52e31ab059 Netns:/var/run/netns/cni-308cd3e6-f3e7-3eaf-0f25-b90dd50c3b08 IfName:eth0 Args:IgnoreUnknown=1;K8S_POD_NAMESPACE=default;K8S_POD_NAME=samplepod;K8S_POD_INFRA_CONTAINER_ID=0eb93b24a13b6330323d061f818e15b0086707d1a853a9b4df823a52e31ab059;K8S_POD_UID=53c586ce-0fd1-4991-bbff-188bb534d728 Path: StdinData:[123 34

此日志中有对 eth0 的引用,但我没有在任何此配置中指定 eth0。

我错过了什么(很可能)

这是显示配置的错误之前的 samplepod 输出

Name:             samplepod
Namespace:        default
Priority:         0
Service Account:  default
Node:             kube-node-2/192.168.1.232
Start Time:       Fri, 21 Oct 2022 13:40:12 +1300
Labels:           <none>
Annotations:      cni.projectcalico.org/containerID: cfe4778b5963e7d28365b6012ed0297a0d3c0dc9b0609c0f65a8d97f32ec7f41
                  cni.projectcalico.org/podIP: 
                  cni.projectcalico.org/podIPs: 
                  k8s.v1.cni.cncf.io/networks: macvlan-conf
Status:           Pending
IP:               
IPs:              <none>
Containers:
  samplepod:
    Container ID:  
    Image:         alpine
    Image ID:      
    Port:          <none>
    Host Port:     <none>
    Command:
      /bin/ash
      -c
      trap : TERM INT; sleep infinity & wait
    State:          Waiting
      Reason:       ContainerCreating
    Ready:          False
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-htggc (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             False 
  ContainersReady   False 
  PodScheduled      True 
Volumes:
  kube-api-access-htggc:
    Type:                    Projected (a volume that contains injected data from multiple sources)
    TokenExpirationSeconds:  3607
    ConfigMapName:           kube-root-ca.crt
    ConfigMapOptional:       <nil>
    DownwardAPI:             true
QoS Class:                   BestEffort
Node-Selectors:              <none>
Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                             node.kubernetes.io/unreachable:NoExecute op=Exists for 300s

【问题讨论】:

    标签: kubernetes cni macvlan


    【解决方案1】:

    尝试来自官方multus-cni repo - https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/examples/macvlan-pod.yml 的配置

    特别关注plugins 部分,即:

    spec:
      config: |
        {
          "name": "macvlan-conf",
          "cniVersion": "0.3.1",
          "plugins": [
            {
              "cniVersion": "0.3.1",
              "type": "macvlan",
              "master": "enp1s0",
              "mode": "bridge",
              "ipam": {
                "type": "host-local",
                "subnet": "192.168.100.0/24",
                "rangeStart": "192.168.100.200",
                "rangeEnd": "192.168.100.216", 
                "routes": [
                  {
                    "dst": "0.0.0.0/0",
                    "gw": "192.168.100.254"
                  }
                ]
              }
            }
          ]
        }
    

    以上不是经过测试的示例顺便说一句。

    进行更改后,执行所有正常的操作,例如重新启动 multus 守护程序集并删除您的 pod。

    【讨论】:

    • 错误日志中仍然引用 eth0 的结果相同。我使用的定义是相似的。关键区别在于网关的定义方式 "rangeEnd": "192.168.100.216", "routes": [ { "dst": "0.0.0.0/0" } ], "gateway": "192.168.1.254" }
    • 尝试删除 macvlan-conf 注释并且容器启动正常,并且存在 eth0。我假设它是由 calico 创建的,因此怀疑该部分在移动到 macvlan 创建时总是成功和失败。将查看 multus 日志中是否有任何线索
    • 实际上只是意识到错误已经改变。似乎与网关更改有关,并且看到我的网关在 192.168.1.X 中,而 IP 范围在 192.168.100.x 中。将网关更改为 192.168.100.254 并开始正常,使用默认接口和 macvlan 之一。目前不确定是什么决定了这应该是什么。这个字段是否真的定义了网关。所有这些网络仍然是新的。
    • 为我的回答中的gateway 错误道歉。将修复为100Pod 现在开始了吗?还是还是ContainerCreating
    猜你喜欢
    • 2021-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-03
    • 1970-01-01
    • 1970-01-01
    • 2017-10-09
    相关资源
    最近更新 更多