Automating VMware vCenter with InfraKit

After a brief discussion on Slack it became apparent that a post that details the steps to automate VMware vCenter with InfraKit would be useful.

Building InfraKit

I won’t duplicate the content that already exists on the InfraKit GitHub located Here the only change is around the build of the binaries. Instead of building everything, we will just build the components that we need to automate vCenter.

The steps below are all that are required:

make build/infrakit && \
make build/infrakit-manager && \
make build/infrakit-group-default && \
make build/infrakit-flavor-swarm && \
make build/infrakit-instance-vsphere

Starting InfraKit

We can then start the group and flavour plugins as per normal, however the vSphere plugin requires some additional details in order for it to start successfully, namely the details of the vCenter we’re automating by doing the following:

Environment var

export VCURL=https://user:pass@vcIPAddress/sdk

Plugin flag

./build/infrakit-instance-vsphere --url=https://user:pass@vcIPAddress/sdk

Note: For testing purposes the plugin can be instructed to not delete instances when they’re “Destroyed”, instead these instances will effectively stop being managed by InfraKit and will need deleting manually. This can be accomplished by starting the plugin with the flag --ignoreOnDestroy=true.

Using InfraKit to deploy instances from a VMware template/existing VM

In one of the more recent PRs, support for VMware VM Templates (.vmtx) or existing Virtual Machines to be used as the basis for new VM instances was added. This means that it becomes very straight forward to deploy and maintain an infrastructure using Virtual Machines that have been created through other tools.

Below is a snippet of the JSON that is used to describe the deployment of instances from the use of a Template
"Instance": {
"Plugin": "instance-vsphere",
"Properties": {
"Datacenter" : "Home Lab",
"Datastore" : "vSphereNFS",
"Hostname" : "esxi01.fnnrn.me",
"Template" : "CentOS7-WEB",
"PowerOn" : true
}
}

The "Datacenter" is optional, and is only required in the even that the VMware vCenter cluster contains more than one Datacenter (linked-mode etc.). The new VM instances will be built using the

Using InfraKit to deploy instances from a LinuxKit .iso

In order to build instances using an .iso that has been pushed to VMware vCenter additional details are required, this is because the .iso doesn’t contain any information to describe a Virtual Machine. The plugin has a number of defaults for CPUs/Memory but these can be overridden as shown below, also the ISOPath must be correct for the Datastore that is used.

"Instance": {
"Plugin": "instance-vsphere",
"Properties": {
"Datacenter" : "Home Lab",
"Datastore" : "vSphereNFS",
"Hostname" : "esxi01.fnnrn.me",
"Network" : "HomeNetwork" ,
"Memory" : 512,
"CPUs" : 1,
"ISOPath" : "linuxkit/vSphere.iso",
"PowerOn" : false
}
}

This will create an entirely new Virtual Machine for every instance to the specs detailed in the properties and attach it to the VMware vSwitch/dvSwitch network.

Creating Instances

All instances will be created in a folder that matches the "ID": "InfraKitVMs" they will also be tagged internally so that InfraKit knows which instances it owns. Creating your allocated instances is as simple then as committing your InfraKit JSON:

./infrakit group commit InfraKitVMs.json

At this point the plugin will inspect your configuration, if the configuration has been committed before then the plugin will inspect the current configuration and determine the changes that are required. If the configuration has changed (e.g. Memory allocation has changed), then the plugin will recreate the virtual machines with the updated configuration. If it is just changes to the allocation of VMs then the plugin will determine if VMs need adding or removing and apply the relevant changes.

VMware vCenter

If you move a Virtual Machine from the InfraKit created folder then it will no longer be monitored by InfraKit, it also means that InfraKit will create a new Virtual Machine to replace the one it previously managed. If you drag the Virtual Machine bag to its folder then, the previous Virtual Machine will be deleted as the allocation count will be +1.

VMware vSphere

vSphere doesn’t support the “construct” of folders, therefore all created Virtual Machines will reside in the root with all other Virtual Machines created on that vSphere host.

 

Leave a Reply

Your email address will not be published. Required fields are marked *