Using VMware’s Guestinfo Interface to Configure cloud-config on a CoreOS VM

Whilst looking to spin up a new CoreOS VM to run Docker containers in, I noticed that they had added support for configuring cloud-config via VMware’s Guestinfo interface. In short, instead of putting your cloud-config in to an ISO an attaching it to the VM, you can embed it within the VM’s configuration file. To me, this seems like a far cleaner way of configuring CoreOS and potentially far simpler.

Unfortunately, it’s very easy to mess up this approach and it can be difficult to figure out where you’ve gone wrong if you’re not familiar with it, so read carefully! CoreOS’s documentation on this is useful, but not always the most intuitive.

The instructions below were used to use the Guestinfo Interface to pass the cloud-config file to a VM running CoreOS 899.15.0. Hopefully you’ll find them useful if you’re giving this method a try!

Instructions

First of all, download the latest CoreOS Stable OVA from http://stable.release.core-os.net/amd64-usr/current/coreos_production_vmware_ova.ova. Then, using your vSphere client, use the Deploy OVF wizard and follow the steps. Do not opt to have the VM powered on once the wizard completes.

Then, create your cloud-config file as normal. Here’s mine that i’ll be using an an example;

Notably, compared to CoreOS’s documentation on this, your SSH key must be embedded in quotes as above, otherwise it isn’t parsed correctly! I’ll be raising this as an issue with them shortly.

As noted in the documentation, Guestinfo expects the cloud-config data to be encoded using base64, so use base64 -w0 cloud-config && echo  to take your cloud-config file, encode it to base64 and output it to your terminal. For example;

Now we need to edit the VM’s configuration file to set the relevant configuration parameters. If you’re using a vSphere ESXi server like me, SSH to the CLI and use vi /vmfs/volumes/DATASTORE/VMNAME/VMNAME.vmx to edit the file. Jump to the bottom of the file and add the following lines;

The first line is our base64 encoded cloud-config file and the second line tells CoreOS that the configuration data is encoded in base64 (as it is possible to pass the data in a number of other formats). Save the configuration file and quit.

After editing the VM’s configuration, we need to inform vSphere that the file has changed and that it should reload it. From the ESXi’s server CLI again, run the command vim-cmd vmsvc/getallvms  . Find the name of your VM in the list and note down its Vmid. Then, run the command  vim-cmd vmsvc/reload Vmid, replacing Vmid with the Vmid from the previous command. As a word of warning, do not edit the VM’s configuration file or reload the VM’s configuration while the VM is powered on, as your changes will likely be overwritten. You must do these steps with the VM powered off.

Success! CoreOS has read our cloud-config data and set the hostname correctly.

Success! CoreOS has read our cloud-config data and set the hostname correctly.

Finally, power on the VM and watch the console output. If successful, the VM should boot and at the login screen the hostname you supplied in your cloud-config file should be visible instead of the default ‘localhost’ hostname. Try connecting over SSH to the IP displayed on the console and logging in using the username core. If the cloud-config file was loaded successfully (and you have your SSH key loaded locally), you should be able to connect to CoreOS’s CLI.

Troubleshooting

As mentioned earlier, it’s easy to make a mistake using this method and CoreOS isn’t exactly helpful at telling you what went wrong – at first!

Bypassing the CoreOS Login

In order to troubleshoot why the cloud-config configuration isn’t being loaded, we first need to get in to CoreOS’s CLI. Of course, without a working cloud-config configuration this usually wouldn’t be possible. Like all good Linux systems though, it’s possible to bypass the login locally when booting up!

Reboot the VM, and as soon as the GRUB bootloader is displayed, quickly press e to edit the bootloader – you will need to be very quick as GRUB will timeout after about a second and continue booting as usual. Once in the bootloader, move down to the 4th line and append  coreos.autologin . If done correctly, it should look similar to the screenshot below;

A correctly altered kernel boot parameter for enabling automatic login.

A correctly altered kernel boot parameter for enabling automatic login.

Once edited, press F10 to continue booting. This time, the login will be bypassed and you’ll be dumped at the standard CoreOS CLI. Note that this will only work locally – you won’t be able to login over SSH.

Checking that the Guestinfo parameters have been set

To check that the Guestinfo has been correctly set in the VM’s configuration file and read by the hypervisor, run the following commands to show the contents of the various Guestinfo configuration parameters;

If the parameters have been set correctly, you should see the exact same data as you set in the VM’s configuration file. If they differ or if the command returns “No value found”, shut down the VM, edit the VM’s configuration file again and check that both  guestinfo.coreos.config.data  and  guestinfo.coreos.config.data.encoding  have been set correctly and then reload the VM’s configuration. Then, power on the VM and try again.

Manually running the cloud-config configuration

From the CoreOS CLI, run  coreos-cloudinit --from-vmware-guestinfo . This will pull the Guestinfo configuration from the hypervisor and try to parse it – this is a great way to discover if you’ve made an error in your cloud-config file or the encoding of it. If the data is all correct, you should see the following lines;

If the data has an error in it, you should see a message with the error along with which line of your cloud-config file caused the error. You can also try using CoreOS’s cloud-config validator tool to check the validity of your cloud-config configuration.

You may also like...

3 Responses

  1. BOK says:

    FYI This information was useful. To me. 🙂
    Thank you!

  2. KingJ says:

    Glad to hear you found it useful!

  1. April 22, 2017

    […] I use VMware for my CoreOS Container Linux nodes, and successfully use VMware’s Guestinfo interface to supply Cloud Config, I was unable to successfully supply the Ignition configuration to the VM using this method. […]

Leave a Reply

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