kind: VirtualMachine
spec:
domain:
devices:
interfaces:
- name: red
masquerade: {} (1)
ports:
- port: 80 (2)
networks:
- name: red
pod: {}
You can use the default Pod network with container-native virtualization. To do so,
you must use the masquerade
binding method. It is the only recommended
binding method for use with the default Pod network. Do not use
masquerade
mode with non-default networks.
For secondary networks, use the |
You can use masquerade mode to hide a virtual machine’s outgoing traffic behind the Pod IP address. Masquerade mode uses Network Address Translation (NAT) to connect virtual machines to the Pod network backend through a Linux bridge.
Enable masquerade mode and allow traffic to enter the virtual machine by editing your virtual machine configuration file.
The virtual machine must be configured to use DHCP to acquire IPv4 addresses. The examples below are configured to use DHCP.
Edit the interfaces
spec of your virtual machine configuration file:
kind: VirtualMachine
spec:
domain:
devices:
interfaces:
- name: red
masquerade: {} (1)
ports:
- port: 80 (2)
networks:
- name: red
pod: {}
1 | Connect using masquerade mode |
2 | Allow incoming traffic on port 80 |
Create the virtual machine:
$ oc create -f <vm-name>.yaml
If you create a virtual machine from the container-native virtualization web console wizard, select the required binding method from the Networking screen.
Name | Description |
---|---|
Create NIC |
Create a new NIC for the virtual machine. |
NIC NAME |
Name for the NIC. |
MAC ADDRESS |
MAC address for the network interface. If a MAC address is not specified, an ephemeral address is generated for the session. |
NETWORK CONFIGURATION |
List of available NetworkAttachmentDefinition objects. |
BINDING METHOD |
List of available binding methods. For the default Pod network, |
PXE NIC |
List of PXE-capable networks. Only visible if |
apiVersion: kubevirt.io/v1alpha3
kind: VirtualMachine
metadata:
name: example-vm
namespace: default
spec:
running: false
template:
spec:
domain:
devices:
disks:
- name: containerdisk
disk:
bus: virtio
- name: cloudinitdisk
disk:
bus: virtio
interfaces:
- masquerade: {}
name: default
resources:
requests:
memory: 1024M
networks:
- name: default
pod: {}
volumes:
- name: containerdisk
containerDisk:
image: kubevirt/fedora-cloud-container-disk-demo
- name: cloudinitdisk
cloudInitNoCloud:
userData: |
#!/bin/bash
echo "fedora" | passwd fedora --stdin
apiVersion: kubevirt.io/v1alpha3
kind: VirtualMachineInstance
metadata:
labels:
special: vmi-windows
name: vmi-windows
spec:
domain:
clock:
timer:
hpet:
present: false
hyperv: {}
pit:
tickPolicy: delay
rtc:
tickPolicy: catchup
utc: {}
cpu:
cores: 2
devices:
disks:
- disk:
bus: sata
name: pvcdisk
interfaces:
- masquerade: {}
model: e1000
name: default
features:
acpi: {}
apic: {}
hyperv:
relaxed: {}
spinlocks:
spinlocks: 8191
vapic: {}
firmware:
uuid: 5d307ca9-b3ef-428c-8861-06e72d69f223
machine:
type: q35
resources:
requests:
memory: 2Gi
networks:
- name: default
pod: {}
terminationGracePeriodSeconds: 0
volumes:
- name: pvcdisk
persistentVolumeClaim:
claimName: disk-windows