mirror of
https://github.com/openshift/openshift-docs.git
synced 2026-02-05 21:46:22 +01:00
59 lines
2.5 KiB
Plaintext
59 lines
2.5 KiB
Plaintext
// Module included in the following assemblies:
|
|
//
|
|
// * virt/virtual_machines/vm_networking/virt-attaching-vm-external-network.adoc
|
|
|
|
:_content-type: PROCEDURE
|
|
[id="virt-attaching-vm-additional-network-cli_{context}"]
|
|
= Attaching a virtual machine to an additional network in the CLI
|
|
|
|
Attach a virtual machine to an additional network by adding a bridge interface and specifying a network attachment definition in the virtual machine configuration.
|
|
|
|
This procedure uses a YAML file to demonstrate editing the configuration and applying the updated file to the cluster. You can alternatively use the `oc edit <object> <name>` command to edit an existing virtual machine.
|
|
|
|
.Prerequisites
|
|
|
|
* 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.
|
|
|
|
.Procedure
|
|
|
|
. Create or edit a configuration of a virtual machine that you want to connect to the bridge network.
|
|
. Add the bridge interface to the `spec.template.spec.domain.devices.interfaces` list and the network attachment definition to the `spec.template.spec.networks` list. This example adds a bridge interface called `bridge-net` that connects to the `a-bridge-network` network attachment definition:
|
|
+
|
|
[source,yaml]
|
|
----
|
|
apiVersion: kubevirt.io/v1
|
|
kind: VirtualMachine
|
|
metadata:
|
|
name: <example-vm>
|
|
spec:
|
|
template:
|
|
spec:
|
|
domain:
|
|
devices:
|
|
interfaces:
|
|
- masquerade: {}
|
|
name: <default>
|
|
- bridge: {}
|
|
name: <bridge-net> <1>
|
|
...
|
|
networks:
|
|
- name: <default>
|
|
pod: {}
|
|
- name: <bridge-net> <2>
|
|
multus:
|
|
networkName: <network-namespace>/<a-bridge-network> <3>
|
|
...
|
|
----
|
|
<1> The name of the bridge interface.
|
|
<2> The name of the network. This value must match the `name` value of the corresponding `spec.template.spec.domain.devices.interfaces` entry.
|
|
<3> The name of the network attachment definition, prefixed by the namespace where it exists. The namespace must be either the `default` namespace or the same namespace where the VM is to be created. In this case, `multus` is used. Multus is a cloud network interface (CNI) plug-in that allows multiple CNIs to exist so that a pod or virtual machine can use the interfaces it needs.
|
|
|
|
. Apply the configuration:
|
|
+
|
|
[source,terminal]
|
|
----
|
|
$ oc apply -f <example-vm.yaml>
|
|
----
|
|
|
|
. Optional: If you edited a running virtual machine, you must restart it for the changes to take effect.
|