Connecting a virtual machine to a Linux bridge network
By default, OpenShift Virtualization is installed with a single, internal pod network.
You can create a Linux bridge network and attach a virtual machine (VM) to the network by performing the following steps:
-
Create a Linux bridge node network configuration policy (NNCP).
-
Create a Linux bridge network attachment definition (NAD) by using the web console or the command line.
-
Configure the VM to recognize the NAD by using the web console or the command line.
Note
OpenShift Virtualization does not support Linux bridge bonding modes 0, 5, and 6. For more information, see Which bonding modes work when used with a bridge that virtual machine guests or containers connect to?.
Creating a Linux bridge NNCP
You can create a NodeNetworkConfigurationPolicy (NNCP) manifest for a Linux bridge network.
-
You have installed the Kubernetes NMState Operator.
-
Create the
NodeNetworkConfigurationPolicymanifest. This example includes sample values that you must replace with your own information.apiVersion: nmstate.io/v1 kind: NodeNetworkConfigurationPolicy metadata: name: br1-eth1-policy spec: desiredState: interfaces: - name: br1 description: Linux bridge with eth1 as a port type: linux-bridge state: up ipv4: enabled: false bridge: options: stp: enabled: false port: - name: eth1-
metadata.namedefines the name of the node network configuration policy. -
spec.desiredState.interfaces.namedefines the name of the new Linux bridge. -
spec.desiredState.interfaces.descriptionis an optional field that can be used to define a human-readable description for the bridge. -
spec.desiredState.interfaces.typedefines the interface type. In this example, the type is a Linux bridge. -
spec.desiredState.interfaces.statedefines the requested state for the interface after creation. -
spec.desiredState.interfaces.ipv4.enableddefines whether the ipv4 protocol is active. Setting this tofalsedisables IPv4 addressing on this bridge. -
spec.desiredState.interfaces.bridge.options.stp.enableddefines whether STP is active. Setting this tofalsedisables STP on this bridge. -
spec.desiredState.interfaces.bridge.port.namedefines the node NIC to which the bridge is attached.Note
To create the NNCP manifest for a Linux bridge using OSA with IBM Z®, you must disable VLAN filtering by the setting the
rx-vlan-filtertofalsein theNodeNetworkConfigurationPolicymanifest.Alternatively, if you have SSH access to the node, you can disable VLAN filtering by running the following command:
$ sudo ethtool -K <osa-interface-name> rx-vlan-filter off
-
Creating a Linux bridge NAD
You can create a Linux bridge network attachment definition (NAD) by using the OpenShift Container Platform web console or command line.
Creating a Linux bridge NAD by using the web console
You can create a network attachment definition (NAD) to provide layer-2 networking to pods and virtual machines by using the OpenShift Container Platform web console.
Warning
Configuring IP address management (IPAM) in a network attachment definition for virtual machines is not supported.
-
In the web console, click Networking → NetworkAttachmentDefinitions.
-
Click Create Network Attachment Definition.
Note
The network attachment definition must be in the same namespace as the pod or virtual machine.
-
Enter a unique Name and optional Description.
-
Select CNV Linux bridge from the Network Type list.
-
Enter the name of the bridge in the Bridge Name field.
-
Optional: If the resource has VLAN IDs configured, enter the ID numbers in the VLAN Tag Number field.
Note
OSA interfaces on IBM Z® do not support VLAN filtering and VLAN-tagged traffic is dropped. Avoid using VLAN-tagged NADs with OSA interfaces.
-
Optional: Select MAC Spoof Check to enable MAC spoof filtering. This feature provides security against a MAC spoofing attack by allowing only a single MAC address to exit the pod.
-
Click Create.
Creating a Linux bridge NAD by using the CLI
You can create a network attachment definition (NAD) to provide layer-2 networking to pods and virtual machines (VMs) by using the command line.
The NAD and the VM must be in the same namespace.
Warning
Configuring IP address management (IPAM) in a network attachment definition for virtual machines is not supported.
-
You have installed the OpenShift CLI (
oc).
-
Add the VM to the
NetworkAttachmentDefinitionconfiguration, as in the following example:apiVersion: "k8s.cni.cncf.io/v1" kind: NetworkAttachmentDefinition metadata: name: bridge-network annotations: k8s.v1.cni.cncf.io/resourceName: bridge.network.kubevirt.io/br1 spec: config: | { "cniVersion": "0.3.1", "name": "bridge-network", "type": "bridge", "bridge": "br1", "macspoofchk": false, "vlan": 100, "disableContainerInterface": true, "preserveDefaultVlan": false }- The name for the
NetworkAttachmentDefinitionobject. - Optional: Annotation key-value pair for node selection for the bridge configured on some nodes. If you add this annotation to your network attachment definition, your virtual machine instances will only run on the nodes that have the defined bridge connected.
- The name for the configuration. It is recommended to match the configuration name to the
namevalue of the network attachment definition. - The actual name of the Container Network Interface (CNI) plugin that provides the network for this network attachment definition. Do not change this field unless you want to use a different CNI.
- The name of the Linux bridge configured on the node. The name should match the interface bridge name defined in the
NodeNetworkConfigurationPolicymanifest. - Optional: A flag to enable the MAC spoof check. When set to
true, you cannot change the MAC address of the pod or guest interface. This attribute allows only a single MAC address to exit the pod, which provides security against a MAC spoofing attack. - Optional: The VLAN tag. No additional VLAN configuration is required on the node network configuration policy.
Note
OSA interfaces on IBM Z® do not support VLAN filtering and VLAN-tagged traffic is dropped. Avoid using VLAN-tagged NADs with OSA interfaces.
- Optional: Indicates whether the VM connects to the bridge through the default VLAN. The default value is
true.
- The name for the
-
Optional: If you want to connect a VM to the native network, configure the Linux bridge
NetworkAttachmentDefinitionmanifest without specifying any VLAN:apiVersion: "k8s.cni.cncf.io/v1" kind: NetworkAttachmentDefinition metadata: name: bridge-network annotations: k8s.v1.cni.cncf.io/resourceName: bridge.network.kubevirt.io/br1 spec: config: | { "cniVersion": "0.3.1", "name": "bridge-network", "type": "bridge", "bridge": "br1", "macspoofchk": false, "disableContainerInterface": true } -
Create the network attachment definition:
$ oc create -f network-attachment-definition.yaml- Where
network-attachment-definition.yamlis the file name of the network attachment definition manifest.
- Where
-
Verify that the network attachment definition was created by running the following command:
$ oc get network-attachment-definition bridge-network
Enabling port isolation for a Linux bridge NAD
You can enable port isolation for a Linux bridge network attachment definition (NAD) so that virtual machines (VMs) or pods that run on the same virtual LAN (VLAN) can operate in isolation from one another.
The Linux bridge NAD creates a virtual bridge, or virtual switch, between network interfaces and the physical network.
Isolating ports in this way can provide enhanced security for VM workloads that run on the same node.
-
For VMs, you configured either a static or dynamic IP address for each VM. See "Configuring IP addresses for virtual machines".
-
You created a Linux bridge NAD by using either the web console or the command-line interface.
-
You have installed the OpenShift CLI (
oc).
-
Edit the Linux bridge NAD by setting
portIsolationtotrue:apiVersion: "k8s.cni.cncf.io/v1" kind: NetworkAttachmentDefinition metadata: name: bridge-network annotations: k8s.v1.cni.cncf.io/resourceName: bridge.network.kubevirt.io/br1 spec: config: | { "cniVersion": "0.3.1", "name": "bridge-network", "type": "bridge", "bridge": "br1", "preserveDefaultVlan": false, "vlan": 100, "disableContainerInterface": false, "portIsolation": true } # ...- The name for the configuration. The name must match the value in the
metadata.nameof the NAD. - The actual name of the Container Network Interface (CNI) plugin that provides the network for this network attachment definition. Do not change this field unless you want to use a different CNI.
- The name of the Linux bridge that is configured on the node. The name must match the interface bridge name defined in the NodeNetworkConfigurationPolicy manifest.
- Enables or disables port isolation on the virtual bridge. Default value is
false. When set totrue, each VM or pod is assigned to an isolated port. The virtual bridge prevents traffic from one isolated port from reaching another isolated port.
- The name for the configuration. The name must match the value in the
-
Apply the configuration:
$ oc apply -f example-vm.yaml -
Optional: If you edited a running virtual machine, you must restart it for the changes to take effect.
Configuring a VM network interface
You can configure a virtual machine (VM) network interface by using the OpenShift Container Platform web console or command line.
Configuring a VM network interface by using the web console
You can configure a network interface for a virtual machine (VM) by using the OpenShift Container Platform web console.
-
You created a network attachment definition for the network.
-
Navigate to Virtualization → VirtualMachines.
-
Click a VM to view the VirtualMachine details page.
-
On the Configuration tab, click the Network interfaces tab.
-
Click Add network interface.
-
Enter the interface name and select the network attachment definition from the Network list.
-
Click Save.
-
Restart or live migrate the VM to apply the changes.
Networking fields
| Name | Description |
|---|---|
Name |
Name for the network interface controller. |
Model |
Indicates the model of the network interface controller. Supported values are e1000e and virtio. For IBM Z® ( |
Network |
List of available network attachment definitions. |
Type |
List of available binding methods. Select the binding method suitable for the network interface:
|
MAC Address |
MAC address for the network interface controller. If a MAC address is not specified, one is assigned automatically. |
Configuring a VM network interface by using the CLI
You can configure a virtual machine (VM) network interface for a bridge network by using the command line.
-
You have installed the OpenShift CLI (
oc). -
Shut down the virtual machine before editing the configuration. If you edit a running virtual machine, you must restart the virtual machine for the changes to take effect.
-
Add the bridge interface and the network attachment definition to the VM configuration as in the following example:
apiVersion: kubevirt.io/v1 kind: VirtualMachine metadata: name: example-vm spec: template: spec: domain: devices: interfaces: - bridge: {} name: bridge-net # ... networks: - name: bridge-net multus: networkName: bridge-networkwhere:
spec.template.spec.domain.devices.interface-
Specifies the name of the bridge interface.
spec.template.spec.networks.name-
Specifies the name of the network. This value must match the
namevalue of the correspondingspec.template.spec.domain.devices.interfacesentry. spec.template.spec.networks.multus.networkName-
Specifies the name of the network attachment definition.
-
Apply the configuration:
$ oc apply -f example-vm.yaml -
Optional: If you edited a running virtual machine, you must restart it for the changes to take effect.
Note
When running OpenShift Virtualization on IBM Z® using OSA, RoCE, or HiperSockets interfaces, you must register the MAC address of the device. For more information, see OSA interface traffic forwarding (IBM documentation).