Static ip adress for kubernetes pods with calico cni

6/15/2021

I'm currently using 10.222.0.0/16 network for my pods on a single node cluster test environment.

When I reboot the machine or redeploy pods they get the first ip address which has not been used previously. I want to prevent this from happening by assigning static ips for pods with calico.

How can I achieve this?

-- Nyquillus
kubernetes
project-calico

1 Answer

6/22/2021

Generally that approach would be against the dynamic nature of Kubernetes' IP layer. However, there is a solution found in the Project Calico docs:

Choose the IP address for a pod instead of allowing Calico to choose automatically.

Bear in mind that:

You must be using the Calico IPAM.

If you are not sure, ssh to one of your Kubernetes nodes and examine the CNI configuration.

cat /etc/cni/net.d/10-calico.conflist

Look for the entry:

 "ipam": {
      "type": "calico-ipam"
  },

If it is present, you are using the Calico IPAM. If the IPAM is set to something else, or the 10-calico.conflist file does not exist, you cannot use these features in your cluster.

-- WytrzymaƂy Wiktor
Source: StackOverflow