Antrea IPAM Capabilities

Running NodeIPAM within Antrea Controller

NodeIPAM is a Kubernetes component, which manages IP address pool allocation per each Node, when the Node initializes.

On single stack deployments, NodeIPAM allocates a single IPv4 or IPv6 CIDR per Node, while in dual stack deployments, NodeIPAM allocates two CIDRs per each Node: one for each IP family.

NodeIPAM is configured with a CIDR per each family, which it slices into smaller per-Node CIDRs. When a Node is initialized, the CIDRs are set to the podCIDRs attribute of the Node spec.

Antrea NodeIPAM controller can be executed in scenarios where the NodeIPAMController is disabled in kube-controller-manager.

Note that running Antrea NodeIPAM while NodeIPAMController runs within kube-controller-manager would cause conflicts and result in an unstable behavior.

Configuration

Antrea Controller NodeIPAM configuration items are grouped under nodeIPAM dictionary key.

NodeIPAM dictionary contains the following items:

  • enableNodeIPAM: Enable the integrated NodeIPAM controller within the Antrea controller. Default is false.

  • clusterCIDRs: CIDR ranges for Pods in cluster. String array containing single CIDR range, or multiple ranges. The CIDRs could be either IPv4 or IPv6. At most one CIDR may be specified for each IP family. Example values: [172.100.0.0/16], [172.100.0.0/20, fd00:172:100::/60].

  • serviceCIDR: CIDR range for IPv4 Services in cluster. It is not necessary to specify it when there is no overlap with clusterCIDRs.

  • serviceCIDRv6: CIDR range for IPv6 Services in cluster. It is not necessary to specify it when there is no overlap with clusterCIDRs.

  • nodeCIDRMaskSizeIPv4: Mask size for IPv4 Node CIDR in IPv4 or dual-stack cluster. Valid range is 16 to 30. Default is 24.

  • nodeCIDRMaskSizeIPv6: Mask size for IPv6 Node CIDR in IPv6 or dual-stack cluster. Valid range is 64 to 126. Default is 64.

To enable NodeIPAM, you need to enable the NodeIPAM feature gate for antrea-controller with necessary configurations. Below is a sample of needed changes in the Antrea deployment YAML:

  1. antrea-controller.conf: |
  2. ...
  3. featureGates:
  4. NodeIPAM: true
  5. nodeIPAM:
  6. enableNodeIPAM: true
  7. clusterCIDRs: [172.100.0.0/16]
  8. ...

Antrea Flexible IPAM

Antrea supports flexible control over Pod IP addressing since version 1.4. Pod IP addresses can be allocated from an IPPool. When a Pod’s IP is allocated from an IPPool, the traffic from the Pod to Pods on another Node or to external network will be sent to the underlay network through the Node’s transport network interface, and will be forwarded/routed by the underlay network. We also call this forwarding mode bridging mode.

IPPool CRD defines a desired set of IP ranges and VLANs. An IPPool can be annotated to Namespace, Pod and PodTemplate of StatefulSet/Deployment. Then Antrea will manage IP address assignment for corresponding Pods according to IPPool spec. Note that the IP pool annotation cannot be updated or deleted without recreating the resource. An IPPool can be extended, but cannot be shrunk if already assigned to a resource. The IP ranges of IPPools must not overlap, otherwise it would lead to undefined behavior.

Regular Subnet per Node IPAM will continue to be used for resources without the IPPool annotation, or when the AntreaIPAM feature is disabled.

Usage

Enable AntreaIPAM feature gate and bridging mode

To enable flexible IPAM, you need to enable the AntreaIPAM feature gate for both antrea-controller and antrea-agent, and set the enableBridgingMode configuration parameter of antrea-agent to true. The needed changes in the Antrea deployment YAML are:

  1. antrea-controller.conf: |
  2. ...
  3. featureGates:
  4. AntreaIPAM: true
  5. ...
  6. antrea-agent.conf: |
  7. ...
  8. featureGates:
  9. AntreaIPAM: true
  10. ...
  11. enableBridgingMode: true
  12. ...

Create IPPool CR

The following example YAML manifest creates an IPPool CR.

  1. apiVersion: "crd.antrea.io/v1alpha2"
  2. kind: IPPool
  3. metadata:
  4. name: pool1
  5. spec:
  6. ipVersion: 4
  7. ipRanges:
  8. - start: "10.2.0.12"
  9. end: "10.2.0.20"
  10. gateway: "10.2.0.1"
  11. prefixLength: 24
  12. vlan: 2 # Default is 0 (untagged). Valid value is 0~4095.

