Add Rancher Agent from your local OSX using Veertu

Ken Fukuyama
7 min readSep 2, 2017

--

All right, I’ve been investing my time on Rancher recently and it’s so far awesome. When I want to test some features, I like using the try.rancher.com. It’s a managed Rancher Server you can use to TRY Rancher (DON’T USE IT FOR PRODUCTION!!) . Now, because it’s just a Rancher Server, if you want to deploy services to it, you’ll need to add a host to the Rancher Server (the Rancher Agent). It would’ve been awesome if we could just use Docker for Mac and easily add our own Mac as a host temporarily, but things don’t go that easily (at least for the time writing this article). If you can easily spin up a Linux host, it doesn’t really matter but I assume many cannot just easily deploy a Linux for test purposes — I have public cloud resources and a ESXi Hypervisor in my house, but I don’t think this is normal.

So, I think many install some kind of virtualization tool in their local environments (virtualbox, vmware, parallels…) and spin up a Linux VM. One of my colleagues introduced me a tool called Veertu Desktop and it seemed … well … cool. Hence, I’m going to share how I used Veertu to spin up a RancherOS VM and added it to the Rancher Server.

Installing Veertu Desktop

First, let’s go to the website and download the app. After installing it and starting the app, you’ll see a prompt asking to create a new VM.

Unfortunately, we still don’t have the ISO for the RancherOS so let’s download it.

Downloading RancherOS

Head to the RancherOS website and you’ll see the DOWNLOAD RANCHEROS link. It’ll take you to the github releases page. Click on the rancheros.iso link to download the ISO.

Creating the VM

Now that we have the ISO, let’s create the VM in Veertu.

This is how it’s going to look like (the VM Name could be anything). And then let’s select the guest operating system and family.

Choose the desired spec you want the VM to be. For now I’m only giving it 1 core and 1GB of Memory and 20 GB of Storage. Now let’s Launch the VM!

Wait a few minutes and you should see the screen below.

A RancherOS! Easy wasn’t it?? Now, strictly speaking, the actual RancherOS still hasn’t been installed so we need to execute a few more commands.

Installing RancherOS to Disk

Basically, we’re just going to follow the steps in the official docs. But first, let’s make ssh access possible from our local mac. Let’s create a new password for the rancher user.

# create new password
sudo passwd rancher

Now you can access the VM via ssh with the password. The VM’s IP is shown on the top page (in my case 192.168.64.2 ). Let’s ssh into the VM.

# from local mac
ssh rancher@<your vm ip>

You should see something similar to the following:

The authenticity of host '192.168.64.2 (192.168.64.2)' can't be established.
ECDSA key fingerprint is SHA256:/Xj9fTug8vgdBA0/SaAHMiHY4FiDu+JRKljD8ridRpE.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.64.2' (ECDSA) to the list of known hosts.
rancher@192.168.64.2's password:
[rancher@rancher ~]$

and Login should succeed. All right, now let’s create a cloud-config.yml file for the installation.

vi cloud-config.yml

And inside it, paste your public key for ssh connection. This is beyond the scope of this article, so if you don’t know how to find your public key, there are plenty of resources out there.

# something like this on your local mac will show your public key
cat ~/.ssh/id_rsa.pub

Now, the cloud-config.yml is going to be like this:

# cloud-config
ssh_authorized_keys:
- ssh-rsa AAA....

Save the file and hit the installation command for the RancherOS.

sudo ros install -c cloud-config.yml -d /dev/sda

It’s going to look something like this. (answer 2 prompts with y )

