Prepare CentOS-7 VM Template with cloud-init for vSphere

Prepare CentOS-7 VM Template with cloud-init for vSphere

Introduction

Purpose

Quick overview on how to prepare CentOS-7 VM Template with cloud-init for vSphere.

Objectives

Create CentOS-7 VM Template with cloud-init for vSphere

Prerequisites

  1. vSphere 6.5 or 6.7
  2. govc
  3. curl or wget
  4. qemu-img

Procedure

To download CentOS-7 image in qcow2 format, you can click here.

  1. Download CentOS images in qcow2 format:
wget https://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud.qcow2
# or
curl -L https://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud.qcow2
  1. Convert it to vmdk e.g.
qemu-img convert -O vmdk -o subformat=streamOptimized "CentOS-7-x86_64-GenericCloud.qcow2" "centos-7-cloud-init.vmdk"
  1. Set environment variables for govc (docs). Use the following commands as an example:
export GOVC_URL="vcenter.example.com"
export GOVC_USERNAME="username@example.com"
export GOVC_PASSWORD='password'
export GOVC_INSECURE="true"
export GOVC_DATACENTER="DC1"
export GOVC_DATASTORE="/DC1/datastore/data_store1"
export GOVC_RESOURCE_POOL="/DC1/host/192.168.3.2/Resources"
export GOVC_FOLDER="/DC1/vm/templates"

# useful commands
# show available pools
govc find / -type p
# show available folders
govc find / -type f
# show available datastores
govc find / -type s
  1. Upload vmdk disk to vSphere using GOVC:
govc import.vmdk "centos-7-cloud-init.vmdk"
  1. (Optional) Inflate the created disk (see vmware documentation for more details)
govc datastore.disk.inflate "centos-7-cloud-init/centos-7-cloud-init.vmdk"
  1. Create a new virtual machine using that image with vSphere WebUI.

  2. During the Customize Hardware step:

    1. Remove the disk present by default
    2. Click on ADD NEW DEVICE, select Existing Hard Disk and select the disk previously created.
  3. Increase the boot disk size to 40 GB or more. Default size of 8Gb is too small. (Optional: you can increase the boot disk when you create the k8s cluster)

  4. Convert VM to VM Template.

govc vm.markastemplate ${VM_NAME}
  1. When creating a cluster with this image, open Advanced Options and set Network Interface to eth0 for each node group (including master) using this image.