Create multiple IP pools

Understanding multiple IP pools

By default when you install Calico, a single IPv4 pool is created. This IP pool is used for allocating IP addresses to pods and, if needed, tunnels within your cluster.

Sometimes you may want to configure additional IP pools. For example:

Create multiple IP pools when installing Calico

  • Operator
  • Manifest

You can edit the Installation resource within custom-resources.yaml to include multiple unique IP pools. The following example creates two IP pools assigned to different sets of nodes.

  1. apiVersion: operator.tigera.io/v1
  2. kind: Installation
  3. metadata:
  4. name: default
  5. spec:
  6. calicoNetwork:
  7. ipPools:
  8. - name: pool-zone-1
  9. cidr: 192.168.0.0/24
  10. encapsulation: VXLAN
  11. nodeSelector: "zone == 'zone-1'"
  12. - name: pool-zone-2
  13. cidr: 192.168.1.0/24
  14. encapsulation: VXLAN
  15. nodeSelector: "zone == 'zone-2'"

After installing Calico, you can confirm the IP pools were created by using the following command:

  1. kubectl get ippools

Prevent the operator from managing IP pools

In some cases, you may want to disable IP pool management within the operator and instead use calicoctl or kubectl to create and delete IP pools. To do this, you can edit the Installation resource with custom-resources.yaml to specify an empty list of IP pools.

  1. apiVersion: operator.tigera.io/v1
  2. kind: Installation
  3. metadata:
  4. name: default
  5. spec:
  6. calicoNetwork:
  7. ipPools: []

With this configuration, the operator will wait for you to create IP pools before installing Calico components.

When using manifests to install Calico, you can use calicoctl to manage multiple IP pools. For complete control, you can disable creation of the default IP pool before doing so.

  1. Disable the default IP pool by adding the following environment variable to the calico-node DaemonSet in calico.yaml.

    1. env:
    2. - name: NO_DEFAULT_POOLS
    3. value: "true"
  2. Then, install calico.yaml.

  3. Create the desired IP pools. For example, the following commands create two IP pools assigned to different sets of nodes.

    1. calicoctl create -f -<<EOF
    2. apiVersion: projectcalico.org/v3
    3. kind: IPPool
    4. metadata:
    5. name: pool-zone-1
    6. spec:
    7. cidr: 192.168.0.0/24
    8. vxlanMode: Always
    9. natOutgoing: true
    10. nodeSelector: zone == "zone-1"
    11. EOF
    1. calicoctl create -f -<<EOF
    2. apiVersion: projectcalico.org/v3
    3. kind: IPPool
    4. metadata:
    5. name: pool-zone-2
    6. spec:
    7. cidr: 192.168.1.0/24
    8. vxlanMode: Always
    9. natOutgoing: true
    10. nodeSelector: zone == "zone-2"
    11. EOF