Configuring a host-device network
The Cluster Network Operator (CNO) manages additional network definitions. When you specify an additional network to create, the CNO creates the object automatically.
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:
Edit the CNO CR by running the following command:
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:
apiVersion: operator.openshift.io/v1
kind: Network
metadata:
name: cluster
spec:
additionalNetworks: (1)
- name: test-network-1
namespace: test-1
type: Raw
rawCNIConfig: '{
"cniVersion": "0.3.1",
"name": "test-network-1",
"type": "host-device",
"device": "eth1",
"ipam": {
"type": "static",
"addresses": [
{
"address": "192.168.1.23/24"
}
]
}
}'
1 Specify the configuration for the additional network attachment definition. Save your changes and quit the text editor to commit your changes.
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.$ oc get network-attachment-definitions -n <namespace>
test-network-1 14m
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 | Specify a name for the additional network attachment that you are creating. The name must be unique within the specified namespace . |
2 | Specify the namespace to create the network attachment in. If you do not specify a value, the default namespace is used. |
3 | Specify the CNI plug-in configuration in JSON format, which is based on the following template. |
The following object describes the configuration parameters for the host-device CNI plug-in:
host-device CNI plug-in JSON configuration object
{
"cniVersion": "0.3.1",
"name": "<name>", (1)
"type": "host-device",
"device": "<device>", (2)
"kernelpath": "<kernelpath>", (4)
"pciBusID": "<pciBusID>", (5)
"ipam": { (6)
...
}
}
1 | Specify the value for the name parameter you provided previously for the CNO configuration. |
2 | Specify the name of the device, such as eth0 . |
3 | Specify the device hardware MAC address. |
4 | Specify the Linux kernel device path, such as /sys/devices/pci0000:00/0000:00:1f.6 . |
5 | Specify the PCI address of the network device, such as 0000:00:1f.6 . |
6 | Specify 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
:
name: hostdev-net
namespace: work-network
type: Raw
rawCNIConfig: '{ (1)
"cniVersion": "0.3.1",
"name": "work-network",
"type": "host-device",
"device": "eth1",
"ipam": {
"type": "dhcp"
}
}'
1 | The 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 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
{
"ipam": {
"type": "static",
"addresses": [ (1)
{
"address": "<address>", (2)
"gateway": "<gateway>" (3)
}
],
"routes": [ (4)
{
"gw": "<gw>" (6)
}
],
"dns": { (7)
"nameservers": ["<nameserver>"], (8)
"domain": "<domain>", (9)
"search": ["<search_domain>"] (10)
}
}
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 |
DHCP assignment configuration
{
"ipam": {
"type": "dhcp"
}
}
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
{
"ipam": {
"type": "whereabouts",
"range": "<range>", (1)
"exclude": ["<exclude_part>, ..."], (2)
}
}
1 | Specify an IP address and range in CIDR notation. IP addresses are assigned from within this range of addresses. |
2 | Optional: 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:
{
"ipam": {
"type": "static",
"addresses": [
{
"address": "191.168.1.7"
}
]
}
}
Dynamic IP address assignment configuration example using DHCP
You can configure ipam for DHCP:
Dynamic IP address assignment configuration example using Whereabouts
{
"ipam": {
"type": "whereabouts",
"range": "192.0.2.192/27",
"exclude": [
"192.0.2.192/30",
"192.0.2.196/32"
]
}
Next steps
- .