Container Orchestration

Saurav chaudhary
8 min readOct 1, 2021

What are we going to learn in this Blog?

📌Why container orchestration?

📌Docker Swarm

📌Kubernetes

You know Nothing, Jon snow😉

Why container orchestration?

In my previous blogs & videos I have only talked about of using a single container by running a single instance of any application. But what when we will have a big amount of users ,so how will we manage things ?

Let’s suppose a situation where we are running a container of NodeJS by running a command docker run Nodejs and The users have increased as for now. then what should we do ?

we will run multiple instance of NodeJS application by this command

By this we are creating multiple instances of our application but what when any of containers fails or stops, Then how will we fix it ?

we have to manually keep a look on that so that whenever a container stops, you will destroy that instance and create another. But what will if the docker host stops 😂 All the container on that will also be stopped hence resulting in a bad user experience. This situation can be managed by a dedicated engineer but what when we have thousands of Docker hosts running with thousands of containers in them. It is kind of impossible to fix that manually. So we have automate that using some tools or scripts to work accordingly.

And the solution for it is Container orchestration, it will basically create multiple instances of your application with just a simple command and it will also maintain the load by their load balancing techniques. it will also create a network inside the containers and will also share the storage. Apart from that it has some amazing features which is really mind blowing.

It will automatically increase or decrease the number of containers or hosts according to the users using our application after the deployment. I mean that is super cool😍

Through this simple docker swarm command we are creating 100 instances of our NodeJS application. Isn't that's cool😒.

Networking inside the docker host through orchestration

So Which solutions of container orchestration are really good in the market, let’s check it out📌✔

The Top Three Container Orchestration Solutions are —

  1. Docker Swarm which has been developed by the docker is quite easy to set up but lacks so many advance features from it.
  2. Kubernetes which has been developed by the google is quite kind of hard to set up but has some really advanced features in it, in fact as of now it is supported by all cloud platforms like GCP , AWS etc.. Kubernetes is now one of the highest rated project on GitHub too.
  3. Mesos which has been developed by the apache is hard to set up but has so many advance features in it.

Now Let’s Dive Deeper into

Docker swarm

As we have discussed about the container orchestration solutions so Docker swarm is one of the solutions.

we create multiple instances of our application just by running a simple command. we can create a whole cluster of workers nodes for our application and docker swarm will balance the load itself. but we have to make sure that on each host docker has been installed

Docker swarm has one swarm manager who manages all the worker nodes. We can initialize a docker swarm manager by running a simple command.

To assign other workers as worker node run docker swarm init and it will give a output of a token, use that output to initialize the worker nodes and creating number of instances of our application.

This command will assign the host as the swarm manager but now is this possible to login into each node and assigning the work as the worker node .No its not possible that's why we use docker swarm orchestration which has a specials feature of docker service which does exactly the same job for us. so again life is easy🙌

So Run this command to create multiple instances of your application

we can use port mapping, environmental variables ,network assigning all those things that we have used in our simple docker .

That was just a high level overview of what docker swarm is and how it has solved the orchestration problems.

Now Let’s Dive Deeper into the high level overview of

Kubernetes

📌Before heading towards the kubernetes cluster, we need to understand some of the basic concepts of kubernetes.

Let us first learn about the node

Node is the physical or virtual machine where kubernetes is installed, A node is a machine where kubernetes launched their containers.

it is also known as Minions

But what if when this node fails? Obviously our application will go down😂 So what should we do in this?

To solve this problem let me introduce cluster to you✌

So Cluster is basically a group of nodes, so if one nodes goes down , our application won’t go down at the time. By this we can also share loads between the nodes. We can automate this process too by the help of Kubernetes tools.

Now a question will come into your mind that hey saurav these all are the worker nodes so how will we manage this all , from where they will get instructions, where all the data of those worker nodes will be saved??

So the answer is Master node

This master node is actually responsible for container orchestration and handles all the worker node

Now Let’s move towards the components of the kubernetes , when you installed the kubernetes you have actually installed these things 😜

API-Server

ETCD

Schedulers

Controller

Container runtime

Kubelet

Now lets dive deep into each of this and see how they are helping in the kubernetes environment

  1. API-Server — API-Server basically acts as a frontend, the users,management devices and the command line connects to the api in order to talk to the kubernetes cluster.
  2. ETCD — It basically stores all the information about the worker nodes and the master nodes in a distributed key value form.
  3. Schedulers — It is basically used to assign some tasks to the newly created modes.
  4. Controllers controllers are the main brain behind this container orchestration. They are responsible for replacing those nodes which has been stopped With new worker nodes.
  5. Container runtime — container runtime is the underline software that is basically used to run the containers , In case of ours we will use dockers to run those containers.
  6. Kubelet Kubelet basically acts as an agent which is responsible to maintain all the containers and it makes sure that every node is working properly with the container.

Now that’s very cool as we have learned all about the kubernetes components , nodes & master. But how this are distributed on the server i mean how one node is considered to be worker node and one to be the master. So let’s dive deep into behind the scenes because it will help you in setting up your cluster in an efficient way.

Containers will always run on the container runtime environment which has been installed on the worker node. So basically worker nodes runs all the container of our application. We can use other container runtime also like RKT, CRI-O

Kube-apiserver is installed on the master node and thats what make a node a master node. It is connected with the kubelet which gives the whole health information about the containers and the nodes.

ETCD , Controller ,scheduler is also installed on the master node.

Now lets learn something about the Kubectl that is one of the command line utility used to manage and deploy the cluster.

Let’s Learn some of the commands

The kubectl run command is used to deploy an application on the cluster

The Kubectl cluster info command is used to get information about the cluster

The kubectl get nodes is used to show all the nodes that in the running state.

There are much more to learn in the kubernetes like POD’S , replicasets , networking in the pods etc… So Go ahead and learn some real kubernetes now you have got a basic understanding of all kubernetes , docker swarm & Container Orchestration.

Hands-on learning exercises

There are some sets of questions based on the Container orchestration those you have learned above, now its time to test yourself. So make sure to test yourself before moving to the next blog .Comment on the blog and let me know how much marks you have achieved. In case of any doubts/questions/suggestions feel free to Dm me on Twitter.

  1. What is Container orchestration?
  2. How to run multiple instances of your application together?
  3. How to get information about the cluster using CLI command?
  4. which container orchestration is best & why?
  5. How can we store container data permanently ?

Try this all questions to test yourself and let me know

End of Blog

Happy learning 😃

Follow us on Twitter To join us in the initiative of learning Devops in 60 days.

see you in next blog, stay happy 😄

--

--