Kubernetes for Docker developers @ GIDS16

Kubernetes for Docker developers @ GIDS16

Burr Sutter from RedHat spoke about Kubernetes for Docker Developers at Great Indian Developer Summit 2016 (GIDS16). The session started with basics of Docker followed by how Kubernetes can help Docker developers to easily manage applications.

Docker is an open source platform as a service (PaaS) to automate deployment of applications. With Docker, developers don’t have to worry about the environment on which their application will run. Docker containers (explained below) wraps up an application with all of it’s dependencies with exact same version that run on production server same way as on your system irrespective of environment. E.x.: “/” (Unix) vs “\” (Windows) won’t break your app.

Docker has a repository of backend stack images. If you don’t find one suitable image, you create your own. Following code snippet shows a sample to create your own image:

cd /vagrant/src/kube4docker/node­demo //directory your application
docker build ­t burr/mynode:v1 . //build image of your application
docker run ­d ­p 8000:8000 burr/mynode:v1 //run an instance of your image on docker

You can check your app by going to (or whatever your IP address is). Once the image is ready, we can run multiple instance, called Docker container, of the same image. Each container is executed as an isolated process on top of same host operating system.

If you want to access bash shell of your container, you can do so as following:

docker ps //get the id of your container
docker exec -it container_id

Say if you want to run another two instance of same image mynode, you will have to execute docker run command two more times. This means you need to execute above commands n number of times for n containers, or may be you can script it. But Kubernetes can make your life simpler.

Kubernetes is an open source container cluster manager designed originally by Google. Kubernetes has capabilities of:

  • Self-healing
  • Horizontal manual & auto scaling
  • Automatic restarting
  • Scheduled across hosts
  • Built-in load-balancer
  • Rolling upgrades

Cluster of hosts is here called pods. Pods allow sharing of IP, storage volumes, resources and lifecycles across containers. Resources can be shared in pods using namespace and it can be defined in a .yaml file. Following is the sample of a .yaml file:

apiVersion: v1
kind: Namespace
name: kubedemo

To create a namespace using above .yaml file, you can execute following commands:

kubectl create -f ./kubedemo-namespace.yaml //create namespace

Once the namespace is created, you can run your application on a pod in the created namespace. Following are the commands to do so:

kubectl --namespace=kubedemo run mynode --image=burr/mynode:v1 --port=8000 //run your application

To make your life simpler, you can specify number of containers you want and Kubernetes will create replica of your container. You just need to execute this command:

kubectl ­­namespace=kubedemo scale rc mynode ­­replicas=3

Replicas are managed by replication controller (RC) of Kubernetes. RC is created by default with number of replica as 1 if you don’t specify. RC makes sure that your container is always up and running. If by any chance one of your container goes down, RC will start one for you to keep your application always up and running.

When you have n containers, you would want to balance load across those n containers. Load balancing with Kubernetes is simple as executing following command:

kubectl --namespace=kubedemo expose rc mynode --type="LoadBalancer"

You don’t have to setup your own load balancer, but you definitely can if you want to.

One more thing for which Kubernetes makes life simpler is rolling upgrades. Difficulty level of rolling upgrades is proportional to number of containers, even if scripted. But with Kubernetes you just need to do this:

docker build -t burr/mynode:v2 . //build image of your updated application
kubectl --namespace=kubedemo rolling-update mynode --image=burr/mynode:v2 --update-period=2s //start updating your application

Overall, Kubernetes is an exciting tool to manage applications on top of clusters to make lives of DevOps and administrators. And speaker has convinced to at-least give it a try with an interesting session.

(PS: All the snippets are taken from document shared by speaker Burr Sutter.)


You Might Also Like

Leave a Reply

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