Implement Kubernetes to Extend Devops Workflow.

Updated 16 March 2020

https://kubernetes.io/


Description:

Kubernetes is an open-source container management (orchestration) tool. It’s container management responsibilities include container deployment, scaling & descaling of containers & container load balancing.

Why Use Kubernetes?

Companies out there maybe using Docker or Rocket or maybe simply Linux containers for containerizing their applications. But, whatever it is, they use it on a massive scale. They don’t stop at using 1 or 2 containers in Prod. But rather, 10’s or 100’s of containers for load balancing the traffic and ensuring high availability.

Keep in mind that, as the traffic increases, they even have to scale up the number of containers to service the ‘n’ no of requests that come in every second. And, they have to also scale down the containers when the demand is less.

That is why, the need for container management tools is important. Both Docker Swarm and Kubernetes are popular tools for Container management and orchestration. But, Kubernetes is the undisputed market leader. Partly because it is Google’s brainchild and partly because of its better functionality.

Features of Kubernetes:

  • Automates various manual processes: for instance, Kubernetes will control for you which server will host the container, how it will be launched etc.
  • Interacts with several groups of containers: Kubernetes is able to manage more cluster at the same time
  • Provides additional services: as well as the management of containers, Kubernetes offers security, networking and storage services
  • Self-monitoring: Kubernetes checks constantly the health of nodes and containers
  • Horizontal scaling: Kubernetes allows you scaling resources not only vertically but also horizontally, easily and quickly
  • Storage orchestration: Kubernetes mounts and add storage system of your choice to run apps
  •  Automates rollouts and rollbacks: if after a change to your application something goes wrong, Kubernetes will rollback for you
  •  Container balancing: Kubernetes always knows where to place containers, by calculating the “best location” for them
  •  Run everywhere: Kubernetes is an open source tool and gives you the freedom to take advantage of on-premises, hybrid, or public cloud infrastructure, letting you move workloads to anywhere you want.

How To Install Kubernetes Cluster :

Pre-requisites To Install Kubernetes :

Since we are dealing with VMs, we recommend the following settings for the VMs:-

Master:

  • 2 GB RAM
  • 2 Cores of CPU

Slave/ Node:

  • 1 GB RAM
  • 1 Core of CPU

Pre-Installation Steps On Both Master & Slave (To Install Kubernetes):

First, login as ‘sudo’ user because the following set of commands need to be executed with ‘sudo’ permissions. Then, update your ‘apt-get’ repository.

Turn Off Swap Space:

comment -out all the swap entries in /etc/fstab file , because kubernetes doesn’t support swap memory.

Update The Hosts File With IPs Of Master & Node:

Run the following command on both machines to note the IP addresses of each.

Now go to the ‘hosts’ file on both the master and node and add an entry specifying their respective IP addresses along with their names which are master-node and slave-node. This is used for referencing them in the cluster. It should look like the below screenshot on both the machines.

Setting Static IP Addresses

Next, we will make the IP addresses used above, static for the VMs. We can do that by modifying the network interfaces file. Run the following command to open the file:

Now enter the following lines in the file.

Install OpenSSH-Server

Now we have to install openssh-server. Run the following command:

Install Docker

Now , we have to install Docker because Docker images will be used for managing the containers in the cluster. Run the following commands:

Next we have to install these 3 essential components for setting up Kubernetes environment: kubeadm, kubectl, and kubelet.

Run the following commands before installing the Kubernetes environment.

Install kubeadm, Kubelet And Kubectl :

Updating Kubernetes Configuration

Next, we will change the configuration file of Kubernetes. Run the following command:

Steps Only For Kubernetes Master VM (master-node:)

Step 1: We will now start our Kubernetes cluster from the master’s machine. Run the following command:

Step 2: As mentioned before, run the commands from the above output as a non-root user

To verify, if kubectl is working or not, run the following command:

Step 3: You will notice from the previous command, that all the pods are running except one: ‘kube-dns’. For resolving this we will install a pod network. To install the CALICO pod network, run the following command:

Step 4: Next, we will install the dashboard. To install the Dashboard, run the following command:

Step 5: Your dashboard is now ready with it’s the pod in the running state.

Step 6: By default dashboard will not be visible on the Master VM. Run the following command in the command line:

To view the dashboard in the browser, navigate to the following address in the browser of your Master VM:

You will then be prompted with this page, to enter the credentials:

Step 7: In this step, we will create the service account for the dashboard and get it’s credentials.
Note: Run all these commands in a new terminal, or your kubectl proxy command will stop. 

Run the following commands:

1. This command will create a service account for dashboard in the default namespace

2. This command will add the cluster binding rules to your dashboard account

 3. This command will give you the token required for your dashboard login:

You should get the token like this:

4. Copy this token and paste it in Dashboard Login Page, by selecting token option

5. You have successfully logged into your dashboard!

Steps For Only Kubernetes Node VM (knode)

It is time to get your node, to join the cluster! This is probably the only step that you will be doing on the node, after installing kubernetes on it.

Run the join command that you saved, when you ran ‘kubeadm init’ command on the master.

Note: Run this command with “sudo”.

For further comprehensive best practices you can visit :

https://kubernetes.io/docs/home/

Category(s) Uncategorized
author
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Start a Project






    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home