Provisioning a K8s Cluster Using Rancher in AWS EC2

In this blog, we’re demonstrating how to use a container tool to create a gossip-based Kubernetes cluster using Rancher (RKE).

The rancher is an enterprise open source tool much like Kubernetes and Swarm container orchestration and it’s very simple to use.

Two steps we will be performing:

  1. Installing Rancher
  2. Creating a k8s cluster using rancher.

Installing Rancher

We have two options available to install Rancher:

  1. Single node installation
  2. High availability installation.

Single Node Installation: Install rancher in single Linux node; this is for development and testing purposes. Click here for more details on Rancher single node installation.

High Availability Installation: Installing and configuring Rancher on a cluster mode for production mode is recommended by Rancher. Click here for more details on Rancher high availability installation.

Here in this article, we will perform a single node installation.

Rancher is a simple Docker container; we just need to spin up the Rancher container.

Note: The above command does not persist the storage; if we want to store the data, add -v /opt/rancher:/var/lib/rancher to the command.

After the container is up and running, you can access the UI on “https” and the first screen will ask you to set password need to set the password for the rancher.

After setting password you will see below page as shown below:

At this point, Rancher setup is done.

Creating K8s Clusters Using Rancher

There are three ways to create clusters:

  1. Rancher UI
  2. Rancher API
  3. Rancher CLI

Here we are going with Rancher UI.

To create a k8s cluster, click on Add Cluster. Here are the options:

Rancher gives you four options to install and configure K8s cluster.

  1. Hosted Kubernetes provider
  2. From nodes in an infrastructure provider.
  3. Import existing K8s cluster.
  4. From my own existing node.

We are going with “From Nodes in an infrastructure provider” with AWS EC2 instance.

Click here for more details on the above options.

Before going with AWS EC2, there are some prerequisite steps need to follow:

  1. Create a policy with EC2 full access rights and assign that policy to a user in AWS IAM.
  2. Add the IAM policy to the permission user.
  3. Generate the AWS security access key pair of above user.

In Rancher, the K8s cluster contains three nodes:

  1. etdc
  2. control panel
  3. worker

etdc: etdc node runs the database; it will store the Kubernetes state in key-value pair. etdc node is very important because every event done in the Kubernetes cluster will store in this node only. So for high availability of this node, Rancher suggests user 1 or 3 or 5 or more nodes.

control panel: control panel node runs Kubernetes Scheduler, API manager and Control manager.

worker: worker node runs kubelets and pods and containers.

Click here for more details on the above nodes.

Setup

We need to configure Node pools as shown below.

Here I am trying to create all the three components in 1 node

Before going forward, we need to add Node Template

Here we need to supply the AWS Access key pair for the Authenticate and Configure node template.

Here I am installing a cluster in the us-west-2 region

In the Instance section, we need to note the instance type and AWS EC2 AMI ID for the particular region which we are installing Kubernetes.

Click on Create to create cluster process. This will take some time to complete the process.

Once that is done, up and running cluster metrics will show as below.

We can launch kubectl command line and execute commands.

Summary

We can create a multi-node Kubernetes cluster using Rancher and scale up and scale down multiple nodes, pods and highly available Kubernetes cluster.

Santosh Rahul Goru

Santosh Rahul Goru works with HCL Technologies as Lead Engineer, working with Docker, kubernetes, Rancher, Ansible, Terraform, Gitlab, Jenkins and other DevOps tools and practices.

Santosh Rahul Goru has 1 posts and counting. See all posts by Santosh Rahul Goru