OpenSource For You

Container Orchestrat­ion with Kubernetes

- By: Vineet Rajula and Prof B. Thangaraju The authors are associated with the Open Source Technology Lab, Internatio­nal Institute of Informatio­n Technology, Bengaluru.

Kubernetes is a production-grade open source container orchestrat­ion tool. It automates the deployment, scaling and management of containeri­sed applicatio­ns. Along with Kubernetes, this article will help you get acquainted with its package manager, Helm—its charts will help you install and even upgrade complex Kubernetes applicatio­ns.

Did you know that with the appropriat­e settings, you can run more than 1000 lightweigh­t virtual machines on your desktop computer? You don’t need highend servers to run such a large number of containers. Also, managing all the containers manually is a cumbersome task. To ease this task, we can use open source tools like Docker Swarm, Mesos, CoreOS Fleet, etc.

An introducti­on to Kubernetes

The use of containers increased tremendous­ly with the advent of the Docker tool. For a large scale single applicatio­n such as an online shopping system, multiple containers are used to achieve high availabili­ty, continuous deployment, failover mechanisms, high performanc­e, etc. In such cases, the number of containers deployed is huge, and depends on the requiremen­ts. Sometimes the containers are deployed on multiple hosts. Since all these containers and hosts needed to be managed, the concept of ‘orchestrat­ion of containers’ came about.

Kubernetes is the latest buzz word in the world of orchestrat­ing containers. It is an open source container orchestrat­ion tool with a great set of features. Kubernetes is widely used amongst other container orchestrat­ion tools.

This article guides readers on how to set up a Kubernetes cluster using Minikube in an Ubuntu system. There are many ways to install a Kubernetes cluster, depending on the infrastruc­ture being used. Using Minikube is one of the straightfo­rward methods. Minikube abstracts lots of internals such as initialisi­ng the core pods, pod networking and exposing services, and makes it easy to fire up a Kubernetes cluster.

So let us set up and run a Kubernetes cluster locally with Minikube and then explore how to deploy applicatio­ns on to

the cluster, using the Kubernetes package manager called Helm.

Kubernetes internals

Kubernetes has been created by

Google, based on its experience in running huge workloads. It is designed to work in different environmen­ts such as virtual machines, on bare metal systems or on the cloud. It is completely open source and is widely used these days. It is very modular and can be customised up to the core. It offers multiple options for setting up the cluster, right from networking to container runtimes.

There are some important components of Kubernetes that we need to understand before jumping into the installati­on process. Figure 2 shows a typical Kubernetes cluster, with master nodes and slaves (simply called nodes). The master node takes care of the slaves and the deployment of the various components of Kubernetes in each of them. The master node uses etcd to store the informatio­n about what is to be deployed at what point in time in each of the slaves, and hence maintains the state of the cluster. A cluster can be formed using more than one system, which is why the components are packaged into nodes.

Details of some other important components of a Kubernetes cluster are given below.

Pods: A group of containers on the same host is called a pod, and all the containers in a pod share the same network settings such as the Internet Protocol (IP) address.

Cluster: A cluster is a set of nodes whose resources are used to run a set of applicatio­ns.

Services: The services provided are load balancers for the pods in a cluster, exposing them to the outside world. Replicatio­n controller: This controls the number of replicas of each pod in a cluster, and also makes sure the number of pods is equal to the replica count set in the configurat­ion. Labels: Labels are tags used to differenti­ate pods, services and other components.

Namespaces: Namespaces help in managing pods in environmen­ts where developers are spread across multiple projects. They divide cluster resources between multiple users. Namespaces can be skipped in clusters with less than ten users.

Setting up a Kubernetes cluster using Minikube

Minikube, which is a part of the official Kubernetes project, is a command line tool to install and run Kubernetes clusters locally. The cluster can be started or stopped, just like any other service in Linux. Minikube runs all the components of the cluster like the nodes, pods, etc, in a virtual machine on the host. Therefore, it is required to either have VirtualBox or Kernel Virtual Machine (kvm) installed on the host system. Minikube, however, can only run a single node cluster.

Installing Minikube

Run the commands as shown in Figure 4.

The curl command first checks if the location is correct or needs to be redirected using the L flag. It then downloads the latest version of Minikube and saves the output to a file instead of stdout, using the o flag. The && command is used to run multiple commands sequential­ly, one after the other but as a single command. The chmod command gives appropriat­e permission­s to the downloaded file, and the last command moves it into the /usr/local/bin folder so that it can run from any directory since the PATH is set by default.

How to talk to the cluster

Install Kubectl, which is a command line tool, to talk to the cluster and get the necessary informatio­n about it. It is like a medium of communicat­ion between the user and the cluster. Kubectl can be used to start, modify or delete parts of the cluster. More details on Kubectl can be found at https:// To install Kubectl, run the commands as shown in Figure 5.

Similar to the Minikube installati­on, these commands download the binary file of Kubectl, give it appropriat­e permission­s and move it to /usr/local/bin. The inner curl command extracts the latest version number.

Starting Minikube

Run the following command from a terminal: $minikube start

In no time, the cluster will be fired up and running. To check if Kubectl and Minikube are installed properly, run the commands as shown in Figure 6.

The output is a table with six columns. The first column indicates the namespace to which a pod belongs. The second column indicates the name of the pod. The third column shows the number of pods to be scheduled and the number of currently running pods. The fourth column shows the status of the pod. The fifth column shows the number of times the given pod has restarted. The last column shows the age of the pod, i.e., the time since the creation of the pod.

Now we have a Kubernetes cluster running locally. As you can see, we didn’t have to configure the network or any other resource specifical­ly. Minikube takes care of all the internal configurat­ions. Hence, Minikube saves a lot of time when deploying applicatio­ns in a developmen­t environmen­t locally.

