Rancher : One place for all Kubernetes Clusters

Rancher : One place for all Kubernetes Clusters

Rancher: One place for all Kubernetes Clusters

Rancher is open-source software for delivering Kubernetes-as-a-Service.

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 has a 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 their 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 bare metal servers or VM’s and it provides a 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 the other two will be worker nodes. I have followed the official documentation for installation but some steps are tweaked a bit for the more easy stuff.

- **Step 1**: Downloading the RKE binarywget [https://github.com/rancher/rke/releases/download/v0.1.18/rke_linux-amd64](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 characteristics of the nodes 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 a cluster.yml file. Basically, it's the three nodes configuration and some other cluster-related config which I have chosen as default.

nodes:
- address: {IP}
  port: "22"
  internal_address: ""
  role:
  - controlplane
  - etcd
  hostname_override: ""
  user: ubuntu
  docker_socket: /var/run/docker.sock
  ssh_key: ""
  ssh_key_path: {your_key_path}
  labels: {}

Below is my config:

Above is how the Node will look in the 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 the same location) or if you have filed 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 LogsFew 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 setupAll 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 screenRancher first screen

Rancher DashboardRancher 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 the cluster name, the Access Key, and secret Key .

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

cluster Optionscluster Options

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

VPCVPC

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

NodesNodes

Step5: Create Cluster

Cluster CreationCluster Creation

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

AWS Cluster createdAWS Cluster created

Google Kubernetes Cluster Creation using Rancher:

Step1: Create a Service Account with the following permissions in your Google Cloud Console.

Service accountService 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 creationJSON 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 FileAdding Cluster and providing JSON File

Step4: Once you click on Configure Nodes, it will authenticate with the JSON file provided and display different sections 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 to create, your Google Kubernetes cluster will be created.

GKEGKE

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 clusterImporting cluster

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

commandscommands

role creationrole creation

applying yaml file to the RKE cluster for rancher importapplying 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 it's very simple and you do not have to do anything else apart from giving the cluster name and node shapes & count.

OKE cluster CreationOKE cluster Creation

Cluster CreatedCluster Created

Rancher Dashboard:

Lets see the Rancher Dashboard Now.

All clusters in one placeAll clusters in one place

Now you have a 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 it for the Google Kubernetes cluster and the process is the same for all the clusters.

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

Select monitoringSelect monitoring

Step3: click Enable and set the limits. Click Save

ConfigureConfigure

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 respectivelyGoogle Kubernetes Engine & Oracle Kubernetes Engine Grafana Dashboards respectively

RKE Grafana DashboardRKE Grafana Dashboard

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

google GKE podsgoogle GKE pods

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

Deploying application: Deploying an 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.

DeployDeploy

Let's deploy a sample nginx application. When you choose deploy you get a variety of options to deploy your application.

Deploy applicationDeploy 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 applicationdeployed 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

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 post 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/saiyampathak/ https://twitter.com/SaiyamPathak youtube.com/saiyam911