6.5. Deploying a container image and creating a RHEL virtual machine in vSphere
After creating a Virtual Machine Disk (VMDK) from a RHEL bootc image by using the bootc-image-builder tool, you can deploy it to VMware vSphere by using the vSphere GUI client. The deployment creates a VM which can be customized further before booting.
Prerequisites
- You created a container image. See Creating QCOW2 images by using bootc-image-builder.
- You pushed the container image to an accessible repository.
You configured the govc VMware CLI tool client. To use the govc VMware CLI tool client, you must set the following values in the environment:
- GOVC_URL
- GOVC_DATACENTER
- GOVC_FOLDER
- GOVC_DATASTORE
- GOVC_RESOURCE_POOL
- GOVC_NETWORK
Procedure
Create a
metadata.yamlfile and add the following information to this file:instance-id: cloud-vm local-hostname: vmnameCreate a
userdata.yamfile and add the following information to the file:#cloud-config users: - name: admin sudo: "ALL=(ALL) NOPASSWD:ALL" ssh_authorized_keys: - ssh-rsa AAA...fhHQ== your.email@example.comssh_authorized_keysis your SSH public key. You can find your SSH public key in~/.ssh/id_rsa.pub.Export the
metadata.yamlanduserdata.yamlfiles to the environment, compressed withgzip, encoded inbase64as follows. You will use these files in further steps.export METADATA=$(gzip -c9 <metadata.yaml | { base64 -w0 2>/dev/null || base64; }) \ USERDATA=$(gzip -c9 <userdata.yaml | { base64 -w0 2>/dev/null || base64; })Launch the image on vSphere with the
metadata.yamlanduserdata.yamlfiles:Import the
.vmdkimage in to vSphere:$ govc import.vmdk ./composer-api.vmdk <_foldername_>Create the VM in vSphere without powering it on:
govc vm.create \ -net.adapter=vmxnet3 \ -m=4096 -c=2 -g=rhel8_64Guest \ -firmware=bios -disk="foldername/composer-api.vmdk” \ -disk.controller=ide -on=false \ vmnameChange the VM to add ExtraConfig variables, the cloud-init config:
govc vm.change -vm vmname \ -e guestinfo.metadata="${METADATA}" \ -e guestinfo.metadata.encoding="gzip+base64" \ -e guestinfo.userdata="${USERDATA}" \ -e guestinfo.userdata.encoding="gzip+base64" .. Power-on the VM: govc vm.power -on vmnameRetrieve the VM IP address:
HOST=$(govc vm.ip vmname)
Verification
Connect to the VM in which you are running the container image. See Connecting to virtual machines for more details.
Use SSH to log in to the VM, using the user-data specified in
cloud-initfile configuration:$ ssh admin@HOST