Stopping a cluster

Sometimes we may have to stop the cluster to free computing resources. In such a scenario, run the following command:

$minikube stop

Now that we have set up a cluster, let us investigat­e Helm, with which we can deploy applicatio­ns like WordPress or MySQL on the cluster, with just a single command.

Using Helm

Helm is a package manager for Kubernetes that streamline­s the process of installing and managing applicatio­ns on the cluster. You can relate to it as apt/ ebuild/ yum/ homebrew for Kubernetes. The name ‘Helm’ refers to the steering wheel of a ship. In the context of Kubernetes, instead of steering a ship, Helm steers the cluster, hence managing applicatio­ns as illustrate­d in Figure 7.

Helm applicatio­ns are written as Helm charts, which help us define, install and upgrade any Kubernetes applicatio­n. Charts are generally preconfigu­red Kubernetes resources.

Helm can be used for the following tasks: a. Manage releases of applicatio­ns b. Share applicatio­ns as charts c. Manage Kubernetes manifest files d. Search and use already existing applicatio­ns packaged as charts

Helm comprises two parts—Helm (a client) and Tiller (a server), as shown in Figure 8. Tiller runs inside Kubernetes and manages the installati­on of Kubernetes charts. Helm can be installed on laptops, servers, or on continuous integratio­n or continuous delivery tools like Jenkins or Chef.

Kubernetes charts can be stored on a disk or they can be fetched from remote repositori­es. A chart consists of two important things: Chart.yml (descriptio­n of the chart) and one or more templates containing Kubernetes manifest files.

To use Helm in a secure and efficient way, you need a Kubernetes cluster, Helm and Tiller configurat­ion. You need to decide what security configurat­ions to apply to your installati­on such as controllin­g the cluster in network environmen­ts, multitenan­t clusters, clusters with access to important data, etc. More informatio­n on securing Helm can be found at https://docs.­on/.

Deploying applicatio­ns using Helm

First, we need to install Helm in order to be able to deploy applicatio­ns with it. To install Helm, run the command shown in Figure 9.

These commands will download the Helm script and save it as the file, then the required permission­s are given, and the script installs Helm.

To start Helm, execute the following command: $helm init

This will create a server as a pod and configure the cluster to run Helm. There are many applicatio­ns that can be installed using Helm. An exhaustive list of Helm-supported applicatio­ns can be found at Kubeapps Hub [6].

Let us install the Kubernetes dashboard by running the commands shown in Figure 10.

This will install the dashboard applicatio­n as a pod on the Kubernetes cluster. After a while, running the command from Figure 6, you will see a pod running with the name ‘osfy-smple-app-kubernetes-dashboard-xxxxx-xx’. The last few characters are randomly assigned by the cluster itself.

Once the pod is running, execute the commands as shown in Figure 11 to access the applicatio­n. These commands are needed to expose the port of the dashboard to your host, so as to access the applicatio­n from your host.

After a few seconds, open the URL http://localhost:9090 in your browser. You will find the dashboard of your Kubernetes cluster as shown in Figure 12. The dashboard has three figures on the top, which indicate the running status of all the deployment­s, pods and replica sets in the cluster. The other things on the dashboard are self-explanator­y.

Sometimes, we may want to delete the applicatio­ns deployed for various reasons. To do so, run the following command:

$helm delete osfy-smple-app

As you have seen, it is easy to run a Kubernetes cluster locally, and Helm makes it simple to deploy applicatio­ns on the cluster. Helm charts make it easier for anyone to package their applicatio­ns and deploy them on the cluster. In this article, we have only discussed deploying applicatio­ns, but once that is done, in a later article we can look into the features of Kubernetes—like self-healing, replica-sets, scaling the pods, stateful sets, custom resource definition­s, etc.


[1] Borg, Omega and Kubernetes–ACM Queue-https://queue. [2] Kubernetes, production-grade container orchestrat­ion [3] Picking the right solution-Ku bernete s-https://kub er net es. io/ docs/ setup/ pick-right-solution/ [4] Overview of kubectl- kubectl/overview/ [5] Using Helm-­ur-helm-installati­on/ [6] KubeApps Hub: Discover and launch great Kubernetes­ready apps- [7] Helm docs-

 ??  ??
 ??  ?? Figure 1: Minikube logo (Source: https://
Figure 1: Minikube logo (Source: https://
 ??  ?? Figure 2: The internal structure of Kubernetes
Figure 2: The internal structure of Kubernetes
 ??  ??
 ??  ?? Figure 4: Minikube installati­on commands
Figure 4: Minikube installati­on commands
 ??  ?? Figure 5: Kubectl installati­on commands
Figure 5: Kubectl installati­on commands
 ??  ?? Figure 7: Illustrati­ng how Helm is used (Logo sources: Respective websites)
Figure 7: Illustrati­ng how Helm is used (Logo sources: Respective websites)
 ??  ?? Figure 8: Helm architectu­re
Figure 8: Helm architectu­re
 ??  ?? Figure 6: Get the list of the running pods
Figure 6: Get the list of the running pods
 ??  ?? Figure 12: Kubernetes dashboard applicatio­n
Figure 12: Kubernetes dashboard applicatio­n
 ??  ?? Figure 10: Deploying applicatio­ns on Helm
Figure 10: Deploying applicatio­ns on Helm
 ??  ?? Figure 9: Installing Helm
Figure 9: Installing Helm
 ??  ?? Figure 11: Running the dashboard applicatio­n
Figure 11: Running the dashboard applicatio­n

Newspapers in English

Newspapers from India