Connecting a virtual machine to a secondary localnet user-defined network
You can connect a virtual machine (VM) to an OVN-Kubernetes localnet secondary network by using the CLI. Cluster administrators can use the ClusterUserDefinedNetwork (CUDN) custom resource definition (CRD) to create a shared OVN-Kubernetes network across multiple namespaces.
An OVN-Kubernetes secondary network is compatible with the multi-network policy API which provides the MultiNetworkPolicy custom resource definition (CRD) to control traffic flow to and from VMs.
Important
You must use the ipBlock attribute to define network policy ingress and egress rules for specific CIDR blocks. Using pod or namespace selector policy peers is not supported.
A localnet topology connects the secondary network to the physical underlay. This enables both east-west cluster traffic and access to services running outside the cluster, but it requires additional configuration of the underlying Open vSwitch (OVS) system on cluster nodes.
Creating a user-defined-network for localnet topology by using the CLI
You can create a secondary cluster-scoped user-defined-network (CUDN) for the localnet network topology by using the CLI.
-
You are logged in to the cluster as a user with
cluster-adminprivileges. -
You have installed the OpenShift CLI (
oc). -
You installed the Kubernetes NMState Operator.
-
Create a
NodeNetworkConfigurationPolicyobject to map the OVN-Kubernetes secondary network to an Open vSwitch (OVS) bridge.Example
NodeNetworkConfigurationPolicymanifest:apiVersion: nmstate.io/v1 kind: NodeNetworkConfigurationPolicy metadata: name: mapping spec: nodeSelector: node-role.kubernetes.io/worker: '' desiredState: ovn: bridge-mappings: - localnet: localnet1 bridge: br-ex state: present- The name of the configuration object.
- Specifies the nodes to which the node network configuration policy is applied. The recommended node selector value is
node-role.kubernetes.io/worker: ''. - The name of the additional network from which traffic is forwarded to the OVS bridge. This attribute must match the value of the
spec.network.localnet.physicalNetworkNamefield of theClusterUserDefinedNetworkobject that defines the OVN-Kubernetes additional network. This example uses the namelocalnet1. - The name of the OVS bridge on the node. This value is required if the
stateattribute ispresentor not specified. - The state of the mapping. Must be either
presentto add the mapping orabsentto remove the mapping. The default value ispresent.Important
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?.
-
Apply the
NodeNetworkConfigurationPolicymanifest by running the following command:$ oc apply -f <filename>.yamlwhere:
- <filename>
-
Specifies the name of your
NodeNetworkConfigurationPolicymanifest YAML file.
-
Create a
ClusterUserDefinedNetworkobject to create a localnet secondary network.Example
ClusterUserDefinedNetworkmanifest:apiVersion: k8s.ovn.org/v1 kind: ClusterUserDefinedNetwork metadata: name: cudn-localnet spec: namespaceSelector: matchExpressions: - key: kubernetes.io/metadata.name operator: In values: ["red", "blue"] network: topology: Localnet localnet: role: Secondary physicalNetworkName: localnet1 ipam: mode: Disabled # ...- The name of the
ClusterUserDefinedNetworkcustom resource. - The set of namespaces that the cluster UDN applies to. The namespace selector must not point to the following values:
default; anopenshift-*namespace; or any global namespaces that are defined by the Cluster Network Operator (CNO). - The type of selector. In this example, the
matchExpressionsselector selects objects that have the labelkubernetes.io/metadata.namewith the valueredorblue. - The type of operator. Possible values are
In,NotIn, andExists. - The topological configuration of the network. A
Localnettopology connects the logical network to the physical underlay. - Specifies whether the UDN is primary or secondary. The required value is
Secondaryfortopology: Localnet. - The name of the OVN-Kubernetes bridge mapping that is configured on the node. This value must match the
spec.desiredState.ovn.bridge-mappings.localnetfield in theNodeNetworkConfigurationPolicymanifest that you previously created. This ensures that you are bridging to the intended segment of your physical network. - Specifies whether IP address management (IPAM) is enabled or disabled. The required value is
Disabled. OpenShift Virtualization does not support configuring IPAM for virtual machines.
- The name of the
-
Apply the
ClusterUserDefinedNetworkmanifest by running the following command:$ oc apply -f <filename>.yamlwhere:
- <filename>
-
Specifies the name of your
ClusterUserDefinedNetworkmanifest YAML file.
Creating a namespace for secondary user-defined networks by using the CLI
You can create a namespace to be used with an existing secondary cluster-scoped user-defined network (CUDN) by using the CLI.
-
You are logged in to the cluster as a user with
cluster-adminpermissions. -
You have installed the OpenShift CLI (
oc).
-
Create a
Namespaceobject similar to the following example:apiVersion: v1 kind: Namespace metadata: name: red # ... -
Apply the
Namespacemanifest by running the following command:oc apply -f <filename>.yamlwhere:
- <filename>
-
Specifies the name of your
Namespacemanifest YAML file.
Attaching a virtual machine to secondary user-defined networks by using the CLI
You can connect a virtual machine (VM) to multiple secondary cluster-scoped user-defined networks (CUDNs) by configuring the interface binding.
-
You have installed the OpenShift CLI (
oc).
-
Edit the
VirtualMachinemanifest to add the CUDN interface details, as in the following example:apiVersion: kubevirt.io/v1 kind: VirtualMachine metadata: name: example-vm namespace: red spec: template: spec: domain: devices: interfaces: - name: secondary_localnet bridge: {} machine: type: "" resources: requests: memory: 2048M networks: - name: secondary_localnet multus: networkName: <localnet_cudn_name>where:
metadata.namespace-
Specifies the namespace in which the VM is located. This value must match a namespace that is associated with the secondary CUDN.
spec.template.spec.domain.devices.interfaces.name-
Specifies the name of the secondary user-defined network interface.
spec.template.spec.networks.name-
Specifies the name of the network. This value must match the value of the
spec.template.spec.domain.devices.interfaces.namefield. spec.template.spec.networks.multus.networkName-
Specifies the name of the localnet
ClusterUserDefinedNetworkobject that you previously created.
-
Apply the
VirtualMachinemanifest by running the following command:$ oc apply -f <filename>.yamlwhere:
- <filename>
-
Specifies the name of your
VirtualMachinemanifest YAML file.Note
When running OpenShift Virtualization on IBM Z®, be aware that certain network interfaces, such as OSA, RoCE, and HiperSockets, only forward network traffic to devices that are registered with the respective interface. As a result, any traffic that is destined for unregistered devices is not forwarded. For more information, see OSA interface traffic forwarding (IBM documentation).