Configuring a macvlan network with basic customizations

As a cluster administrator, you can configure an additional network for your cluster using the macvlan Container Network Interface (CNI) plug-in. When a pod is attached to the network, the plug-in creates a sub-interface from the parent interface on the host. A unique hardware mac address is generated for each sub-device.

The unique MAC addresses this plug-in generates for sub-interfaces might not be compatible with the security polices of your cloud provider.

You specify a basic configuration directly in YAML. This approach offers fewer configuration options than by specifying a macvlan configuration by using a CNI object directly in JSON.

Creating an additional network attachment with the macvlan 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 macvlan 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: SimpleMacvlan
    10. simpleMacvlanConfig:
    11. ipamConfig:
    12. type: static
    13. staticIPAMConfig:
    14. addresses:
    15. - address: 10.1.1.7/24
    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 macvlan CNI plug-in

The following YAML describes the configuration parameters for the macvlan Container Network Interface (CNI) plug-in:

macvlan YAML configuration

  1. name: <name> (1)
  2. namespace: <namespace> (2)
  3. type: SimpleMacvlan
  4. simpleMacvlanConfig:
  5. master: <master> (3)
  6. mode: <mode> (4)
  7. mtu: <mtu> (5)
  8. ipamConfig: (6)
  9. ...
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 a value is not specified, the default namespace is used.
3The ethernet, bonded, or VLAN interface to associate with the virtual interface. If a value for master is not specified, then the host system’s primary ethernet interface is used.
4Configures traffic visibility on the virtual network. Must be either bridge, passthru, private, or vepa. If a value for mode is not provided, the default value is bridge.
5Set the maximum transmission unit (MTU) to the specified value. The default value is automatically set by the kernel.
6Specify a configuration object for the ipam CNI plug-in. The plug-in manages IP address assignment for the attachment definition.

macvlan configuration example

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

  1. name: macvlan-net
  2. namespace: work-network
  3. type: SimpleMacvlan
  4. simpleMacvlanConfig:
  5. ipamConfig:
  6. type: DHCP

Configuration for ipam CNI plug-in

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

The following YAML configuration describes the parameters that you can set.

ipam CNI plug-in YAML configuration object

  1. ipamConfig:
  2. type: <type> (1)
  3. ... (2)
1Specify static to configure the plug-in to manage IP address assignment. Specify DHCP to allow a DHCP server to manage IP address assignment. You cannot specify any additional parameters if you specify a value of DHCP.
2If you set the type parameter to static, then provide the staticIPAMConfig parameter.

Static ipam configuration YAML

The following YAML describes a configuration for static IP address assignment:

Static ipam configuration YAML

  1. ipamConfig:
  2. type: static
  3. staticIPAMConfig:
  4. addresses: (1)
  5. - address: <address> (2)
  6. gateway: <gateway> (3)
  7. routes: (4)
  8. - destination: <destination> (5)
  9. gateway: <gateway> (6)
  10. dns: (7)
  11. nameservers: (8)
  12. - <nameserver>
  13. domain: <domain> (9)
  14. search: (10)
  15. - <search_domain>
1A collection of mappings that define 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.
4A collection of mappings 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: The DNS configuration.
8A collection 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 ipam configuration YAML

The following YAML describes a configuration for static IP address assignment:

Dynamic ipam configuration YAML

  1. ipamConfig:
  2. type: DHCP

Static IP address assignment configuration example

The following example shows an ipam configuration for static IP addresses:

  1. ipamConfig:
  2. type: static
  3. staticIPAMConfig:
  4. addresses:
  5. - address: 198.51.100.11/24
  6. gateway: 198.51.100.10
  7. routes:
  8. - destination: 0.0.0.0/0
  9. gateway: 198.51.100.1
  10. dns:
  11. nameservers:
  12. - 198.51.100.1
  13. - 198.51.100.2
  14. domain: testDNS.example
  15. search:
  16. - testdomain1.example
  17. - testdomain2.example

Dynamic IP address assignment configuration example

The following example shows an ipam configuration for DHCP:

  1. ipamConfig:
  2. type: DHCP

Next steps