You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
= Configuring an IP address for a new virtual machine using cloud-init
8
8
9
-
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.
9
+
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.
10
+
11
+
[NOTE]
12
+
====
13
+
If the VM is connected to the pod network, the pod network interface is the default route unless you update it.
14
+
====
15
+
16
+
.Prerequisites
17
+
18
+
* The virtual machine is connected to a secondary network.
19
+
* You have a DHCP server available on the secondary network to configure a dynamic IP for the virtual machine.
10
20
11
21
.Procedure
12
22
13
-
* Create a virtual machine configuration and include the cloud-init network details in the `spec.volumes.cloudInitNoCloud.networkData`field of the virtual machine configuration:
23
+
* Edit the `spec.template.spec.volumes.cloudInitNoCloud.networkData`stanza of the virtual machine configuration:
14
24
15
-
.. To configure a dynamic IP, specify the interface name and the `dhcp4` boolean:
25
+
** To configure a dynamic IP address, specify the interface name and enable DHCP:
16
26
+
17
27
[source,yaml]
18
28
----
19
29
kind: VirtualMachine
20
30
spec:
21
31
# ...
22
-
volumes:
23
-
- cloudInitNoCloud:
24
-
networkData: |
25
-
version: 2
26
-
ethernets:
27
-
eth1: <1>
28
-
dhcp4: true <2>
32
+
template:
33
+
# ...
34
+
spec:
35
+
volumes:
36
+
- cloudInitNoCloud:
37
+
networkData: |
38
+
version: 2
39
+
ethernets:
40
+
eth1: <1>
41
+
dhcp4: true
29
42
----
30
-
<1> The interface name.
31
-
<2> Uses DHCP to provision an IPv4 address.
43
+
<1> Specify the interface name.
32
44
33
-
.. To configure a static IP, specify the interface name and the IP address:
45
+
** To configure a static IP, specify the interface name and the IP address:
34
46
+
35
47
[source,yaml]
36
48
----
37
49
kind: VirtualMachine
38
50
spec:
39
51
# ...
40
-
volumes:
41
-
- cloudInitNoCloud:
42
-
networkData: |
43
-
version: 2
44
-
ethernets:
45
-
eth1: <1>
46
-
addresses:
47
-
- 10.10.10.14/24 <2>
52
+
template:
53
+
# ...
54
+
spec:
55
+
volumes:
56
+
- cloudInitNoCloud:
57
+
networkData: |
58
+
version: 2
59
+
ethernets:
60
+
eth1: <1>
61
+
addresses:
62
+
- 10.10.10.14/24 <2>
48
63
----
49
-
<1> The interface name.
50
-
<2> The static IP address for the virtual machine.
You can configure either dynamically or statically provisioned IP addresses for virtual machines.
10
-
11
-
.Prerequisites
12
-
13
-
* The virtual machine must connect to an xref:../../../virt/virtual_machines/vm_networking/virt-attaching-vm-multiple-networks.adoc#virt-attaching-vm-multiple-networks[external network].
14
-
15
-
* You must have a DHCP server available on the additional network to configure a dynamic IP for the virtual machine.
9
+
You can configure static and dynamic IP addresses for virtual machines.
0 commit comments