Configure downstream Rancher cluster nodes using vSphere and Cloud-init for RHEL 8

In this post, the idea is to explain how to configure Cloud-init to automatically setup IP of a VM with the operating system RHEL 8 in vSphere. Thanks to this we can when deploy the template VM with Rancher. The article here only makes sense if you are not using DHCP to dynamically allocate VM IPs.

vSphere setup

Rancher have the ability to dynamically allocate IP with the Network Protocol Profiles vSphere. This parameter can be found in the configure panel of the Datacenter. When you create a new pool, you specify the assigned network and list of IPs available for vSphere. vSphere will know which IPs it has not yet distributed or which are not available.

Exemple of an Network Protocol Profiles defined

Cloud-init script

In RHEL 8, network configuration can be made in the directory:
/etc/sysconfig/network-scripts/
So, for example we need to create the file ifcfg-eth0 and new route in route-eth0. To do that, we will using a cloud-init script to get the network information of the VM. The information can be retrieved by the VM using the VMware tools and the vApp variables. open-vm-tools and cloud-init package need to be installed.

This is the script I using to setup network configuration in the VM. The script is launched only on the first boot of the machine. After executed one time, cloud-init don't reexecute the script.

Rancher cluster configuration

In the Rancher Server, we need to configure the Downstream cluster pool node to automatically get an available IP and inject the information in the vApp variables. The correct network need to be selected in the previous form information.

vApp configuration in the Rancher Server console of the vSphere downstream cluster

Finally, when Rancher Server will created a new VM, it will use the Network Protocol Profiles to get an available IP, specify the values in the vApp parameters, so when the VM start Cloud-init can retrieved the informations and setup network interface.
I have described here one possibility to initialise a VM network using the VMware tool and Cloud-init.

Arnaud
me@arfevrier.fr
Rennes, France