IPPool Annotations on Namespace

The following example YAML manifest creates a Namespace to allocate Pod IPs from the IP pool.

  1. kind: Namespace
  2. metadata:
  3. annotations:
  4. ipam.antrea.io/ippools: 'pool1'
  5. ...

IPPool Annotations on Pod (available since Antrea 1.5)

Since Antrea 1.5, Pod IPPool annotation is supported and has a higher priority than the Namespace IPPool annotation. This annotation can be added to PodTemplate of a controller resource such as StatefulSet and Deployment.

Pod IP annotation is supported for a single Pod to specify a fixed IP for the Pod.

Examples of annotations on a Pod or PodTemplate:

  1. kind: StatefulSet
  2. spec:
  3. replicas: 1 # Do not increase replicas if there is pod-ips annotation in PodTemplate
  4. template:
  5. metadata:
  6. annotations:
  7. ipam.antrea.io/ippools: 'sts-ip-pool1' # This annotation will be set automatically on all Pods managed by this resource
  8. ipam.antrea.io/pod-ips: '<ip-in-sts-ip-pool1>'
  9. ...
  1. kind: StatefulSet
  2. spec:
  3. replicas: 4
  4. template:
  5. metadata:
  6. annotations:
  7. ipam.antrea.io/ippools: 'sts-ip-pool1' # This annotation will be set automatically on all Pods managed by this resource
  8. # Do not add pod-ips annotation to PodTemplate if there is more than 1 replica
  9. ...
  1. kind: Pod
  2. metadata:
  3. annotations:
  4. ipam.antrea.io/ippools: 'pod-ip-pool1'
  5. ...
  1. kind: Pod
  2. metadata:
  3. annotations:
  4. ipam.antrea.io/ippools: 'pod-ip-pool1'
  5. ipam.antrea.io/pod-ips: '<ip-in-pod-ip-pool1>'
  6. ...
  1. kind: Pod
  2. metadata:
  3. annotations:
  4. ipam.antrea.io/pod-ips: '<ip-in-namespace-pool>'
  5. ...

Persistent IP for StatefulSet Pod (available since Antrea 1.5)

A StatefulSet Pod’s IP will be kept after Pod restarts, when the IP is allocated from the annotated IPPool.

Data path behaviors

When AntreaIPAM is enabled, antrea-agent will connect the Node’s network interface to the OVS bridge at startup, and it will detach the interface from the OVS bridge and restore its configurations at exit. Node may lose network connection when antrea-agent or OVS daemons are stopped unexpectedly, which can be recovered by rebooting the Node. AntreaIPAM Pods’ traffic will not be routed by local Node’s network stack.

Traffic from AntreaIPAM Pods without VLAN, regular Subnet per Node IPAM Pods, and K8s Nodes is recognized as VLAN 0 (untagged).

Traffic to a local Pod in the Pod’s VLAN will be sent to the Pod’s OVS port directly, after the destination MAC is rewritten to the Pod’s MAC address. This includes AntreaIPAM Pods and regular Subnet per Node IPAM Pods, even when they are not in the same subnet. Traffic to a Pod in different VLAN will be sent to the underlay network, where the underlay router will route the traffic to the destination VLAN.

Requirements for this Feature

As of now, this feature is supported on Linux Nodes, with IPv4, system OVS datapath type, and noEncap, noSNAT traffic mode.

The IPs in the IPPools without VLAN must be in the same underlay subnet as the Node IP, because inter-Node traffic of AntreaIPAM Pods is forwarded by the Node network. IPPools with VLAN must not overlap with other network subnets, and the underlay network router should provide the network connectivity for these VLANs. Only a single IP pool can be included in the Namespace annotation. In the future, annotation of up to two pools for IPv4 and IPv6 respectively will be supported.

IPAM for Secondary Network

With the AntreaIPAM feature, Antrea can allocate IPs for Pod secondary networks. At the moment, AntreaIPAM supports secondary networks managed by Multus, we will add support for secondary networks managed by Antrea in the future.

Prerequisites

The IPAM capability for secondary network was added in Antrea version 1.7. It requires the AntreaIPAM feature gate to be enabled on both antrea-controller and antrea-agent, as AntreaIPAM is still an alpha feature at this moment and is not enabled by default.

CNI IPAM configuration

