Join us

Nodejs app + Kubernetes for beginners

Hello everyone. We are going to start a Kubernetes series. In this series, we will learn the basics of Kubernetes and try to deploy our sample microservice code with Kubernetes.

Disclaimer :) If you don’t have prior knowledge of Docker, please refer to this blog. It will help you to understand Kubernetes more precisely.

What we are going to achieve in this article

  1. What is Kubernetes? Why and when should we use it?
  2. The flow of the entire service.
  3. Create a basic microservice.
  4. Add Kubernetes necessary file and explain about these files.
  5. Run this Kubernetes and access this on localhost.

Step 1: What is Kubernetes? Why and when should we use it?

I assume that if you came here, you probably have some idea about Kubernetes. But even if you don’t know about Kubernetes, please follow the resources below, which will give you a clear idea about Kubernetes.

Step 2: Entire Flow.

Let's understand this flow. So, we can make our Kubernetes manifest file accordingly.

  • MongoDB: MongoDB can communicate with user service only. MongoDB is not authorised to talk with the gateway service.
  • User: User service can communicate with Gateway Service and MongoDB service but can not share from the internet.
  • Gateway: Gateway service can communicate to the internet and then the gateway will talk to the user service.

Step 3: Create a Basic microservice

  1. User
  2. Gateway
  3. MongoDB

Step 4: Add Kubernetes necessary file and explain about these files

  • In the Basic-Kubernetes branch, there are three folders.

  • Each folder has 2 .yaml files other than code
    1. deployment.yaml: This file is responsible for running a build docker images
    2. service.yaml: This file is responsible for exposing the code outside the world or even in the same network.

  • Explanation of MongoDB folder
    1. Mongodb is an independent service. As shown in the above diagram user service is dependent on MongoDB.
    2. So, our aim will be to run MongoDB successfully on Kubernetes.
    3. Before that let's look at the deployment file and service file of MongoDB.

deployment.yaml

service.yaml
1. In this file we need to look at ClusterIP
2. ClusterIP is used to expose any pod inside the same cluster.
3. We used here type as ClusterIP because MongoDB service no need to expose outside the Cluster.

4. Now let's run the MongoDB service by running the following command

5. Now our container is created and the service also.

Explanation of User folder

  1. User folder is where all user-related logic resides. So, this user service can communicate with the MongoDB service.
    2. This service is also going to use internally. So, that is why this service type is ClusterIP.

deployment.yaml

service.yaml

Let's run user service

Now if we see we have 2 services and deployments are running

Explanation of Gateway folder

  1. A gateway where our routes are mentioned. Which is going to expose us to the external world.
  2. Since it is going to communicate to internet. That is why this service type is kept as LoadBalancer.

deployment.yaml

service.yaml

Let’s run user service

Now if we see we have 3services and 3 deployments are running

NOTE:

In the above picture, if we see in services part. Gateway service can be accessed from localhost:8001.

Next, article we will deploy the same application on AWS EKS. Which is managed service by AWS

Feedback: Thank you for reading this article. I hope you understood the basics of deploying your application from scratch on Kubernetes. Please feel free to ask questions or give suggestions to improve the content quality.


Only registered users can post comments. Please, login or signup.

Start blogging about your favorite technologies, reach more readers and earn rewards!

Join other developers and claim your FAUN account now!

Avatar

RAKESH KUMAR SHARMA

@airrakesh
Simplifying human life | 👨🏽‍💻
User Popularity
33

Influence

2k

Total Hits

2

Posts