Configuring IP addresses for virtual machines
You can configure either dynamically or statically provisioned IP addresses for virtual machines.
Prerequisites
The virtual machine can connect to a secondary network
To configure a dynamic IP for the virtual machine, you must have a DHCP server available on the secondary network.
Configuring an IP address for a new virtual machine using cloud-init
You can use cloud-init to configure an IP address when you create a virtual machine. The IP address can be dynamically or statically provisioned.
Procedure
Create a virtual machine configuration and include the cloud-init network details in the
spec.volumes.cloudInitNoCloud.networkData
field of the virtual machine configuration:To configure a dynamic IP, specify the interface name and the
dhcp4
boolean:kind: VirtualMachine
spec:
...
volumes:
- cloudInitNoCloud:
networkData: |
version: 2
ethernets:
eth1: (1)
dhcp4: true (2)
1 The interface name. 2 Uses DHCP to provision an IPv4 address. To configure a static IP, specify the interface name and the IP address:
kind: VirtualMachine
spec:
...
volumes:
- cloudInitNoCloud:
networkData: |
version: 2
ethernets:
eth1: (1)
addresses:
- 10.10.10.14/24 (2)
1 The interface name. 2 The static IP address for the virtual machine.