Dynamic IP address assignment configuration with Whereabouts
The Whereabouts CNI plugin helps the dynamic assignment of an IP address to a secondary network without the use of a DHCP server.
The Whereabouts CNI plugin also supports overlapping IP address ranges and configuration of the same CIDR range multiple times within separate NetworkAttachmentDefinition CRDs. This provides greater flexibility and management capabilities in multitenant environments.
Dynamic IP address configuration parameters
The following table describes the configuration objects for dynamic IP address assignment with Whereabouts:
| Field | Type | Description |
|---|---|---|
|
|
The IPAM address type. The value |
|
|
An IP address and range in CIDR notation. IP addresses are assigned from within this range of addresses. |
|
|
Optional: A list of zero or more IP addresses and ranges in CIDR notation. IP addresses within an excluded address range are not assigned. |
|
|
Optional: Helps ensure that each group or domain of pods gets its own set of IP addresses, even if they share the same range of IP addresses. Setting this field is important for keeping networks separate and organized, notably in multitenant environments. |
Dynamic IP address assignment configuration with Whereabouts that excludes IP address ranges
The following example shows a dynamic address assignment configuration in a NAD file that uses Whereabouts:
{
"ipam": {
"type": "whereabouts",
"range": "192.0.2.192/27",
"exclude": [
"192.0.2.192/30",
"192.0.2.196/32"
]
}
}
Dynamic IP address assignment that uses Whereabouts with overlapping IP address ranges
The following example shows a dynamic IP address assignment that uses overlapping IP address ranges for multitenant networks.
{
"ipam": {
"type": "whereabouts",
"range": "192.0.2.192/29",
"network_name": "example_net_common",
}
}
where:
network_name-
Optional parameter. If set, must match the
network_nameofNetworkAttachmentDefinition 2.
{
"ipam": {
"type": "whereabouts",
"range": "192.0.2.192/24",
"network_name": "example_net_common",
}
}
where:
network_name-
Optional parameter. If set, must match the
network_nameofNetworkAttachmentDefinition 1.
Creating a whereabouts-reconciler daemon set
The Whereabouts reconciler is responsible for managing dynamic IP address assignments for the pods within a cluster by using the Whereabouts IP Address Management (IPAM) solution. The Whereabouts reconciler ensures that each pod gets a unique IP address from the specified IP address range. The Whereabouts reconciler also handles IP address releases when pods are deleted or scaled down.
|
|
You can also use a |
The whereabouts-reconciler daemon set is automatically created when you configure a secondary network through the Cluster Network Operator. The whereabouts-reconciler DaemonSet does not get automatically created when you configure a secondary network from a YAML manifest.
To trigger the deployment of the whereabouts-reconciler daemon set, you must manually create a whereabouts-shim network attachment by editing the Cluster Network Operator custom resource (CR) file.
-
Edit the
Network.operator.openshift.ioCR by running the following command:$ oc edit network.operator.openshift.io cluster -
Include the
additionalNetworkssection shown in this example YAML extract within thespecdefinition of the CR:apiVersion: operator.openshift.io/v1 kind: Network metadata: name: cluster # ... spec: additionalNetworks: - name: whereabouts-shim namespace: default rawCNIConfig: |- { "name": "whereabouts-shim", "cniVersion": "0.3.1", "type": "bridge", "ipam": { "type": "whereabouts" } } type: Raw # ... -
Save the file and exit the text editor.
-
Verify that the
whereabouts-reconcilerdaemon set deployed successfully by running the following command:$ oc get all -n openshift-multus | grep whereabouts-reconcilerpod/whereabouts-reconciler-jnp6g 1/1 Running 0 6s pod/whereabouts-reconciler-k76gg 1/1 Running 0 6s daemonset.apps/whereabouts-reconciler 6 6 6 6 6 kubernetes.io/os=linux 6s
Configuring the Whereabouts IP reconciler schedule
The Whereabouts IPAM CNI plugin runs the IP address reconciler daily. This process cleans up any stranded IP address allocations that might result in exhausting IP addresses and therefore prevent new pods from getting a stranded IP address allocated to them.
Use this procedure to change the frequency at which the IP reconciler runs.
-
You installed the OpenShift CLI (
oc). -
You have access to the cluster as a user with the
cluster-adminrole. -
You have deployed the
whereabouts-reconcilerdaemon set, and thewhereabouts-reconcilerpods are up and running.
-
Run the following command to create a
ConfigMapobject namedwhereabouts-configin theopenshift-multusnamespace with a specific cron expression for the IP reconciler:$ oc create configmap whereabouts-config -n openshift-multus --from-literal=reconciler_cron_expression="*/15 * * * *"This cron expression indicates the IP reconciler runs every 15 minutes. Adjust the expression based on your specific requirements.
The
whereabouts-reconcilerdaemon set can only consume a cron expression pattern that includes five asterisks. Red Hat does not support the sixth asterisk, which is used to denote seconds. -
Retrieve information about resources related to the
whereabouts-reconcilerdaemon set and pods within theopenshift-multusnamespace by running the following command:$ oc get all -n openshift-multus | grep whereabouts-reconcilerpod/whereabouts-reconciler-2p7hw 1/1 Running 0 4m14s pod/whereabouts-reconciler-76jk7 1/1 Running 0 4m14s daemonset.apps/whereabouts-reconciler 6 6 6 6 6 kubernetes.io/os=linux 4m16s -
Run the following command to verify that the
whereabouts-reconcilerpod runs the IP reconciler with the configured interval:$ oc -n openshift-multus logs whereabouts-reconciler-2p7hw2024-02-02T16:33:54Z [debug] event not relevant: "/cron-schedule/..2024_02_02_16_33_54.1375928161": CREATE 2024-02-02T16:33:54Z [debug] event not relevant: "/cron-schedule/..2024_02_02_16_33_54.1375928161": CHMOD 2024-02-02T16:33:54Z [debug] event not relevant: "/cron-schedule/..data_tmp": RENAME 2024-02-02T16:33:54Z [verbose] using expression: */15 * * * * 2024-02-02T16:33:54Z [verbose] configuration updated to file "/cron-schedule/..data". New cron expression: */15 * * * * 2024-02-02T16:33:54Z [verbose] successfully updated CRON configuration id "00c2d1c9-631d-403f-bb86-73ad104a6817" - new cron expression: */15 * * * * 2024-02-02T16:33:54Z [debug] event not relevant: "/cron-schedule/config": CREATE 2024-02-02T16:33:54Z [debug] event not relevant: "/cron-schedule/..2024_02_02_16_26_17.3874177937": REMOVE 2024-02-02T16:45:00Z [verbose] starting reconciler run 2024-02-02T16:45:00Z [debug] NewReconcileLooper - inferred connection data 2024-02-02T16:45:00Z [debug] listing IP pools 2024-02-02T16:45:00Z [debug] no IP addresses to cleanup 2024-02-02T16:45:00Z [verbose] reconciler success
Fast IPAM configuration for the Whereabouts IPAM CNI plugin
Wherabouts is an IP Address Management (IPAM) Container Network Interface (CNI) plugin that assigns IP addresses at a cluster-wide level. Whereabouts does not require a Dynamic Host Configuration Protocol (DHCP) server.
A typical Wherabouts workflow is described as follows:
-
Whereabouts takes an address range in classless inter-domain routing (CIDR) notation, such as
192.168.2.0/24, and assigns IP addresses within that range, such as192.168.2.1to192.168.2.254. -
Whereabouts assigns an IP address, the lowest value address in a CIDR range, to a pod and tracks the IP address in a data store for the lifetime of that pod.
-
When the pod is removed, Whereabouts frees the address from the pod so that the address is available for assignment.
To improve the performance of Whereabouts, especially if nodes in your cluster run a high amount of pods, you can enable the Fast IPAM feature.
|
|
Fast IPAM is a Technology Preview feature only. Technology Preview features are not supported with Red Hat production service level agreements (SLAs) and might not be functionally complete. Red Hat does not recommend using them in production. These features provide early access to upcoming product features, enabling customers to test functionality and provide feedback during the development process. For more information about the support scope of Red Hat Technology Preview features, see Technology Preview Features Support Scope. |
The Fast IPAM feature uses nodeslicepools, which are managed by the Whereabouts Controller, to optimize IP allocation for nodes.
-
You added the
whereabouts-shimconfiguration to theNetwork.operator.openshift.iocustom resource (CR), so that the Cluster Network Operator (CNO) can deploy the Whereabouts Controller. See "Creating a Whereabouts reconciler daemon set". -
For the Fast IPAM feature to work, ensure that the
NetworkAttachmentDefinition(NAD) and the pod exist in the sameopenshift-multusnamespace.
-
Confirm that the Whereabouts Controller is running by entering the following command.
$ oc get pods -n openshift-multus | grep whereabouts-controllerwhereabouts-controller-5cbfd6c475-fr7d7 1/1 Running 0 22s ...If the Whereabouts Controller is not running, the Fast IPAM does not work.
-
Create a NAD file for your cluster and add the Fast IPAM details to the file as demonstrated in the following example configuration:
apiVersion: "k8s.cni.cncf.io/v1" kind: NetworkAttachmentDefinition metadata: name: wb-ipam namespace: openshift-multus spec: config: '{ "cniVersion": "0.3.0", "name": "wb-ipam-cni-name", "type": "bridge", "bridge": "cni0", "ipam": { "type": "whereabouts", "range": "10.5.0.0/20", "node_slice_size": "/24" } }' # ...where:
namespace-
The namespace where CNO deploys the NAD.
name-
The name of the Whereabouts IPAM CNI plugin.
type-
The type of IPAM CNI plugin, such as
whereabouts. range-
The IP address range for the IP pool that the Whereabouts IPAM CNI plugin uses for allocating IP addresses to pods.
node_slice_size-
Sets the slice size of IP addresses available to each node.
-
Add the Whereabouts IPAM CNI plugin annotation details to the YAML file for the pod:
apiVersion: v1 kind: Pod metadata: name: samplepod annotations: k8s.v1.cni.cncf.io/networks: openshift-multus/wb-ipam spec: containers: - name: samplecontainer command: ["/bin/bash", "-c", "trap : TERM INT; sleep infinity & wait"] image: registry.redhat.io/ubi9/ubi-minimal # ...where:
name-
The name of the pod.
k8s.v1.cni.cncf.io/networks-
The annotation details that references the Whereabouts IPAM CNI plugin name that exists in the
openshift-multusnamespace. - name-
The name of the container for the pod.
command-
Defines the entry point for the container and controls the behavior of the container in the Whereabouts IPAM CNI plugin.
-
Apply the NAD file configuration to pods that exist on nodes that run in your cluster:
$ oc create -f <NAD_file_name>.yaml
-
Show the IP address details of the pod by entering the following command:
$ oc describe pod <pod_name>... k8s.v1.cni.cncf.io/network-status: [{ "name": "ovn-kubernetes", "interface": "eth0", "ips": [ "10.128.3.174" ], "mac": "0a:58:0a:80:03:ae", "default": true, "dns": {} },{ "name": "openshift-multus/wb-ipam", "interface": "net1", "ips": [ "10.5.0.1" ], "mac": "1a:04:6f:a4:15:3c", "dns": {} }] k8s.v1.cni.cncf.io/networks: openshift-multus/wb-ipam ... -
Access the pod and confirm its interfaces by entering the following command:
$ oc exec <pod_name> -- ip a... 3: net1@if439: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000 link/ether 1a:04:6f:a4:15:3c brd ff:ff:ff:ff:ff:ff link-netnsid 0 inet 10.5.0.1/20 brd 10.5.15.255 scope global net1 valid_lft forever preferred_lft forever inet6 fe80::1804:6fff:fea4:153c/64 scope link valid_lft forever preferred_lft forever ...where:
inet: Pod is attached to the10.5.0.1IP address on thenet1interface as expected. -
Check that the node selector pool exists in the
openshift-multusnamespace by entering the following command. The expected output shows the name of the node selector pool, such asnodeslicepool, and the creation age in minutes, such as `32m.$ oc get nodeslicepool -n openshift-multusExample outputNAME AGE wb-ipam-cni-name 32m
Creating a configuration for assignment of dual-stack IP addresses dynamically
You can dynamically assign dual-stack IP addresses to a secondary network so that pods can communicate over both IPv4 and IPv6 addresses.
You can configure the following IP address assignment types in the ipRanges parameter:
-
IPv4 addresses
-
IPv6 addresses
-
multiple IP address assignment
-
Set
typetowhereabouts. -
Use
ipRangesto allocate IP addresses as shown in the following example:cniVersion: operator.openshift.io/v1 kind: Network metadata: name: cluster spec: additionalNetworks: - name: whereabouts-shim namespace: default type: Raw rawCNIConfig: |- { "name": "whereabouts-dual-stack", "cniVersion": "0.3.1, "type": "bridge", "ipam": { "type": "whereabouts", "ipRanges": [ {"range": "192.168.10.0/24"}, {"range": "2001:db8::/64"} ] } } -
Attach the secondary network to a pod. For more information, see "Adding a pod to a secondary network".
-
Verify that all IP addresses got assigned to the network interfaces within the network namespace of a pod by entering the following command:
$ oc exec -it <pod_name> -- ip awhere:
<pod_name>-
The name of the pod.