OpenSource For You

Microservi­ces with Docker and Kubernetes: An Overview

- By: Shashidhar Soppin The author is a senior architect and has 16+ years of experience in the IT industry—in virtualisa­tion, the cloud, Docker, open source software, ML, deep learning and OpenStack. He is part of the product engineerin­g team at Wipro. You

Docker is an open source platform that’s used to build, ship and run distribute­d services. Kubernetes is an open source orchestrat­ion platform for automating deployment, scaling and the operations of applicatio­n containers across clusters of hosts. Microservi­ces structure an applicatio­n into several modular services. Here’s a quick look at why these are so useful today.

The Linux operating system has become very stable now and is capable of cleanly sandboxing processes, to execute processes easily; it also comes with better name space control. This has led to the developmen­t and enhancemen­t of various container technologi­es. Some of the features/characteri­stics of the Linux OS that help container developmen­t are:

Only the required libraries get installed in their respective containers.

Custom containers can be built easily.

During the initial days, LXC (Linux container) was very popular and was the foundation stone for the developmen­t of various other containers.

Name space and control groups (process level isolation). A brief history of containers is outlined in Table 1.

Some of the advantages of containers are:

Containers are more lightweigh­t compared to virtual machines (VMs).

The container platform is used in a concise way to build Docker (which is one of the container standards; it is actually a static library and is a daemon running inside the Linux OS).

Containers make our applicatio­ns portable. Containers can be easily shipped, built and deployed.

Containers

Containers are an encapsulat­ion of an applicatio­n with its dependenci­es. They look like lightweigh­t VMs but that is not the case. A container holds an isolated instance of an operating system, which is used to run various other applicatio­ns.

The architectu­re diagram of Docker-container in Figure 1 shows how each of the individual components are interconne­cted.

Various components of the Docker-container architectu­re

The Docker daemon (generally referred to as dockerd) listens for Docker API requests and manages Docker objects such as images, containers, networks and volumes. A daemon

can also communicat­e with other daemons to manage Docker services.

The Docker client (also called ‘docker’), with which many Docker users interact with Docker, can communicat­e with more than one daemon.

A Docker registry stores Docker images. Docker

Hub and Docker Cloud are public registries that anybody can use, and Docker is configured to look for images on Docker Hub, by default.

Note: When we use the docker pull or docker run commands, the required images are pulled from the configured registry. When we use the docker push command, the image is pushed to our configured registry.

When we use Docker, we are creating and using images, containers, networks, volumes, plugins and other various such objects. These are called Docker objects.

Thus containers are fundamenta­lly changing the way we develop, distribute and run software on a daily basis. These developmen­ts and advantages of containers help in the advancemen­t of microservi­ces technology. Microservi­ces are small services running as separate processes, where each service is lined up with separate business capabiliti­es. When one lists the advantages of microservi­ces over monolithic

applicatio­ns (as given below), it will help users understand and appreciate the beauty of the former. In microservi­ces: One single applicatio­n is broken down into a network of processes.

All these services communicat­e using REST or MQ. Applicatio­ns are loosely coupled.

The scaling up of applicatio­ns is a lot easier.

There is very good isolation of these services, as when one fails, others can continue.

What is Kubernetes and why should one use it?

Kubernetes is an open source orchestrat­or for deploying containeri­sed applicatio­ns (microservi­ces). It is also defined as a platform for creating, deploying and managing various distribute­d applicatio­ns. These applicatio­ns may be of different sizes and shapes. Kubernetes was originally developed by Google to deploy scalable, reliable systems in containers via applicatio­n-oriented APIs. Kubernetes is suitable not only for Internet-scale companies but also for cloud-native companies, of all sizes. Some of the advantages of Kubernetes are listed below:

Kubernetes provides the software necessary to build and deploy reliable and scalable distribute­d systems. Kubernetes supports container APIs with the following benefits:

• Velocity—a number of things can be shipped quickly, while also staying available.

Scaling—favours scaling with decoupled architectu­re through load balancers and scaling with consistenc­y. Abstract—applicatio­ns built and deployed on top of Kubernetes can be ported across different environmen­ts. Developers are separated from specified machines for providing abstractio­n. This reduces the overall machines required, thus reducing the cost of CPUs and RAM.

Efficiency—the developer’s test environmen­t can be cheaply and quickly created via Kubernetes clusters and this can be shared as well, thus reducing the cost of developmen­t. Kubernetes continuous­ly takes action to ensure that the current state matches the desired state.

The various components involved in Kubernetes

Pods: These are groups of containers that can group together other container images developed by different teams into a single deployable unit.

NameSpaces: This provides isolation and complete access control for each microservi­ce, to control the degree to which other services interact with it.

Kubernetes services: Provides load balancing, discovery isolation and naming of microservi­ces.

Ingress: These are objects that provide an easy-to-use front-end (externalis­ed API surface area).

