# User Defined Network(s) example [About user-defined networks](https://docs.redhat.com/en/documentation/openshift_container_platform/4.20/html-single/multiple_networks/index#about-user-defined-networks) [Documentation link](https://docs.redhat.com/en/documentation/openshift_container_platform/4.20/html-single/multiple_networks/index#support-matrix-for-udn-nad_understanding-multiple-networks) [Some other work I've done](https://hackmd.io/@johnsimcall/SywaehikZx) with User Defined Networks and Open vSwitch bridge mappings / localnets ## Node-level / Server-level configuration If multiple VLANs are available via OpenShift's main interface (also known as `br-ex`) then you can create a `localnet` mapping to give your VMs access to those VLANs. In the example below I create a bridge-mapping called "trunk" via NNCP, then reference that "trunk" when creating VM networks via UserDefinedNetwork YAML. Note, this can also be done via the Web UI. ```yaml= --- apiVersion: nmstate.io/v1 kind: NodeNetworkConfigurationPolicy metadata: name: br-ex-trunk spec: # nodeSelector: # kubernetes.io/hostname: 'server01.example.com' ### TODO: target Workers desiredState: ovn: bridge-mappings: - localnet: trunk bridge: br-ex state: present ``` ## Creating the VM networks (vSwitches) :::info I prefer this method now because it allows me to share one `localnet` bridge-mapping among many VM networks / VLANs instead of having to create a bridge-mapping for every VLAN. ::: The two examples below use `ClusterUserDefinedNetwork` to create `NetworkAttachmentDefinitions` in the `default` Namespace -- which means they can be used by all VMs. If the network segments need to be created for each `Namespace` / tenant, then `UserDefinedNetworks` should be used - or alter the scope of the `ClusterUserDefinedNetwork's` namespace selector. ### Use the default/native VLAN The YAML below will allow VMs to connect with the OpenShift Nodes' `MachineNetwork` ```yaml= --- apiVersion: k8s.ovn.org/v1 kind: ClusterUserDefinedNetwork metadata: name: native-vlan spec: namespaceSelector: matchExpressions: - key: kubernetes.io/metadata.name operator: In values: - default network: topology: Localnet localnet: physicalNetworkName: trunk role: Secondary ipam: mode: Disabled ``` ### Use a VLAN tag The YAML below will allow VMs to use VLAN 1234 ```yaml= --- apiVersion: k8s.ovn.org/v1 kind: ClusterUserDefinedNetwork metadata: name: vlan-1234 ### CHANGE THIS spec: namespaceSelector: matchExpressions: - key: kubernetes.io/metadata.name operator: In values: - default network: topology: Localnet localnet: physicalNetworkName: trunk role: Secondary ipam: mode: Disabled vlan: mode: Access access: id: 1234 ### CHANGE THIS ```