Configuring a host-device network

As a cluster administrator, you can configure an additional network for your cluster by using the host-device Container Network Interface (CNI) plug-in. The plug-in moves the specified network device from the network namespace of the host into the network namespace of the pod.

Creating an additional network attachment with the host-device CNI plug-in

The Cluster Network Operator (CNO) manages additional network definitions. When you specify an additional network to create, the CNO creates the NetworkAttachmentDefinition object automatically.

Do not edit the NetworkAttachmentDefinition objects that the Cluster Network Operator manages. Doing so might disrupt network traffic on your additional network.

Prerequisites

  • Install the OpenShift CLI (oc).

  • Log in as a user with cluster-admin privileges.

Procedure

To create an additional network for your cluster, complete the following steps:

  1. Edit the CNO CR by running the following command:

    1. $ oc edit networks.operator.openshift.io cluster
  2. Modify the CR that you are creating by adding the configuration for the additional network you are creating, as in the following example CR.

    The following YAML configures the host-device CNI plug-in:

    1. apiVersion: operator.openshift.io/v1
    2. kind: Network
    3. metadata:
    4. name: cluster
    5. spec:
    6. additionalNetworks: (1)
    7. - name: test-network-1
    8. namespace: test-1
    9. type: Raw
    10. rawCNIConfig: '{
    11. "cniVersion": "0.3.1",
    12. "name": "test-network-1",
    13. "type": "host-device",
    14. "device": "eth1",
    15. "ipam": {
    16. "type": "static",
    17. "addresses": [
    18. {
    19. "address": "192.168.1.23/24"
    20. }
    21. ]
    22. }
    23. }'
    1Specify the configuration for the additional network attachment definition.
  3. Save your changes and quit the text editor to commit your changes.

  4. Confirm that the CNO created the NetworkAttachmentDefinition object by running the following command. Replace <namespace> with the namespace that you specified when configuring the network attachment. There might be a delay before the CNO creates the object.

    1. $ oc get network-attachment-definitions -n <namespace>

    Example output

    1. NAME AGE
    2. test-network-1 14m

Configuration for host-device

The configuration for an additional network attachment that uses the host-device Container Network Interface (CNI) plug-in is provided in two parts:

  • Cluster Network Operator (CNO) configuration

  • CNI plug-in configuration

The CNO configuration specifies the name for the additional network attachment and the namespace to create the attachment in. The plug-in is configured by a JSON object specified by the rawCNIConfig parameter in the CNO configuration.

The following YAML describes the configuration parameters for the CNO:

Cluster Network Operator YAML configuration

  1. name: <name> (1)
  2. namespace: <namespace> (2)
  3. rawCNIConfig: '{ (3)
  4. ...
  5. }'
  6. type: Raw
1Specify a name for the additional network attachment that you are creating. The name must be unique within the specified namespace.
2Specify the namespace to create the network attachment in. If you do not specify a value, the default namespace is used.
3Specify the CNI plug-in configuration in JSON format, which is based on the following template.
Specify your network device by setting only one of the following parameters: device, hwaddr, kernelpath, or pciBusID.

The following object describes the configuration parameters for the host-device CNI plug-in:

host-device CNI plug-in JSON configuration object

  1. {
  2. "cniVersion": "0.3.1",
  3. "name": "<name>", (1)
  4. "type": "host-device",
  5. "device": "<device>", (2)
  6. "hwaddr": "<hwaddr>", (3)
  7. "kernelpath": "<kernelpath>", (4)
  8. "pciBusID": "<pciBusID>", (5)
  9. "ipam": { (6)
  10. ...
  11. }
  12. }
1Specify the value for the name parameter you provided previously for the CNO configuration.
2Specify the name of the device, such as eth0.
3Specify the device hardware MAC address.
4Specify the Linux kernel device path, such as /sys/devices/pci0000:00/0000:00:1f.6.
5Specify the PCI address of the network device, such as 0000:00:1f.6.
6Specify a configuration object for the ipam CNI plug-in. The plug-in manages IP address assignment for the attachment definition.

host-device configuration example

The following example configures an additional network named hostdev-net:

  1. name: hostdev-net
  2. namespace: work-network
  3. type: Raw
  4. rawCNIConfig: '{ (1)
  5. "cniVersion": "0.3.1",
  6. "name": "work-network",
  7. "type": "host-device",
  8. "device": "eth1",
  9. "ipam": {
  10. "type": "dhcp"
  11. }
  12. }'
1The CNI configuration object is specified as a YAML string.