[rancher@rancher ~]$ sudo ros install -c cloud-config.yml -d /dev/sda
> INFO[0000] No install type specified...defaulting to generic
Installing from rancher/os:v1.0.4
Continue [y/N]: y
> INFO[0001] start !isoinstallerloaded
> INFO[0001] trying to load /bootiso/rancheros/installer.tar.gz
5bef08742407: Loading layer [==================================================>] 4.221 MB/4.221 MB
209603ef092a: Loading layer [==================================================>] 14.97 MB/14.97 MB
293106d5dba6: Loading layer [==================================================>] 4.608 kB/4.608 kB
8818febd4a42: Loading layer [==================================================>] 18.1 MB/18.1 MB
1fe3b8da456a: Loading layer [==================================================>] 1.645 MB/1.645 MB
c83e7299960b: Loading layer [==================================================>] 1.536 kB/1.536 kB
6e4b2e1174c6: Loading layer [==================================================>] 2.56 kB/2.56 kB
c646d595ced3: Loading layer [==================================================>] 3.072 kB/3.072 kB
> INFO[0005] Loaded images from /bootiso/rancheros/installer.tar.gz
> INFO[0005] starting installer container for rancher/os-installer:latest (new)
Installing from rancher/os-installer:latest
mount: /dev/sr0 is write-protected, mounting read-only
mke2fs 1.43.4 (31-Jan-2017)
Discarding device blocks: done
Creating filesystem with 5242368 4k blocks and 5242880 inodes
Filesystem UUID: ffa63f65-e86b-4de4-bf19-280b024c9c81
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
Continue with reboot [y/N]: y
> INFO[0008] Rebooting
ptime="2017-09-02T14:10:03Z" level=info msg="Setting reboot timeout to 60 (rancher.shutdown_timeout set to 60)"
Ntime="2017-09-02T14:10:04Z" level=info msg="Stopping /docker : e3e6d6198211"
Ktime="2017-09-02T14:10:05Z" level=info msg="Stopping /ntp : df0bc3c64eb5"
Otime="2017-09-02T14:10:05Z" level=info msg="Stopping /network : 22c9edc43542"
Ltime="2017-09-02T14:10:05Z" level=info msg="Stopping /udev : c6c0b7b8e94a"
Ntime="2017-09-02T14:10:05Z" level=info msg="Stopping /syslog : f4bfdad999dc"
Mtime="2017-09-02T14:10:05Z" level=info msg="Stopping /acpid : a6db45070d49"
Ytime="2017-09-02T14:10:05Z" level=info msg="Console Stopping [/console] : dc91669a3f41"
Connection to 192.168.64.2 closed by remote host.
Connection to 192.168.64.2 closed.

Installation to disk is complete! Now if you try to ssh to the same VM, you’re going to see something like this:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
SHA256:10eEBAgFKQrU7DIU9CQ519MuHbKqX5IDb1gVCf76pN8.
Please contact your system administrator.
Add correct host key in /Users/yourusername/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /Users/yourusername/.ssh/known_hosts:69
ECDSA host key for 192.168.64.2 has changed and you have requested strict checking.
Host key verification failed.

This is expected, and you’ll have to remove the row (in my case 192.168.64.2 ) inside ~/.ssh/known_hosts . If you’re doing this sequentially, it will probably be the last row of ~/.ssh/known_hosts . Delete it and save it. And then try connecting to the VM again. And you should succeed!!

Adding the RancherOS to the Rancher Server

We’re getting close! All we have to do is add the RancherOS to the Rancher Server via rancher-agent . Login to the Rancher Server and go to Infrastructure > Hosts > Add Host

Be sure to add your VM’s IP address inside №4 (you’ll need it if you’re going to create multiple VMs inside your local network). Copy the command in №5 and execute inside your RancherOS. After a while, you should see a host added to the Infrastructure like the following capture:

Voila!! We’ve successfully added a RancherOS agent to the Rancher Server!!

Let’s Test It!!

Finally, let’s test if everything is working! Go to the Catalog and lets add a Wordpress stack.

If everything’s working, in a few minutes, you should see all the containers being deployed.

Let’s click the 80/tcp link of the wordpress-lb service.

PERFECT! We have a fully functional Rancher cluster ready! Now let’s start digging deeper with this awesome tool!!

--

--

Ken Fukuyama

Front-end Engineer@CYDAS, Inc. OpenFaaS Contributor. Loves Technologies. IaC, DevOps, Containers, Frontend, Backend, BigData.