使用192.168.0.0/16或其他iprange作为kubernetes +法兰绒的Pod cidr

时间:2018-10-24 07:22:27

标签: kubernetes flannel

在教程https://kubernetes.io/docs/setup/independent/create-cluster-kubeadm/中,它显示为

  

要使法兰绒正常工作,必须将--pod-network-cidr=10.244.0.0/16传递给kubeadm init.

如何通过其他cidr,例如--pod-network-cidr=192.168.0.0/16

2 个答案:

答案 0 :(得分:1)

遵循本教程中的相同步骤,除了:

(1)在kubeadm reset之后,清除主节点和从节点上的早期网络接口。

sudo ip link del cni0
sudo ip link del flannel.1
sudo systemctl restart network

(2)运行kubeadm init --pod-network-cidr=192.168.0.0/16

(3)下载kube-flannel.yml文件,将硬编码的10.244.0.0更改为192.168.0.0,然后执行kubectl create -f kube-flannel.yml

测试结果

$ k get po -o=wide
NAME                         READY     STATUS    RESTARTS   AGE       IP             NODE
h2-75cb7756c6-r4gkj          1/1       Running   0          5m        192.168.1.14   slave1
h2-75cb7756c6-xfstk          1/1       Running   0          16m       192.168.0.5    master
jobserver-58bf6985f9-77mdd   1/1       Running   0          16m       192.168.0.6    master
jobserver-58bf6985f9-h9hlx   1/1       Running   0          5m        192.168.1.15   slave1

# ping pod on slave
$ ping 192.168.1.14  
PING 192.168.1.14 (192.168.1.14) 56(84) bytes of data.
64 bytes from 192.168.1.14: icmp_seq=1 ttl=63 time=0.454 ms

# ping pod on master
$ ping 192.168.0.5
PING 192.168.0.5 (192.168.0.5) 56(84) bytes of data.
64 bytes from 192.168.0.5: icmp_seq=1 ttl=64 time=0.143 ms

# ping docker container on the same node
$ ping 172.18.0.2    
PING 172.18.0.2 (172.18.0.2): 56 data bytes
64 bytes from 172.18.0.2: seq=0 ttl=241 time=21.580 ms

答案 1 :(得分:0)

添加到@Leon的answer

如果要将网络从weavenet移至flannel,则在步骤1中,还需要进行sudo ip link del weave