Configuration for ipam CNI plug-in

The ipam Container Network Interface (CNI) plug-in provides IP address management (IPAM) for other CNI plug-ins.

You can use the following methods for IP address assignment:

  • Static assignment.

  • Dynamic assignment through a DHCP server. The DHCP server you specify must be reachable from the additional network.

  • Dynamic assignment through the Whereabouts IPAM CNI plug-in.

Static IP address assignment configuration

The following JSON describes the configuration for static IP address assignment:

Static assignment configuration

  1. {
  2. "ipam": {
  3. "type": "static",
  4. "addresses": [ (1)
  5. {
  6. "address": "<address>", (2)
  7. "gateway": "<gateway>" (3)
  8. }
  9. ],
  10. "routes": [ (4)
  11. {
  12. "dst": "<dst>", (5)
  13. "gw": "<gw>" (6)
  14. }
  15. ],
  16. "dns": { (7)
  17. "nameservers": ["<nameserver>"], (8)
  18. "domain": "<domain>", (9)
  19. "search": ["<search_domain>"] (10)
  20. }
  21. }
  22. }
1An array describing IP addresses to assign to the virtual interface. Both IPv4 and IPv6 IP addresses are supported.
2An IP address and network prefix that you specify. For example, if you specify 10.10.21.10/24, then the additional network is assigned an IP address of 10.10.21.10 and the netmask is 255.255.255.0.
3The default gateway to route egress network traffic to.
4An array describing routes to configure inside the pod.
5The IP address range in CIDR format, such as 192.168.17.0/24, or 0.0.0.0/0 for the default route.
6The gateway where network traffic is routed.
7Optional: DNS configuration.
8An of array of one or more IP addresses for to send DNS queries to.
9The default domain to append to a hostname. For example, if the domain is set to example.com, a DNS lookup query for example-host is rewritten as example-host.example.com.
10An array of domain names to append to an unqualified hostname, such as example-host, during a DNS lookup query.

Dynamic IP address assignment configuration

The following JSON describes the configuration for dynamic IP address address assignment with DHCP.

Renewal of DHCP leases

A pod obtains its original DHCP lease when it is created. The lease must be periodically renewed by a minimal DHCP server deployment running on the cluster.

To trigger the deployment of the DHCP server, you must create a shim network attachment by editing the Cluster Network Operator configuration, as in the following example:

Example shim network attachment definition
  1. apiVersion: operator.openshift.io/v1
  2. kind: Network
  3. metadata:
  4. name: cluster
  5. spec:
  6. additionalNetworks:
  7. - name: dhcp-shim
  8. namespace: default
  9. type: Raw
  10. rawCNIConfig: |-
  11. {
  12. name”: dhcp-shim”,
  13. cniVersion”: 0.3.1”,
  14. type”: bridge”,
  15. ipam”: {
  16. type”: dhcp
  17. }
  18. }

DHCP assignment configuration

  1. {
  2. "ipam": {
  3. "type": "dhcp"
  4. }
  5. }

Dynamic IP address assignment configuration with Whereabouts

The Whereabouts CNI plug-in allows the dynamic assignment of an IP address to an additional network without the use of a DHCP server.

The following JSON describes the configuration for dynamic IP address assignment with Whereabouts:

Whereabouts assignment configuration

  1. {
  2. "ipam": {
  3. "type": "whereabouts",
  4. "range": "<range>", (1)
  5. "exclude": ["<exclude_part>, ..."], (2)
  6. }
  7. }
1Specify an IP address and range in CIDR notation. IP addresses are assigned from within this range of addresses.
2Optional: Specify a list of IP addresses and ranges in CIDR notation. IP addresses within an excluded address range are not assigned.

Static IP address assignment configuration example

You can configure ipam for static IP address assignment:

  1. {
  2. "ipam": {
  3. "type": "static",
  4. "addresses": [
  5. {
  6. "address": "191.168.1.7"
  7. }
  8. ]
  9. }
  10. }

Dynamic IP address assignment configuration example using DHCP

You can configure ipam for DHCP:

  1. {
  2. "ipam": {
  3. "type": "dhcp"
  4. }
  5. }

Dynamic IP address assignment configuration example using Whereabouts

You can configure ipam to use Whereabouts:

  1. {
  2. "ipam": {
  3. "type": "whereabouts",
  4. "range": "192.0.2.192/27",
  5. "exclude": [
  6. "192.0.2.192/30",
  7. "192.0.2.196/32"
  8. ]
  9. }
  10. }

Next steps