Kubernetes — Orchestration Guide [A Lovely Symphony]

Covenant Chukwudi
MyCloudSeries
Published in
5 min readMar 19, 2019
Kuberentes, the symphony orchestrator of massive docker farms :). Image credits: Stackify.

What is Kubernetes?

Kubernetes is a container orchestration tool that gives you the ability to run and manage containers over a distributed system. It is designed to help in managing containers at scale from hundreds of containers to thousands of containers. Kubernetes uses different types of container technologies, but in this context, we will be focusing on Docker which we already did a series on:

Learning Docker 1, Learning Docker 2, Learning Docker 3

Consider a scenario of our previous Docker example, where we had a NodeJS Docker setup serving up our app over Nginx as the proxy server. If there is a spike in the traffic hitting the containers in which the NodeJS application is running, it might not be able to handle the load because it is a simple setup within a single machine/server. Hence, we would have to scale up to support that load. This would generally involve you having multiple instances of our NodeJS app containers running on multiple EC2 instances (if you are using AWS) and have a series of load balancers at different network points handling the requests. This type of setup can get really complex very fast and become extremely difficult to manage. This is where Kubernetes comes in.

Kubernetes enables you to orchestrate a scalable container management system. It makes having your multiple containers(which can be instances of different images) running on multiple machines(nodes) easier to set up and manage efficiently. Kubernetes is a very helpful tool when you have different containers running in different quantities across multiple machines.

Setting Up Kubernetes [Locally]

There are quite some distinctions between how you would set-up Kubernetes on your local machine and how you would do set it up in the cloud. The setup that runs in a local machine is usually for test purposes and cannot be used for staging or production.

For the purpose of learning at our current stage, let us discuss on how we would do set it up on our local system. We would discuss cloud-based setups in the upcoming series.

Minikube

Minikube is the tool we would be using to setup Kubernetes on our local machine. Minikube enables you to create a Kubernetes cluster on your local machine which is essentially a virtual machine (singular node) running a number of containers. Minikube is essentially used for managing the virtual machine itself.

Kubectl

kubectl is a tool which is used to interact with the Kubernetes API, it is used both locally and in production for managing containers in a node. It gives you the ability to manage the creation, scaling, destruction e.t.c of containers in a node.

In case you’re wondering what the Kubernetes master is, it is essentially the brain box or administrator of an entire Kubernetes Cluster. It is what controls an entire Kubernetes Cluster and is responsible for nodes, clusters and pod management.

Installation On Mac

To setup Minikube and Kubectl on your local system, follow these steps: though these steps are for a mac machine, it should give you an idea of what to look out for and install if you are using any other OS distribution:

  1. If you are using a mac and you don’t have brew installed, paste and run the below command on your terminal. "/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  2. Next we install kubectl by running the following command in our terminal: brew install kubectl
  3. Upon successful installation of kubectl, we install virtual box which will provide the virtual machine driver which our Minikube tool will need to setup a kubernetes cluster when installed. To do this, head on to virtualbox.org/wiki/downloads and download the corresponding installer for your OS, in our case Mac Os X.
  4. Execute the downloaded Virtual Box executable and follow the installation instructions it prompts.
  5. Next, we install Mini Kube by running this command in your terminal: brew cask install minikube
  6. Finally, run minikube start to confirm successful installation of Minikube. It could take several minutes to startup, If you get a success message in starting then congratulations, you’ve successfully setup Kubernetes on your local machine.

Checking Our Setup

With our installation complete and Minikube started successfully, run

minikube status

and you should see a status output showing you something similar to this:

$ minikube status
host: Running
kubelet: Running
apiserver: Running
kubectl: Correctly Configured: pointing to minikube-vm at 192.168.99.103

You can also run the command kubectl cluster-info in your terminal and you should see an output similar to this:

$ kubectl cluster-info
Kubernetes master is running at https://192.168.99.103:8443
KubeDNS is running at https://192.168.99.103:8443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

If you got responses to those commands similar to the above then awesome. Your Minikube and kubectl setup are successful and healthy.

Moving Forward

We are going to work towards having the NodeJS app we used in our last docker series running as containers within our local Kubernetes cluster (minikube). We would learn a lot of commands, tips and tricks along the way.

Let’s get started

Setup our code

Clone the code repository using git in whatever directory you want by running:

git clone https://github.com/VeaSoft/docker-nodejs.git

create a docker file called DockerFile in the root directory of the code and paste the following content, nothing new, just exactly what we did in our previous Docker series.

FROM ubuntu:16.04

RUN apt-get update

RUN apt-get install -y curl

RUN apt-get install sudo -y

RUN curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -

RUN apt-get install -y nodejs

RUN nodejs -v

RUN mkdir /usr/share/app

WORKDIR /usr/share/app

COPY . .

CMD nodejs index.js

Publish your docker image to Docker Hub

Kubernetes expects your container image to be built and pushed to docker hub already, we’re going to do just that if you didn’t do it in our docker series.

In your code directory build the image using your docker user id:

docker build -t <userid>/dockerize-nodejs-image . -f DockerFile

Since my docker user-id is covenant, I will run the command like this in my terminal:

docker build -t covenant/dockerize-nodejs-image . -f DockerFile

Next, we push our image to DockerHub:

docker push <userid>/dockerize-nodejs-image

Awesome, so now we have our docker image on docker hub which our Kubernetes setup can use as we go on. You can view my own uploaded image here:

https://cloud.docker.com/u/covenant/repository/docker/covenant/dockerize-nodejs-image

Kubernetes Configuration

In your project directory, create a file and call it ourapp-pod.yaml. This file would contain some configuration code which Kubernetes would use to create containers for us.

In our next article, we would continue from here and discuss exactly what is going to be in our config file and a whole lot of other things.

Sticky Notes

  1. Kubernetes is a very powerful toolchain that gives you the ability to run, manage and administrate multiple different containers over multiple machines.
  2. Kubernetes saves you a lot of headaches and makes creating highly scalable network systems easier and more efficient to manage.
  3. To Setup Kubernetes locally, we use a tool called Minikube.
  4. Kubernetes requires us to have our docker images already published to a repository like DockerHub

Conclusion

Kubernetes is a really really awesome and powerful tool that can make building highly scalable applications much easier once you learn how to use it.

Hire Me

Have any interesting project?, super awesome. Shoot me an email at covenantchukwudi@gmail.com

--

--

Covenant Chukwudi
MyCloudSeries

I build products that would have positive effect on lives