mirror of
https://github.com/openshift/openshift-docs.git
synced 2026-02-07 00:48:01 +01:00
103 lines
2.9 KiB
Plaintext
103 lines
2.9 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 network attachment definition in the CLI
|
|
|
|
As a network administrator, you can configure a network attachment definition
|
|
of type `cnv-bridge` to provide Layer-2 networking to pods and virtual machines.
|
|
|
|
[NOTE]
|
|
====
|
|
The network attachment definition must be in the same namespace as the pod or virtual machine.
|
|
====
|
|
|
|
.Procedure
|
|
|
|
. Create a new file for the network attachment definition 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>
|
|
"vlan": 1 <5>
|
|
},
|
|
{
|
|
"type": "cnv-tuning" <6>
|
|
}
|
|
]
|
|
}'
|
|
----
|
|
<1> If you add this annotation to your network attachment definition, 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 network attachment definition.
|
|
<3> The actual name of the Container Network Interface (CNI) plug-in that provides
|
|
the network for this network attachment definition. 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> Optional: The VLAN tag.
|
|
<6> 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 network attachment definition.
|
|
+
|
|
[NOTE]
|
|
====
|
|
The virtual machine instance will be connected to both the `default` pod network and `bridge-net`, which is
|
|
defined by a network attachment definition named `a-bridge-network`.
|
|
====
|
|
|
|
. Apply the configuration file to the resource:
|
|
+
|
|
[source,terminal]
|
|
----
|
|
$ oc create -f <local/path/to/network-attachment-definition.yaml>
|
|
----
|