Use 192.168.0.0/16 or other iprange as pod cidr for kubernetes + flannel

10/24/2018

In the tutorial https://kubernetes.io/docs/setup/independent/create-cluster-kubeadm/, it says

For flannel to work correctly, you must pass --pod-network-cidr=10.244.0.0/16 to kubeadm init..

How to pass other cidr, e.g., --pod-network-cidr=192.168.0.0/16?

-- Leon
flannel
kubernetes

2 Answers

7/3/2019

Adding on to @Leon's answer

If you want to move your networking from weavenet to flannel the in Step 1 you also need to do sudo ip link del weave

-- garlicFrancium
Source: StackOverflow

10/24/2018

Follow the same steps in the tutorial, except:

(1) After kubeadm reset, clear earlier net interfaces on both master and slave nodes.

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

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

(3) Download the kube-flannel.yml file, change hard coded 10.244.0.0 to 192.168.0.0, then do kubectl create -f kube-flannel.yml.

Test result

$ 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
-- Leon
Source: StackOverflow