To configure Antrea IPAM, antrea should be specified as the IPAM plugin in the the CNI IPAM configuration, and at least one Antrea IPPool should be specified in the ippools field. IPs will be allocated from the specified IPPool(s) for the secondary network.

  1. {
  2. "cniVersion": "0.3.0",
  3. "name": "ipv4-net-1",
  4. "type": "macvlan",
  5. "master": "eth0",
  6. "mode": "bridge",
  7. "ipam": {
  8. "type": "antrea",
  9. "ippools": [ "ipv4-pool-1" ]
  10. }
  11. }

Multiple IPPools can be specified to allocate multiple IPs from each IPPool for the secondary network. For example, you can specify one IPPool to allocate an IPv4 address and another IPPool to allocate an IPv6 address in the dual-stack case.

  1. {
  2. "cniVersion": "0.3.0",
  3. "name": "dual-stack-net-1",
  4. "type": "macvlan",
  5. "master": "eth0",
  6. "mode": "bridge",
  7. "ipam": {
  8. "type": "antrea",
  9. "ippools": [ "ipv4-pool-1", "ipv6-pool-1" ]
  10. }
  11. }

Additionally, Antrea IPAM also supports the same configuration of static IP addresses, static routes, and DNS settings, as what is supported by the static IPAM plugin. The following example requests an IP from an IPPool and also specifies two additional static IP addresses. It also includes static routes and DNS settings.

  1. {
  2. "cniVersion": "0.3.0",
  3. "name": "pool-and-static-net-1",
  4. "type": "bridge",
  5. "bridge": "br0"
  6. "ipam": {
  7. "type": "antrea",
  8. "ippools": [ "ipv4-pool-1" ],
  9. "addresses": [
  10. {
  11. "address": "10.10.0.1/24",
  12. "gateway": "10.10.0.254"
  13. },
  14. {
  15. "address": "3ffe:ffff:0:01ff::1/64",
  16. "gateway": "3ffe:ffff:0::1"
  17. }
  18. ],
  19. "routes": [
  20. { "dst": "0.0.0.0/0" },
  21. { "dst": "192.168.0.0/16", "gw": "10.10.5.1" },
  22. { "dst": "3ffe:ffff:0:01ff::1/64" }
  23. ],
  24. "dns": {
  25. "nameservers" : ["8.8.8.8"],
  26. "domain": "example.com",
  27. "search": [ "example.com" ]
  28. }
  29. }
  30. }

The CNI IPAM configuration can include only static addresses without IPPools, if only static IP addresses are needed.

Configuration with NetworkAttachmentDefinition CRD

CNI and IPAM configuration of a secondary network is typically defined with the NetworkAttachmentDefinition CRD. For example:

  1. apiVersion: "k8s.cni.cncf.io/v1"
  2. kind: NetworkAttachmentDefinition
  3. metadata:
  4. name: ipv4-net-1
  5. spec:
  6. {
  7. "cniVersion": "0.3.0",
  8. "type": "macvlan",
  9. "master": "eth0",
  10. "mode": "bridge",
  11. "ipam": {
  12. "type": "antrea",
  13. "ippools": [ "ipv4-pool-1" ]
  14. }
  15. }

IPPool CRD

Antrea IP pools are defined with the IPPool CRD. The following two examples define an IPv4 and an IPv6 IP pool respectively.

  1. apiVersion: "crd.antrea.io/v1alpha2"
  2. kind: IPPool
  3. metadata:
  4. name: ipv4-pool-1
  5. spec:
  6. ipVersion: 4
  7. ipRanges:
  8. - cidr: "10.10.1.0/26"
  9. gateway: "10.10.1.1"
  10. prefixLength: 24
  1. apiVersion: "crd.antrea.io/v1alpha2"
  2. kind: IPPool
  3. metadata:
  4. name: ipv6-pool-1
  5. spec:
  6. ipVersion: 6
  7. ipRanges:
  8. - start: "3ffe:ffff:1:01ff::0100"
  9. end: "3ffe:ffff:1:01ff::0200"
  10. gateway: "3ffe:ffff:1:01ff::1"
  11. prefixLength: 64

VLAN ID in the IP range subnet definition of IPPool CRD is not supported for secondary network IPAM.

Secondary Network creation with Multus

To leverage Antrea for secondary network IPAM, Antrea must be used as the CNI for the Pods’ primary network, while the secondary networks are implemented by other CNIs which are managed by Multus. The Antrea + Multus guide talks about how to use Antrea with Multus, including the option of using Antrea IPAM for secondary networks.