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.

Let’s go!

cloud-init

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.

  1. Deploy your ubuntu cloud image (a .ova file in my case)
  2. 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

Done!

Management Service Configuration

This is not entirely as easy as the previous part and takes some keyboard bashing.

  1. Point a DNS to the management service you started in the previous step.
  2. Go to https://<rancher ip/host>
  3. Set a password and chose “I want to create or manage multiple clusters
  4. Accept the license agreement optionally opt out of the data collection
  5. Click Continue
  6. Choose the cluster DNS you created at step 1 and continue
  7. Hover the mouse over Global and click on Global
This image has an empty alt attribute; its file name is image-9.png
  1. Click on Add Cluster
  2. Select vSphere as provider
  3. Give the cluster a name. Please note that this is the cluster that will run your workloads later.
  4. Select a name prefix. I used rancher here.
  5. Select the number of nodes you want to use and make sure that all of the check boxes are green.
  6. Click on Add Node Template
  7. Input the dns/ip of your Vcenter server and the credentials you want rancher to use for managing the nodes.
  8. Click on Create
  9. If the credentials was fine you should now get some details of your Vcenter populated in the Scheduling form.
  10. Configure which data store to use and where to store the VMs
  11. 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
  12. Chose the template you created above.
  13. When done it should look something like this:
  1. 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
  1. Click on Add Network and select which network you want the nodes to operate on.
  2. Add tags if you wish
  3. Click on Create
  4. 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!

Troubleshooting

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.

Related Posts

Leave a Reply

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