flannel网络实验

发布时间 2023-12-08 16:52:58作者: 少年老余

一、部署flannel (注意安装cni)

下载地址:https://github.com/flannel-io/flannel

wget https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml

kubectl apply -f kube-flannel.yml

启动报错:
 Error registering network: failed to acquire lease: node "k8s" pod cidr not assigned
解决:
vim /etc/kubernetes/manifests/kube-controller-manager.yaml
增加参数:
--allocate-node-cidrs=true
--cluster-cidr=10.244.0.0/16
重启kubelet
 
二、三种模式对比
 

ipip多了tunl0隧道,flannel.ipip网卡

vxlan,IP多了个flannel.1

 

1、路由:

host-gw, 直接宿主机网卡路由,发现直接通过物理网卡ens33路由

 ipip,走对方node 宿主机ip入, 从flannel.ipip出

vxlan: pod各网段, 直接互相路由

 

2、traceroute追踪:

相同node:直接互通,无需关注

host-gw,

 ipip,

vxlan,

 

不同node:

host-gw:经过了对方node宿主机ip

ipip:直接到对方pod ip

 

vxlan: 跟ipip一样, 直接到对方pod ip

 

3、ping, tcpdump追踪:

相同node:只经过网桥

host-gw,经过网桥, 不经过宿主网卡

 ipip,只经过网桥

 

vxlan,只经过网桥

 

不同node:

host-gw,

网桥看:

 连接详情:

 

ipip,不经过ens33, 经过网桥和flannel.ipip

 连接详情:

 

vxlan,

不经过ens33, 经过网桥和flannel.1

 

 

 

 

 

 

 

 

 

 

 

 

备注:

为了方便执行命令,直接进入对应容器的namespace下

#找到容器ID,并打印它的NS ID
docker inspect --format "{{.State.Pid}}" dockername
#进入此容器的网络Namespace
nsenter -n -t 43567