1
0
mirror of https://github.com/openshift/openshift-docs.git synced 2026-02-07 00:48:01 +01:00
Files
openshift-docs/modules/virt-creating-bridge-nad-cli.adoc
Lavanya a152f3d640 This is a combination of 3 commits on Aug 12.
source and output formatting

add source terminal tags

source,terminal tags

peer review
2020-08-17 17:05:59 +00:00

102 lines
2.8 KiB
Plaintext

// Module included in the following assemblies:
//
// * virt/virtual_machines/vm_networking/virt-attaching-vm-multiple-networks.adoc
[id="virt-creating-bridge-nad-cli_{context}"]
= Creating a Linux bridge NetworkAttachmentDefinition in the CLI
As a network administrator, you can configure a NetworkAttachmentDefinition
of type `cnv-bridge` to provide Layer-2 networking to Pods and virtual machines.
[NOTE]
====
The NetworkAttachmentDefinition must be in the same namespace as the Pod or virtual machine.
====
.Procedure
. Create a new file for the NetworkAttachmentDefinition in any local directory.
The file must have the following contents, modified to match your
configuration:
+
[source,yaml]
----
apiVersion: "k8s.cni.cncf.io/v1"
kind: NetworkAttachmentDefinition
metadata:
name: a-bridge-network
annotations:
k8s.v1.cni.cncf.io/resourceName: bridge.network.kubevirt.io/br0 <1>
spec:
config: '{
"cniVersion": "0.3.1",
"name": "a-bridge-network", <2>
"plugins": [
{
"type": "cnv-bridge", <3>
"bridge": "br0" <4>
},
{
"type": "cnv-tuning" <5>
}
]
}'
----
<1> If you add this annotation to your NetworkAttachmentDefinition, your virtual machine instances
will only run on nodes that have the `br0` bridge connected.
<2> Required. A name for the configuration. It is recommended to match the configuration name to the `name` value of the NetworkAttachmentDefinition.
<3> The actual name of the Container Network Interface (CNI) plug-in that provides
the network for this NetworkAttachmentDefinition. Do not change this field unless
you want to use a different CNI.
<4> You must substitute the actual name of the bridge, if it is not `br0`.
<5> Required. This allows the MAC pool manager to assign a unique MAC address to the connection.
+
[source,terminal]
----
$ oc create -f <resource_spec.yaml>
----
. Edit the configuration file of a virtual machine or virtual machine instance that you want to connect to the bridge network, for example:
+
[source,yaml]
----
apiVersion: v1
kind: VirtualMachine
metadata:
name: example-vm
spec:
domain:
devices:
interfaces:
- masquerade: {}
name: default
- bridge: {}
name: bridge-net <1>
...
networks:
- name: default
pod: {}
- name: bridge-net <1>
multus:
networkName: a-bridge-network <2>
...
----
<1> The `name` value for the bridge interface and network must be the same.
<2> You must substitute the actual `name` value from the
NetworkAttachmentDefinition.
+
[NOTE]
====
The virtual machine instance will be connected to both the `default` Pod network and `bridge-net`, which is
defined by a NetworkAttachmentDefinition named `a-bridge-network`.
====
. Apply the configuration file to the resource:
+
[source,terminal]
----
$ oc create -f <local/path/to/network-attachment-definition.yaml>
----