Little cheat sheet for setting up a single node Kubernetes/Rancher on a developer machine using Hyper-V without tying it to the DHCP IP address that was issued at the time of creation. Setup Rancher on RancherOS
  1. Download the RancherOS Hyper-V ISO image from the GitHub repo
  2. Setup a Hyper-V VM with the bootable ISO set as the boot device (with Internet connectivity - I used 4 vCPU, 16GB RAM and 500GB vHDD)
  3. Boot the VM and allow Linux to boot
  4. Type the following command (uses a password to avoid SSH keys):
    sudo ros install -d /dev/sda --append "rancher.password=yourpassword"
  5. Reboot and skip the CD boot step (i.e. boot from the hard disk)
  6. Login with "rancher" and "yourpassword" - at this point you may wish to get the IP and switch to another SSH client such as PuTTY and login from there.
  7. Create an SSL certificate for your "rancherdev" domain - from your rancher home directory
    docker run -v $PWD/certs:/certs -e SSL_SUBJECT="" paulczar/omgwtfssl
  8. Optionally, you can now delete this container/image from Docker
  9. Run the following command to start Rancher in a Docker container (with persistent storage and custom SSL certificate)
    docker run -d -v /mnt/docker/mysql:/var/lib/mysql -v $PWD/rancher:/var/lib/rancher -v $PWD/certs/cert.pem:/etc/rancher/ssl/cert.pem -v $PWD/certs/key.pem:/etc/rancher/ssl/key.pem -v $PWD/certs/ca.pem:/etc/rancher/ssl/cacerts.pem --restart=unless-stopped -p 8080:80 -p 8443:443 rancher/rancher
  10. In order to internally resolve the custom rancherdev domain in RancherOS, add a loopback record it to the hosts file
    echo "" | sudo tee -a /etc/hosts > /dev/null
  11. Rancher should now be running on the VM's public IP (run "ifconfig" to get your VM IP if you don't have it already)
  12. On your host OS (e.g. Windows) add this IP to the hosts file against "" (c:\windows\system32\drivers\etc\hosts)
  13. Browse to the in your web browser
  14. Follow the wizard to setup password/servername etc. for Rancher
Create a new Kubernetes cluster using Rancher
  1. In the Rancher browser UI - select to add a new cluster
  2. Choose "Custom" and use all the defaults, no cloud provider, [I disabled recurring etcd snapshots in the advanced options since this is a dev setup] - click Next
  3. In the next screen, choose all the Node Roles (etcd, Control Plane, Worker) - expand Advanced options and set the public and internal address to be to ensure the node can survive an external IP change (or another copy running)
  4. Copy the generated Docker command to the clipboard and press Done - it should look something like this:
    sudo docker run -d --privileged --restart=unless-stopped --net=host -v /etc/kubernetes:/etc/kubernetes -v /var/run:/var/run rancher/rancher-agent:v2.1.6 --server --token XXX --ca-checksum XXX --node-name my-dev-node --address --internal-address --etcd --controlplane --worker
  5. Paste and run the command in the RancherOS shell
  6. Rancher should then provision the Kubernetes cluster
NB. Any links generated by the Rancher UI to containers you install will use "" as the URL which is of course wrong from your host OS. You will need to manually enter the URL as Surving an IP Change If you fire up the VM for the first time on another machine or your DHCP recycles and your external IP changes, you will need to follow these steps to get up and running:
  1. Run the VM as normal in Hyper-V
  2. Login via the Hyper-V console with rancher/yourpassword
  3. Get the IP address of the running RancherOS
  4. Update your Windows host file (c:\windows\system32\drivers\etc\hosts) with and entry for pointing to the VM IP
  5. Browse to the rancher URL and give it some time to come back online