k8s中阶_001_Pod网络_01_CNI插件_01_插件选择

背景:

在集群搭建之前,需要根据集群的部署环境的限制应用需求对CNI插件进行选择

1.简介:

  1. 容器网络接口标准:Container Network Interface
  2. CNI插件:CNI接口标准的实现。常见插件有:flannel、Calico、Weave Net、midonet、Contiv和公有云厂商提供的CNI插件如 Amazon VPC、Aliyun Terway 
  3. kubelet:根据CNI插件对应的ConfigMap配置信息调用CNI插件来实现Pod网络配置

以flannel为例:

配置:/etc/cni/net.d/10-flannel.conflist,网段信息配置存放kubeadm配置里面

插件:/opt/cni/bin/flannel

查看flannel完整配置:

[root@k8s-ha-master02 ~]# kubectl edit cm kube-flannel-cfg -n kube-system


# Please edit the object below. Lines beginning with a '#' will be ignored,
# and an empty file will abort the edit. If an error occurs while saving this file will be
# reopened with the relevant failures.
#
apiVersion: v1
data:
  cni-conf.json: |
    {
      "name": "cbr0",
      "cniVersion": "0.3.1",
      "plugins": [
        {
          "type": "flannel",
          "delegate": {
            "hairpinMode": true,
            "isDefaultGateway": true
          }
        },
        {
          "type": "portmap",
          "capabilities": {
            "portMappings": true
          }
        }
      ]
    }
  net-conf.json: |
    {
      "Network": "10.244.0.0/16",
      "Backend": {
        "Type": "vxlan"
      }
    }
kind: ConfigMap
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"v1","data":{"cni-conf.json":"{\n  \"name\": \"cbr0\",\n  \"cniVersion\": \"0.3.1\",\n  \"plugins\": [\n    {\n      \"type\": \"flannel\",\n      \"delegate\": {\n        \"hairpinMode\": true,\n        \"isDefaultGateway\": true\n      }\n    },\n    {\n      \"type\": \"portmap\",\n      \"capabilities\": {\n        \"portMappings\": true\n      }\n    }\n  ]\n}\n","net-conf.json":"{\n  \"Network\": \"10.244.0.0/16\",\n  \"Backend\": {\n    \"Type\": \"vxlan\"\n  }\n}\n"},"kind":"ConfigMap","metadata":{"annotations":{},"labels":{"app":"flannel","tier":"node"},"name":"kube-flannel-cfg","namespace":"kube-system"}}
  creationTimestamp: "2020-03-11T09:00:10Z"
  labels:
    app: flannel
    tier: node
  name: kube-flannel-cfg
  namespace: kube-system
  resourceVersion: "7528"
  selfLink: /api/v1/namespaces/kube-system/configmaps/kube-flannel-cfg
  uid: 372fd042-e710-4c8d-89cf-2c6aea5ec2d6

2.CNI插件类型

常见插件有:flannel、Calico、Weave Net、midonet、Contiv和公有云厂商提供的CNI插件如 Amazon VPC、Aliyun Terway

2.1 Overlay插件-虚拟化环境  

如私有云openstack、共有云和VMWare。

Hypervisor01和Hypervisor02在同一个局域网中

Hypervisor01:vmware fusion-NAT

[root@k8s-ha-master02 ~]# arp | grep -v 172
Address                  HWtype  HWaddress           Flags Mask            Iface
k8s-ha-vip               ether   00:50:56:25:63:38   C                     ens34
10.244.2.0               ether   46:e6:cb:45:b0:bb   CM                    flannel.1
k8s-ha-master01          ether   00:50:56:3b:28:5f   C                     ens34
10.244.4.0               ether   2a:a6:bd:43:79:29   CM                    flannel.1
10.244.3.0               ether   e2:1a:a6:2d:05:3a   CM                    flannel.1
k8s-node02               ether   00:50:56:2b:24:a8   C                     ens34
k8s-ha-master03          ether   00:50:56:25:63:38   C                     ens34
10.244.1.7               ether   22:52:b3:8f:a1:bb   C                     cni0
10.244.0.0               ether   7a:97:6f:d0:e8:8f   CM                    flannel.1
k8s-node01               ether   00:50:56:2f:61:ef   C                     ens34
xiliuyaodeMBP            ether   8c:85:90:59:f6:33   C                     ens34

Hypervisor02:vmware workstation-NAT

[root@bogon dist]# arp
? (192.168.43.149) at 8c:85:90:59:f6:33 [ether] on ens34
xiliuyaodeMBP (192.168.43.68) at 8c:85:90:59:f6:33 [ether] on ens34
gateway (192.168.43.1) at a8:9c:ed:f2:4b:a6 [ether] on ens34

通过mac广播可以看出三点:

  1. Hypervisor01管理vm之间可以进行mac广播
  2. vm可以向物理机广播
  3. Hypervisor02与Hypervisor01对外部mac广播都都进行了隔离。

总结:跨Hypervisor的vm之间存在数据链路层通信限制

选择Overlay插件:

  1. 虚拟化或者私有云:Calico-ipip,Flannel-vxlan、Weave
  2. 共有云建议选择云厂商提供的插件:Amazon VPC、Aliyun Terway

优点:

  1. pod创建速度快。pause容器:kubelet创建网络资源,不需要协调硬件
  2. 支持service服务发现

缺点:

  1. 网络通信消耗node计算资源和性能,如node封包、拆包或者NAT端口转发。
  2. pod网络延时较大

2.2 Underlay插件-物理机node集群(同一交换机下的node或者不限mac广播的跨交换机node)

限制较少,可以选择Underlay插件:Calica-bgp,flannel-hostgw、sriov

优点:

  1. 网络性能有优势,不占用node计算资源和性能
  2. 网络延时小

缺点:

  1. pod创建速度慢。pause容器的创建:kubelet需要协调硬件
  2. 实现pod与数据链路层直接连接而不经过节点ip层的Underlay插件,不支持service服务发现

一般应用于对网络性能容忍度较低的计算场景

 

你可能感兴趣的:(kubernetes_中阶)