Setting up a Kubernetes lab with Rancher — Part 2 Adding Nodes

Fusion
5 min readApr 8, 2019

--

This is Part Two from, https://medium.com/@svfusion/setting-up-a-kubernetes-lab-with-rancher-part-1-setting-up-the-host-f8bea9c8553

Part Two of the Guide you will;

  • Create a Cluster
  • Create a ETCD Node
  • Create a Control Plane Node
  • Create a Worker Node

Part two, starts here,

Now that you have your host setup and configured, now you are ready to create the nodes and create a cluster.

For this guide, you will need 3 VMs ready.

VM 1 — ectd node (used as a datastore)

VM2 — controller node (used to control the host)

VM3 — worker node (used to run the containers)

Its best practice to keep all roles separate and not running multiple roles on a node.

Use the same process we used in part 1 to install RancherOS. Do not install the host. Instead, use the cloud-config templates below.

. You will also need to edit the cloud-config on each node with a new IP and hostname. You can keep the same ssh key pair if you wish, but it is best practice to generate new ones for each host.

Use this sample config as templates for each node.

Rancher Prepare Node / etcd

Edit the hostname, IP address, DNS servers, and gateway to match your needs. I used rancheretcd-01 for my hostname. I plan on adding more than one for HA down the road. Also, put your public ssh key. For each node, I’ll add it’s role in the hostname.

#cloud-config-ectd

hostname: rancheretcd-01

rancher:
network:
interfaces:
eth*:
dhcp: false
eth0:
address: 192.168.2.15/24
gateway: 192.168.2.1
dns:
nameservers:
- 192.168.2.1

ssh_authorized_keys:
- ssh-rsa PASTEKEYHERE

Once saved, validate the config,

sudo ros config validate -i cloud-config.yaml

and then run,

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

and choose yes when prompted.

When the install is finished choose yes to reboot,

After the reboot, using the same method but using the IP and ssh key you set for this host, ssh into it.

Create Cluster

Now login to your host using the hostname or IP address you set for the host using a web browser.

Click on Add Cluster.

Choose “From my own existing nodes”, Custom, and give your cluster a name.

See below and choose “Custom” for the cloud provider and click next

Choose the etcd role and then SSH into your VM that you made for your etcd node and copy and paste the command outputted on the page

Hit Enter after you c/p the command

It will then start building the node

Once completed, you will get a message on the Rancher Page that 1 new node registered.

Click Done on the webpage. You will now see your cluster to start provisioning. Before the cluster can be complete, we need to add a control plane node and a worker node.

Create Control-Plane Node

To add the controller plane and worker nodes, use the same process for installing RancherOS on the VM and use the template above for cloud-config. Make sure you change the hostname and IP for each node. I write down all of this information in a spreadsheet to help keep track.

Once you have the other two VMs stood up with RancherOS, log back into the Rancher Host page, go to clusters, click on the options button, and click edit,

Scroll down to the bottom and select Custom for Cloud Provider. After that choose, “Control Plane” for the node.

Then SSH into the VM that you stood up for the control plane and c/p the command at the bottom of the page.

Once that is complete, you’ll see the node has registered,

Click on Save.

Once you have done that, your cluster will start provisioning,

After a few minutes, your cluster should be setup and ready to add the worker node.

Add Worker Node

To add a worker node, follow the same process you used to add the ectd and control plane nodes. Make sure to edit the cloud-config accordingly and choose worker node when you are ready to add it to the cluster.

Once you see that it has been added to the cluster, click on Save,

It will take a few minutes for the worker node to become active,

When it becomes active, you will see the Dashboard for your cluster,

Your cluster is now setup.

Now that you have completed Part 2, you have done the following,

  • Created ssh keys
  • Created cloud-configs
  • Created a Rancher Host
  • Created a cluster
  • Created a etcd Node
  • Created a control plane node
  • Created a worker node

Now that you have your cluster setup, the next step is to add applications to your cluster. This will be discussed in Part Three. Click here for Part Three

--

--