Running and managing containers using Kubernetes

As described earlier, Kubernetes is a platform for creating, deploying and managing distribute­d applicatio­ns. Most of these applicatio­ns take an input, process the data and provide the results as output. Most of these applicatio­ns contain language runtime, libraries (libc and libssl) and source code.

A container image is a binary package that encapsulat­es all of the files necessary to run an applicatio­n inside an OS container. The Open Container Image (OCI) is the standard image format that’s most widely used.

The container types are of two categories:

System containers, which try to imitate virtual machines and may run the full boot processes

Applicatio­n containers, which run single applicatio­ns These images can be run using the docker run –d –name command, using the CLI.

The default container runtime used by Kubernetes is Docker, as the latter provides an API for creating applicatio­n containers on both Linux and Windows based operating systems.

kuard is a database and maps to Port 8080, and can aso be explored using a Web interface.

Docker provides many features by exposing the underlying ‘cgroups’ technology provided by the Linux kernel. With this, the following resource usage can be managed and monitored:

Memory resources management and limitation

CPU resources management and limitation

Deploying a Kubernetes cluster

Kubernetes can be installed on three major cloud providers like that of Amazon’s AWS, Microsoft’s Azure and Google’s Cloud Platform (GCP). Each cloud provider allows its own container service platforms.

Kubernetes also can be installed using Minikube, locally. Minikube is a simulation of the Kubernetes cluster, but the main function of this is for experiment­ation, local

developmen­t or for learning purposes.

Kubernetes can also be run on IoT platforms like Raspberry Pi for IoT applicatio­ns and for low-cost projects. The Kubernetes cluster has multiple components such as: Kubernetes Proxy—for routing network traffic for load balancing services (https://kubernetes.io/docs/gettingsta­rted-guides/scratch/)

Kubernetes DNS—a DNS server for naming and discovery of the services that are defined in DNS Kubernetes UI— this is the GUI to manage the cluster

Pods in Kubernetes

A pod is a collection of applicatio­n containers and volumes running in the same execution environmen­t. One can say that the pods are the smallest deployable artifacts in the Kubernetes cluster environmen­t. Every container within a pod runs in its own cgroup but shares a number of Linux name spaces. Pods cane be created using the following command in the CLI: kubectl run kuard

Most of the pod manifests are written using YAML or JSON scripts. But YAML is preferred as it is in human readable format.

There are various command options using kubectl to run or list pods.

Labels, annotation­s and service discovery

Labels are key-value pairs that can be attached to Kubernetes objects such as pods and replica-sets. These labels help in finding the required informatio­n about Kubernetes objects, metadata for objects and for the grouping of objects.

Annotation­s provide a place to store additional metadata for Kubernetes objects with assisting tools and libraries.

Labels and annotation­s go hand-in-hand; however, annotation­s are used to provide extra informatio­n about where and how an object came from and what its policies are.

A comparison between Docker Swarm and Kubernetes

Both Kubernetes and Docker Swarm are popular and used as container orchestrat­ion platforms. Docker also started supporting and shipping Kubernetes from its CE (community edition) and EE (enterprise edition) releases.

Docker Swarm is the native clustering for Docker. Originally, it did not provide much by way of container automation, but with the latest update to Docker Engine 1.12, container orchestrat­ion is now built into its core with first-party support.

It takes some effort to get Kubernetes installed and running, as compared to the faster and easier Docker Swarm installati­on. Both have good scalabilit­y and high availabili­ty features built into them. Hence, one has to choose the right one based on the need of the hour. For more details, do refer to https://www.upcloud.com/blog/docker-swarm-vskubernet­es/.

References

[1] https://kubernetes.io/docs/getting-started-guides/ scratch/ [2] https://kubernetes.io/docs/setup/independen­t/createclus­ter-kubeadm/ [3] https://docs.docker.com/engine/dockerover­view/#docker-architectu­re [4] https://kubernetes.io/docs/tutorials/kubernetes-basics/ deploy-intro/ [5] https://www.upcloud.com/blog/docker-swarm-vskubernet­es/

 ??  ??
 ??  ??
 ??  ?? Figure 1: Docker container architectu­re (http://apacheboos­ter.com/kb/what-is-adocker-container-for-beginners/docker-architectu­re/)
Figure 1: Docker container architectu­re (http://apacheboos­ter.com/kb/what-is-adocker-container-for-beginners/docker-architectu­re/)
 ??  ?? Figure 2: Kubernetes architectu­re
Figure 2: Kubernetes architectu­re
 ??  ??
 ??  ?? Figure 3: Kubernetes cluster (https://kubernetes.io/docs/tutorials/ kubernetes-basics/deploy-intro/)
Figure 3: Kubernetes cluster (https://kubernetes.io/docs/tutorials/ kubernetes-basics/deploy-intro/)

Newspapers in English

Newspapers from India