Change Kubernetes C...
 
Share:
Notifications
Clear all

[Solved] Change Kubernetes Cluster CIDR subnet for Pods in Microk8s


Brandon Lee
Posts: 486
Admin
Topic starter
(@brandon-lee)
Member
Joined: 15 years ago

If you are running Microk8s and need to change the pod CIDR for Calico after the cluster has been created, below is are the steps you can use to accomplish this. These are the steps that I have taken to fill in the gaps on the official documentation on the Microk8s site:

By default, the pod CIDR is 10.1.0.0/16. This may be fine in your environment. However, if your production LAN is running in a subnet that is contained or overlapped by this /16 subnet, you need to change it since it will cause issues in getting traffic in and out of your cluster.

First, edit your file:

/var/snap/microk8s/current/args/cni-network/cni.yaml

You will want to search for the value "10.1.0.0/16" and change it to the subnet you want to use instead. For instance:

Change "10.1.0.0/16" to "10.100.0.0/16"

Next, edit the file:

 /var/snap/microk8s/current/args/kube-proxy

Change the line:

Change "10.1.0.0/16" to "10.100.0.0/16"

Apply your YAML file with the command:

microk8s kubectl apply -f /var/snap/microk8s/current/args/cni-network/cni.yaml

Next, restart your Microk8s service on all nodes:

sudo snap restart microk8s

Note, if your cluster has already created the default ippools with the other subnet that gets created by default, you will need to delete this configuration. Why? If you don't, the cluster will continue to serve out IPs from this default pool and you won't see your new configuration take effect on new pods spun up. Here are the steps in addition I took to get that done. Note, the commands just copied and pasted from the official documentation didn't work for me in this step. So, here are the correct commands:

microk8s kubectl get ippools.crd.projectcalico.org

microk8s kubectl delete ippool default-ipv4-ippool

microk8s kubectl apply -f /var/snap/microk8s/current/args/cni-network/cni.yaml

After this, restart your deployments, daemon sets, etc. The new pods that are created should be provisioned with the new IP addresses. Hopefully, these steps will help ones struggling with this.