Rancher : One place for all Kubernetes Clusters

Saiyam Pathak
100daysoflearning
10 min readApr 29, 2019

--

Rancher is open-source software for delivering Kubernetes-as-a-Service.
Day 94–97

Managing kubernetes clusters running in different cloud providers was never an easy task until Rancher came. So what exactly is Rancher , Rancher is an open source platform where you can create the cluster in different clouds or import an existing one as well. Today I will tell you how to spin up a kubernetes cluster in Google cloud, AWS Cloud and how to import a cluster from Oracle Cloud. All these three clusters you will be able to see and manage from one place itself which is nothing but Rancher Dashboard. Rancher have wide variety of tools and the company is coming up with more and more cool open source projects including the k3os.io that they recently launched . I will show you the creation of kubernetes cluster from rancher and how easy monitoring and deployments can be done via Rancher Dashboard.

Apart from Deploying the cluster to different cloud vendors , Rancher in march 2019 launched there own RKE(Rancher Kubernetes Engine) which is an extremely simple, lightning fast Kubernetes installer that works everywhere. So it eliminates the pain of installing the kubernetes cluster on baremetal servers or VM’s and it provides lot of customization flexibility as well.

RKE installation : In this I will explain how to install rancher kuberntes cluster on 3 VM’s. So the first thing you need is three machines which you can use to spin up RKE cluster. I am taking 3 EC2 Instances with ubuntu18.04 as the boot image. So I have a separate VM from where I will be performing all the installations to these three nodes where one will be the master and other two will be worker nodes. I have followed the official documentation for installation but for some steps are tweaked a bit for more easy stuff.
- Step 1: Downloading the RKE binary
wget https://github.com/rancher/rke/releases/download/v0.1.18/rke_linux-amd64
- Step 2: mv rke_linux-amd64 rke
- Step 3: export PATH=/home/cloud_user/rke:$PATH
- Step 4: By this point I already have three ubuntu EC2 machines provisioned with docker installed (make sure you run “usermod -aG docker ubuntu” to make docker accessible by ubuntu user as well) on them and the private key file which I used while creating those instances . What you need to do is in your current VM create a file, copy the contents of the key, change key permissions and try to login to one of your EC2 instance .

As you can see I have also done the same. Now you run the following command :
rke config --name cluster.yml (you can use ./rke if path not set). As soon as you hit enter it will start asking you different parameter values based on which it will create the cluster.yml file. These parameters are basically the nodes characteristics that you define and rke automatically creates cluster.yml for you. You can create that by yourself as well by following the documentation from Rancher.

Above are the parameters I passed and based on that it generated cluster.yml file. Basically its the three nodes configuration and some other cluster related config which I have chosen as default .

Above is how the Node will look like in cluster.yml file based on the parameters we passed. Now that you have the cluster.yml file ready you can move on to the next step.

- Step 5: Run “rke up” to make the cluster up (it assumes that you have a file cluster.yml at same location) or if you have file other than cluster.yml than you can run :
rke up --config abc.yml

THATS IT …!!! You will see the cluster spinning up and displaying various INFO Logs for doing all the work to spin up the cluster and connecting the nodes together. This also lets you see what is happening behind the scenes so that you can feel all the steps for Cluster creation. If not then just look our for “building kubernetes cluster successfully”.

Few Logs

After this rke also creates a kubeconfig file which you can use to interact with the cluster (install kubectl before that) with the name ‘kube_config_cluster_yml’ and if you used any other name for the yml file then it will be ‘kube_config_test_yml’, so you can use this config file to interact with the cluster.

All setup

Rancher Installation : Now I will show you how you can install Rancher and create/import clusters from Rancher Dashboard. I will be using the same VM which I used for RKE installation. I will be running Rancher as a docker container on port 80 .

Command : docker run -d --restart=unless-stopped -p 80:80 -p 443:443 rancher/rancher

DONE..!! Rancher will be up and running now.
Login to Rancher <ipaddress> and set password,URl to use.

Rancher first screen
Rancher Dashboard

Rancher is up and running, ready to create and import clusters. I will show you AWS and Google cloud cluster creation using Rancher and import clusters from Oracle cloud & the recently created RKE.

AWS Cluster Creation using Rancher:

Step1: Click ‘‘add cluster’’ and select Amazon EKS, Once you select you will need to provide cluster name, the Access Key and secret Key .

Step2: Click Configure Cluster and select the kubernetes version & Service Role.

cluster Options

Step3: Click Select VPC & Subnet for choosing the VPC and public ip for nodes .

VPC

Step4: Select the Instance options for specifying the shape and sizes of Nodes.

Nodes

Step5: Create Cluster

Cluster Creation

Once you click create your AWS EKS Cluster will be provisioned and will appear in the AWS dashboard and the Rancher Dashboard.

AWS Cluster created

Google Kubernetes Cluster Creation using Rancher:

