在集群搭建之前,需要根据集群的部署环境的限制和应用需求对CNI插件进行选择
以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
常见插件有:flannel、Calico、Weave Net、midonet、Contiv和公有云厂商提供的CNI插件如 Amazon VPC、Aliyun Terway
如私有云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广播可以看出三点:
总结:跨Hypervisor的vm之间存在数据链路层通信限制
选择Overlay插件:
优点:
缺点:
限制较少,可以选择Underlay插件:Calica-bgp,flannel-hostgw、sriov
优点:
缺点:
一般应用于对网络性能容忍度较低的计算场景