Run a Hello-Node Application on Kubernetes

In my last post, I covered some basic about Kubernetes and explained the procedure about how to install locally single-node Kubernetes cluster via Minikube. In this tutorial, I am going to explain the basic concepts about what is the Core Components of Kubernetes and how to deploy an hello-node application in Kubernetes.

You might have by this time gathered some idea about what are the Core components being used inside Kubernetes by looking at the Architecture Diagram that created in this blog. And, you may think that Kubernetes is difficult to learn. Yes, I thought the same when I started learning initially. But, once you learn the Kubernetes, you will love it because of its so-called robust features.

As I explained in the last post, Kubernetes is a leading and powerful container orchestration tool for managing the containerized application.  It consists mainly of the following Core Components. Since the above Architectural Diagram created for single-node Kubernetes cluster, Master’s and Node’s services are running in the same VirtualBox VM. Keep reading my blog, I will write in my upcoming post to explain how to set up Master’s and Node’s services on a different host. Now, Let’s start learning what really Kubernetes Core components do.

Master Core Components

  • kube apiserver –  provides REST API interfaces for cluster management and provides mechanisms for authentication, authorization, admission control, API registration, and discovery.
  • etcd  –  etcd is a distributed storage database. This serves as the central database for a Kubernetes cluster. The major role is to save the state of the entire cluster, and other components can know the status of the cluster by querying etcd. And, it is Simple, Secure, Fast and Reliable as well.
  • controller manager  –  responsible for the overall cluster coordination and maintaining the health of the entire state of the cluster, such as fault detection, auto-scaling, rolling updates and so on.
  • scheduler –  responsible for determining the resource usage of each node and assign an appropriate Node to the new container. This decision based on the usage of CPU, Memory, Disk, Network and so on.

Node Core Components

  • kubelet – It is an agent that runs on every node in a Kubernetes cluster and is responsible for maintaining the life cycle of the Pod, and also handles maintaining mounting volumes, container logging, garbage collection, and many more important things;
  • Container runtime – responsible for image management and the real operation of the Pod and container (CRI). Container Runtime Interface provides an abstraction between kubelet and specific runtime implementation.  In our case, the software which use to launch an application is known as container runtime (i.e. Docker and rkt)
  • Kube-proxy –  is responsible for providing service discovery and load balancing within the cluster for the service. Specifically, it implements the internal access from the pod to the service and the external from the node port to the service.

Now!. you have understood some idea about what Kubernetes Core components do and what the purpose of it is.  You can also refer kubernetes.io for more details. Let’s start jumping into creating a simple hello-node application in Kubernetes. Wait! Without explaining what is Pod, Service, Deployment Kubernetes Objects, you will not understand the commands that we are going to use.

Some of the Kubernetes Objects

  • Pod – is the smallest deployable units that can be created, scheduled and managed. Pods are one or more containers that share volumes, a network namespace, and are a part of a single context.
  • Service – Unified method of accessing the exposed workloads of pods. it acts as load-balancer for the pods above one layer.
  • Deployment – It is a declarative method of managing pod for creating Replicas of containers, providing Roll back and Rolling updates, and so on.

I have covered only some of the Kubernetes Objects for this post since we will use only those objects in a hello-node application. If you would like to know more about Kubernetes Objects, I will share the reference link at the end of this post.

Deploy hello-node in Minikube

Let’s start deploying a hello-node application in Kubernetes. In my last post, I covered how to install minikube locally.  If you do not have an idea about what minikube is, I would recommend reading my previous post. In order to set up a Kubernetes environment, we need to first start the minikube VirutalBox VM.  Run the below command to start minikube.

Now, run the below command to check the kubernetes nodes.

In case, you would like to know what is running inside minikube. Just run the same command with “-o yaml” option. You can see some of the core components under images section that were mentioned in the above diagram.

Let’s run below command to create hello-node application on Kubernetes on Minikube. This command basically pull hello-node image from gcr.io and create a deployment and application pod. 

If the above command is successful, you will see the deployment and pod object is creating the deployment Pod and Application Pod. Run the below command to check the hello-node deployment.

The sample output for your reference.

You can check the events in case container creation is being delayed.

Cool. The hello-node application is successfully deployed in Kubernetes. Now! we need to know how to verify the application whether it is working or not. This is where a service object comes into the picture. Run the below kubectl command to expose the service to port 8080. I am using LoadBalancer Type for exposing the service for this demo. There are a couple of service types available to expose your application. If you would like to know more service Type,  you can check the service type features in the reference link.

Once the service is created, you can verify the service by running the below command.

Finally, you need to run minikube service command to find out the IP address and port of hello-node application.

copy the URL and paste in a web browser and hit Enter Button. A sample application is running in Kubernetes now.

Fantastic!. We have successfully deployed and exposed the hello-node application in Kubernetes.

 

Leave a Comment

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

14 − 11 =