Step1: Create a service Account with following permissions in your Google cloud Console.

Service account

Step2: Create JSON Key for that service account and save it on your computer as this key will be needed while creating the cluster via Rancher

JSON key creation

Step3: Go to Rancher Dashboard, click Add cluster and Select Google GKE. Provide the name for the cluster and paste the service account JSON file that you just created in Step2.

Adding Cluster and providing JSON File

Step4: Once you click on Configure Nodes , it will authenticate with the JSON file provided and display different section where you can select cluster options. You can choose the region , kubernetes version , Node count/shape/Image, enable/disable features like auto repair, auto scaling & auto upgrade and click CREATE.

That is it , as soon as you click create you Google Kubernetes cluster will be created .

GKE

Importing RKE Cluster using Rancher:

in this section I will show you how you can import the RKE cluster into Rancher that you just created at the beginning of this post.

Step1: After clicking add cluster select import option , provide the cluster name and click create.

Importing cluster

Step2: Run the commands as mentioned on the next screen to create a cluster-admin role and rancher import yaml.

commands
role creation
applying yaml file to the RKE cluster for rancher import

Importing ORACLE kubernetes Engine into Rancher Dashboard:

OKE Cluster creation , go to you Oracle OCI console, there you go to developer services from the hamburger menu and select clusters. I will choose the quick create option as its very simple and you do not have to do anything else apart from giving the cluster name and node shapes & count.

OKE cluster Creation
Cluster Created

Rancher Dashboard:

Lets see the Rancher Dashboard Now.

All clusters in one place

Now you have variety of different things that you can do with Rancher Dashboard.

Enable monitoring : You can enable prometheus and grafana monitoring using the dashboard itself and access the grafana dashboards for all the clusters. So I will show you how to do for Google Kubernetes cluster and the process is same for all the clusters.

Step1: Select the cluster you want to enable monitoring for.
Step2: Select monitoring from the tools menu.

Select monitoring

Step3: click Enable and set the limits . Click Save

Configure

Once you click save your monitoring is enabled and when you click on the cluster you can see grafana logos .

click on any Grafana Logo and you will be redirected to the Grafana dashboard where you can see all the metrics and create alerts based on need.

Google Kubernetes Engine & Oracle Kubernetes Engine Grafana Dashboards respectively
RKE Grafana Dashboard

PROBLEM 1: Where is the AWS Grafana Dashboard?? So this is some kind of issue going on in rancher I have seen couple of open issues related to this as well(hope it gets resolved) So even after enabling the monitoring from the Rancher Dashboard the grafana logos are not coming anywhere when I click on the amazon cluster. I have tried on of the solutions by opening the ports as well allowing the port 80 traffic but still the same result, not able to access the grafana dashboard. I will also comment on the issue or create a new one in it gets closed (hope it gets resolved soon).

Managing the cluster: You can easily manage all the deployed pods , services etc of the cluster using the Rancher Dashboard.

google GKE pods

here you can edit the yaml files, redeploy them and change the configurations according to need.

Deploying application : Deploying application to your cluster is very simple using the Rancher Dashboard. You just go to the workloads section of the cluster and you can deploy an application.

Deploy

Lets deploy sample nginx application . When you choose deploy you get variety of options to deploy your application.

Deploy application

You can set the Environment variables, do Node Scheduling, health checks, create volumes and define scaling policy as well. There is so much that you can do from a single screen of application deployment (I was like woww..!!) Also you can expose the port (for my deployment I have exposed it as an external load balancer).

deployed application

Executing the kubectl commands: you can execute kubectl commands from the Rancher UI itself with the help of kubectl shell which gets generated while provisioning of the cluster. One problem here is that when you try to run the kubectl shell multiple times it says disconnected due to some docker issues. Other way round is to download the kubeconfig file and run the kubectl commands locally.

You can also add Volumes and create Pipelines

PROBLEM2: I don’t know but its weird problem that I am facing , One I import a cluster it runs fine like I showed above for Oracle and RKE . If I stop and start the server where rancher is running I start getting below error for the imported clusters.

error

I will create an issue for this as well in GitHub , lets see if anyone else also facing the same.

Covering all the Rancher aspects , features and power in one posts is not possible. So that is it for this article where I told you :

  • Rancher Installation
  • Google cloud GKE installation using Rancher
  • RKE setup
  • AWS EKS creation using Rancher
  • Importing Oracle Cloud OKE into Rancher
  • Enabling Monitoring on Clusters from Rancher
  • Deploying sample application and exposing as a load balancer using Rancher UI
  • Kubectl Using Rancher UI

Happy Learning & Happy Coding
Saiyam Pathak
https://www.linkedin.com/in/saiyam-pathak-97685a64/
https://twitter.com/SaiyamPathak

--

--

Saiyam Pathak
100daysoflearning

l CNCF Ambassador | CKA | CKAD | Influx ACE | Multi-cloud certified | Rancher Ranch Hands member