I used kubeadm
to initialize my K8 master. However, I missed the --pod-network-cidr=10.244.0.0/16
flag to be used with flannel. Is there a way (or a config file) I can modify to reflect this subnet without carrying out the re-init process again?
Asked
Active
Viewed 1.9k times
13

saruftw
- 1,104
- 2
- 14
- 37
-
Edit the generated CNI config files? – coderanger Mar 30 '20 at 22:54
1 Answers
16
Override PodCIDR parameter on the all k8s Node resource with a IP source range 10.244.0.0/16
$ kubectl edit nodes nodename
Replace "Network" field under net-conf.json header in the relevant Flannel ConfigMap with a new network IP range:
$ kubectl edit cm kube-flannel-cfg -n kube-system
net-conf.json: | { "Network": "10.244.0.0/16", "Backend": { "Type": "vxlan" } }
Wipe current CNI network interfaces remaining the old network pool:
$ sudo ip link del cni0; sudo ip link del flannel.1
Re-spawn Flannel and CoreDNS pods respectively:
$ kubectl delete pod --selector=app=flannel -n kube-system
$ kubectl delete pod --selector=k8s-app=kube-dns -n kube-system
Wait until CoreDNS pods obtain IP address from a new network pool. Keep in mind that your custom Pods will still retain the old IP addresses inside containers unless you re-create them manually as well

Arghya Sadhu
- 41,002
- 9
- 78
- 107
-
Attempting to override the `podCIDR` parameter results in the error: `# nodes "(the node name)" was not valid: # * spec.podCIDRs: Forbidden: node updates may not change podCIDR except from "" to valid ` – Earl Ruby Oct 01 '21 at 21:46
-
Great answer. Thank you. In my case, replacing the "Network" field was not necessary. It was already set correctly. – Akito Feb 01 '22 at 21:29
-
The Network section isn't available in Kubernetes 1.21.8, when I run `kubectl edit nodes`. – Trevor Sullivan Feb 28 '22 at 15:09
-
1This will result in duplicate IP addresses. podCIDR should be unique for each node or not set at all. More over, if you use this approach of setting podCIDR you have to do this for every new node manually. – spinkus Mar 20 '22 at 23:31
-
Can you elaborate on the first point. I cannot see the PodCIDR parameter anywhere in the file. TBH I'm happy to re-init with kubeadm but cannot find docs on how to specify --pod-network-cidr on the config file. – Russell Horwood May 07 '22 at 11:36