kind: VirtualMachine
spec:
# ...
template:
# ...
spec:
volumes:
- cloudInitNoCloud:
networkData: |
version: 2
ethernets:
eth1: (1)
dhcp4: true
You can configure static and dynamic IP addresses for virtual machines.
You can use cloud-init to configure the IP address of a secondary NIC when you create a virtual machine (VM). The IP address can be dynamically or statically provisioned.
If the VM is connected to the pod network, the pod network interface is the default route unless you update it. |
The virtual machine is connected to a secondary network.
You have a DHCP server available on the secondary network to configure a dynamic IP for the virtual machine.
Edit the spec.template.spec.volumes.cloudInitNoCloud.networkData
stanza of the virtual machine configuration:
To configure a dynamic IP address, specify the interface name and enable DHCP:
kind: VirtualMachine
spec:
# ...
template:
# ...
spec:
volumes:
- cloudInitNoCloud:
networkData: |
version: 2
ethernets:
eth1: (1)
dhcp4: true
1 | Specify the interface name. |
To configure a static IP, specify the interface name and the IP address:
kind: VirtualMachine
spec:
# ...
template:
# ...
spec:
volumes:
- cloudInitNoCloud:
networkData: |
version: 2
ethernets:
eth1: (1)
addresses:
- 10.10.10.14/24 (2)
1 | Specify the interface name. |
2 | Specify the static IP address. |