For fun I decided to try out Rancher in my VMware lab environment and I did not find any quick and dirty guides so I’ll document my findings here in case it’s helpful to someone else. The goal was to allow rancher to automatically provision nodes in VMWare and create a cluster with a few clicks.
Some gotchas before we start
- You need to have at least a base VMware license. This guide will not work with ESXi free edition.
- I run my VMware lab on version 7. Some things might be different if you run on other versions so keep that in mind if you do.
As usual, if you see something wrong, something that could use improvement or simply leave a thank you note, please do leave a comment.
Table of Contents
Cloud init is a industry standard way of provisioning machines using YAML configs. I’m going to use Ubuntu going forward, but you’re welcome to use your own distribution, at your own risk.
Start by downloading the distribution (.ova) you want to use from https://cloud-images.ubuntu.com/focal/current/. When Rancher deploys new nodes it will use image as a template.
- Deploy your ubuntu cloud image (a .ova file in my case)
- Right click on the provisioned machine and click on Convert to Template
I initially tried Content Library but it failed due to a probable bug so if you are trying that you might want to change to using a template.
Rancher Management Cluster
Start the management cluster
A friend of mine described this as turtle stacking, or more simply put, an external service to manage multiple Kubernetes clusters.
The easy way here is to use docker and create a single node instance of rancher. However, this is not recommended in production. Please follow this guide to setup an HA installation of Rancher instead. Since this is a lab I’ll take the easy way out and create a Rancher instance using docker.
This one is easy as pie and all you need is a machine running docker. The specs needed is really low. Find out more here.
sudo docker run --privileged -d --restart=unless-stopped -p 80:80 -p 443:443 rancher/rancher
Management Service Configuration
This is not entirely as easy as the previous part and takes some keyboard bashing.
- Point a DNS to the management service you started in the previous step.
- Go to https://<rancher ip/host>
- Set a password and chose “I want to create or manage multiple clusters“
- Accept the license agreement optionally opt out of the data collection
- Click Continue
- Choose the cluster DNS you created at step 1 and continue
- Hover the mouse over Global and click on Global
- Click on Add Cluster
- Select vSphere as provider
- Give the cluster a name. Please note that this is the cluster that will run your workloads later.
- Select a name prefix. I used rancher here.
- Select the number of nodes you want to use and make sure that all of the check boxes are green.
- Click on Add Node Template
- Input the dns/ip of your Vcenter server and the credentials you want rancher to use for managing the nodes.
- Click on Create
- If the credentials was fine you should now get some details of your Vcenter populated in the Scheduling form.
- Configure which data store to use and where to store the VMs
- Select the specs you want to use for your nodes in the Instance Options section and then click select Deploy from template: Data Center in the Creation method drop-down
- Chose the template you created above.
- When done it should look something like this:
- Edit the Cloud config section if you want to customize the machine. This seems to be optional depending on the distribution but I added some small things to mine. Use it as a template, or check out the pre-existing cloud-config examples here.
groups: - ubuntu: [root,sys] - cloud-users users: - default - name: myadmin gecos: Patrik Jonsson sudo: ALL=(ALL) NOPASSWD:ALL groups: users, admin ssh_import_id: None lock_passwd: true ssh_authorized_keys: - ssh-ed25519 <public key> manage_resolv_conf: true resolv_conf: nameservers: ['192.168.10.1'] searchdomains: - loadbalancing.se domain: loadbalancing.se options: rotate: true timeout: 1
- Click on Add Network and select which network you want the nodes to operate on.
- Add tags if you wish
- Click on Create
- Click on Create
Now rancher will attempt to create nodes using the template you configured. You can follow the progress by selecting your cluster in the rancher drop-down and clicking on the Nodes menu.
This takes quite a while and might throw some errors along the way but in the end your node list should look something like this:
Well done, you now have a functioning Kubernetes cluster managed by rancher!
Stuck on “Waiting to register with kubernetes”
If the cluster is stuck on this step for too long you might want to verify that the management service DNS is resolvable from the provisioned nodes. See my cloud-init file above for an example of how to set the DNS config and create an admin user account for troubleshooting.
Changing cloud credentials and Node Templates
This was a bit unintuitive for me at least but I suppose if you think of the management service as a portal for multiple users to manage their own cluster it makes sense. Instead of looking under settings, look in your profile at the top right corner to find these settings.