Get, Set and Go with Kubernetes

What on earth is Kubernetes and why should we care?

“ Kubernetes (commonly referred to as “K8s”) is an open source container cluster manager originally designed by Google and donated to the Cloud Native Computing Foundation”.

The name originates from the Greek vocabulary; the meaning of the word “kubernetes” in Greek means “Helmsman”; in other words it means “Governor”. So it was only natural when Google adopted the name to their open source container orchestration tool. As of today, Kuberneteshas become almost the de-facto standard when it comes to container orchestration tasks. With Kubernetes, the deployment, scaling and management of containers have become a breeze. So, if you are a container-geek and live and breathe containers day-in and day-out, chances are you are already familiar with Kubernetes. For rest of the population, this post should be a good starting point!

Kubernetes Tool sets

With the very brief introduction out of the way, let’s talk about the different options of running Kubernetes. You can run Kubernetes in one of the following ways:

i) Install and run on your local macine

ii) Run on a cloud environment such as AWS/Google Cloud/Azure

In this post, I am going to describe how to set it up on a local machine running Windows. Similar procedures can be applied when running on a Mac.

Install Minikube:

Minikube is kubernetes in a nutshell on your laptop, literally. It was aimed at facilitating running a Kubernetes cluster locally without the presence of a cloud environment.

The minikube can be downloaded from here. You can check the latest release and download instructions here.

Both of these microservices are pretty basic and sends out “Hello <Username>” to the console when <Username> is passed as a query parameter to a http Get Rest endpoint.

Both of these run fine when run as docker containers and works as expected when tested with either curl or postman. Now, I want to manage the deployment and scaling of these microservices using Kubernetes. That’s exactly what Kubernetes is meant for.

To run the hello-boot microservice:

kubectl run hello-boot — image=chakrar27/helloboot — port=8080

where “chakrar27/helloboot” is my image name for the spring-boot microservice. The above command results in the following output

replicationcontroller “hello-boot” created

You can check the status of the pod by typing

kubectl get pods ->-> it would show something like this

NAME READY STATUS RESTARTS AGE hello-boot-jvdz3 1/1 Running 0 3m

Once the replication controller is created, next task is to create a “service” out of it so that it’s available to the external resources. You do that by

Run containers at scale

We saw how to run a single instance of a docker container using kubernetes. One significant feature of Kubernetes allows us to deploy containers at scale using something known as “replica-s”. In order to scale the hello-boot microservice to let’s say five instances, all I need to do is

Navigate to the above url in the browser. You can check the Replication Controllers

and the Services

Troubleshooting

While setting up the minikube cluster, if you encounter an error as this

minikube.exe startStarting local Kubernetes cluster...Kubernetes is available at https://192.168.99.100:8443.Kubectl is now configured to use the cluster.PS C:\Users\aprindle\Downloads> kubectl.exe get poUnable to connect to the server: dial tcp 127.0.0.1:8080: ConnectEx tcp: No connection could be made because the targetmachine actively refused it.

then do the following steps. I actually faced this error myself.

set KUBECONFIG=”C:\Users\<username>\.kube\config

kubectl config set-context minikube

Basically, you are resetting the context here. This should solve the problem.