I was having a conversation recently about hosting, who we use, why, etc. Those that know me will be unsurpried that I use UKFast to host things, specifically eCloud. The discussion arrived at documentation and why there arent any ‘Getting Started’ guides for eCloud like there are with AWS or DigitalOcean. This is a good question and the simple answer is just because nobody has written any, so Ive decided to dust some cobwebs off my blog and do a series of posts about how I use eCloud starting with this quick “how to get started” guide.
Disclaimer for new visitors to my blog or those unaware, I work for UKFast, but this blog is for my personal thoughts/opinions and Im writing this as a developer using a service not as an employee trying to sell it. Although I do hope by reading it I may pursuade you to give it a try 🙂
As with other cloud hosting platforms, eCloud comes with a selection of services to meet different customers needs, from VMWare based solutions through to Openstack and Ceph. Im going to focus on eCloud Public which is a vmware based public cloud. Im also going to focus on using develpoer tools rather than the GUI provided by MyUKFast as this is how I use eCloud.
Getting an API key
The api and developer tools require an access token, so before going any further you’ll need to create one. There are some instrcutions on how to do this over on the developer website developers.ukfast.io and links to create an account if you dont have one already.
Once you have an api key, export it to your enviroment and we can get started.
export UKF_API_KEY=yourtokengoeshere
Create a virtual machine
Before I jump to how I manage my infrastructure, I just wanted to mention briefly that creating a vm (virtual machine) is as simple as you would expect, a POST request to the api and you can have a vm in a minute or two depending on the spec you request.
curl -H "Authorization:$UKF_API_KEY" -H "Content-Type:application/json" -XPOST https://api.ukfast.io/ecloud/v1/vms -d '{ "environment": "Public", "pod_id":14, "template":"CentOS 8 64-bit", "cpu":1, "ram":1, "hdd":20, "name":"test vm via curl" }'
For those that dont want to curl, there is also a great command-line client what wraps the api’s into an nice easy to use interface.
ukfast ecloud vm create --environment "Public" --pod=14 --template "CentOS 8 64-bit" --cpu 1 --ram 1 --hdd 20 --name "test vm via cli tool"
I highly recommend the cli tool for making quick calls to the api, it also works really well as part of automated scripts where there isnt a need to use the full sdk.
Terraform
Being able to create and manage vm’s via the cli is great for one off devices but not really practicle for managing multiple devices for a project long term, so I use and recommend Terraform so you can manage your infrastructure as code and commit it to your project repo for version control.
There is an eCloud terraform provider on Github for us to use, if you aren’t familier with terraform I would recommend spending a few minutes reading their getting started guide, it focuses on AWS but lets not hold that against them as it can be applied to any provider 🙂
The eCloud provider isnt currently available in the official registry for auto discovery as its currently in a closed beta and not accepting new vendors. So for now we have to pull it in as a custom provider.
Terraform recommend 3rd party plugins live in `~/.terraform.d/plugins
` but you can put it in various locations if more suitable to your setup, I prefer to follow this standard and combine with version constraints to prevent any unexpected issues if a breaking change is released.
Create this user plugin directory if you dont already have it, then download the latest ecloud provider and export the provider into it.
Ensure the provider has the correct version string appended so you can store multiple releases if needed, eg.
terraform-provider-ecloud_v1.2.3
Create a new file in your project called main.tf
, and add a virtual machine resource as below.
provider "ecloud" {
version = "~> 1.2"
api_key = "yourtokengoeshere"
}
resource "ecloud_virtualmachine" "test-vm" {
environment = "Public"
pod_id = 14
name = "test vm via terrafom"
template = "CentOS 8 64-bit"
cpu = 1
ram = 1
disk {
capacity = 20
}
}
Currently the provider requires your key in plain text within the configuration file, so I recommend securing this with ansible-vault or similar tool, this is to be addressed in a future release but for now lets just copy in our key.
sed -i "s/yourtokengoeshere/$UKF_API_KEY/g" main.tf
You can then initialise the provider with: terraform init
Calling terraform plan
will then prepare a plan for the creation of a single vm. if happy, you can then run terraform apply
to build it.
Terrafom will execute the plan and poll the api until the api confirms the state matches your plan. You can rerun your plan as many times as you like and if something doesnt match, it will reapply the plan to bring things back into sync with the plan.
So thats 3 ways you can create a new VM on eCloud Public using the api, there are also SDK’s on Github if you want to create and manage VMs through an appliacation. I’ll cover doing that from PHP in another post.
$ ukfast ecloud vm list
+--------+--------------------------------+-----+--------+--------+----------------+-----------------+----------+--------------+
| ID | NAME | CPU | RAM GB | HDD GB | IP INTERNAL | IP EXTERNAL | STATUS | POWER STATUS |
+--------+--------------------------------+-----+--------+--------+----------------+-----------------+----------+--------------+
| xxxx19 | test vm via curl | 1 | 1 | 20 | | xxx.xxx.xx.107 | Complete | |
| xxxx20 | test vm via cli tool | 1 | 1 | 20 | | xxx.xxx.xx.108 | Complete | |
| xxxx21 | test vm via terrafom | 1 | 1 | 20 | | xxx.xxx.xx.101 | Complete | |
+--------+--------------------------------+-----+--------+--------+----------------+-----------------+----------+--------------+