How to Deploy Node.js Application in Kubernetes?
Last Updated :
08 May, 2025
Deploying the Node.js application on Kubernetes in a containerized manner makes it highly scalable,fault-tolerant, and allows for zero downtime. Kubernetes allows container orchestration that can be used in many ways during deployment. Load balancing is provided, which helps with automatic load transfer to multiple pods. So, getting all these benefits from Kubernetes lets us understand how we can deploy Node.js applications to Kubernetes.
Deploy Node.js Application in KubernetesPrimary Terminologies
- Kubernetes: It is a container orchestration tool that provides features such as scalability, zero downtime, fault tolerance, and manageability.
- Deployment: It refers to the deployed application in Kubernetes.
- Service: It exposes deployment to outside users instead of the cluster.
Deploying The Node.js Application in Kubernetes
Step 1: Create and push the Docker image of the Node.js application
FROM node:20-alpine
RUN mkdir -p /home/app
WORKDIR /home/app
COPY /package.json /package-lock.json .
RUN npm install
COPY / .
EXPOSE 3000
CMD ["npm","start"]
- Save the file with the name Dockerfile. Now let's build the Docker image using the below command.
docker build -t node-hello-world .

- Here -t option specifies tag of the image. Once the image is ready push it to the docker repository.
- First create a repository in dockerhub after login.

- Run the below command to change the tag of image according to your docker repository.
docker tag [OLD IMAGE NAME] [YOUR_USERNAME/REPOSITORY_NAME:TAG]

- After changing the tag push the image to repository using below command.
docker push IMAGE_NAME:TAG
.png)
Step 2: Create YAML Configuration File for Kubernetes Deployment
- Lets create configuration for kubernetes deployment. Create a YAML file in your project folder with the name as you want.
- First add apiVersion and metadata to the file. Specify the kind of deployment. Here It will be Deployment.
apiVersion: v1
kind: Service
metadata:
name: nodehelloworld
- Now specify other specifications of the deployment. Selector will select all pods with matching app name. Template specifies labels for the deployment. Replicas determines number of replicas that will be created.
spec:
replicas: 1
selector:
matchLabels:
app: nodehelloworld
template:
metadata:
labels:
app: nodehelloworld
- Finally specify the configuration of the container. Specify image name that is pushed earlier and port number of Node.JS application.
spec:
containers:
- name: nodehelloworld
image: deepcodr/node-hello-world:latest
ports:
- containerPort: 3000
imagePullPolicy: Always
- The entire deployment configuration will look like below.
apiVersion: apps/v1
kind: Deployment
metadata:
name: nodehelloworld
spec:
replicas: 1
selector:
matchLabels:
app: nodehelloworld
template:
metadata:
labels:
app: nodehelloworld
spec:
containers:
- name: nodehelloworld
image: deepcodr/node-hello-world:latest
ports:
- containerPort: 3000
imagePullPolicy: Always
Step 3: Add Service Configuration to the File
- Now lets add Service configuration to the file. Above the deployment configuration add service configuration as below.
apiVersion: v1
kind: Service
metadata:
name: nodehelloworld
spec:
selector:
app: nodehelloworld
type: LoadBalancer
ports:
- port: 3000
targetPort: 3000
---
- The specification provided makes the type of service as LoadBalancer. The port specify port on which service will listen on. Targetport specifies port to which traffic is forwarded.
- Other options are similar to that of deployment. Save the file and move to next.
Step 4: Apply the Deployment
- Open terminal where YAML file is present and apply the configuration using below command.
kubectl apply -f filename
- You should see similar response as below.

- Run below command to view the services and external IPS.
kubectl get services
- Copy the IP address and curl it with the application endpoint that you have created. You should get the desired response back.

Conclusion
Thus we have successfully deployed NodeJs application on Kubernetes. This has created pod and service for the application which can run with all features of kubernetes. We can use other kubernetes options to manage pods and update the application as required.
Similar Reads
Non-linear Components In electrical circuits, Non-linear Components are electronic devices that need an external power source to operate actively. Non-Linear Components are those that are changed with respect to the voltage and current. Elements that do not follow ohm's law are called Non-linear Components. Non-linear Co
11 min read
Spring Boot Tutorial Spring Boot is a Java framework that makes it easier to create and run Java applications. It simplifies the configuration and setup process, allowing developers to focus more on writing code for their applications. This Spring Boot Tutorial is a comprehensive guide that covers both basic and advance
10 min read
Class Diagram | Unified Modeling Language (UML) A UML class diagram is a visual tool that represents the structure of a system by showing its classes, attributes, methods, and the relationships between them. It helps everyone involved in a projectâlike developers and designersâunderstand how the system is organized and how its components interact
12 min read
3-Phase Inverter An inverter is a fundamental electrical device designed primarily for the conversion of direct current into alternating current . This versatile device , also known as a variable frequency drive , plays a vital role in a wide range of applications , including variable frequency drives and high power
13 min read
Backpropagation in Neural Network Back Propagation is also known as "Backward Propagation of Errors" is a method used to train neural network . Its goal is to reduce the difference between the modelâs predicted output and the actual output by adjusting the weights and biases in the network.It works iteratively to adjust weights and
9 min read
What is Vacuum Circuit Breaker? A vacuum circuit breaker is a type of breaker that utilizes a vacuum as the medium to extinguish electrical arcs. Within this circuit breaker, there is a vacuum interrupter that houses the stationary and mobile contacts in a permanently sealed enclosure. When the contacts are separated in a high vac
13 min read
Polymorphism in Java Polymorphism in Java is one of the core concepts in object-oriented programming (OOP) that allows objects to behave differently based on their specific class type. The word polymorphism means having many forms, and it comes from the Greek words poly (many) and morph (forms), this means one entity ca
7 min read
CTE in SQL In SQL, a Common Table Expression (CTE) is an essential tool for simplifying complex queries and making them more readable. By defining temporary result sets that can be referenced multiple times, a CTE in SQL allows developers to break down complicated logic into manageable parts. CTEs help with hi
6 min read
Python Variables In Python, variables are used to store data that can be referenced and manipulated during program execution. A variable is essentially a name that is assigned to a value. Unlike many other programming languages, Python variables do not require explicit declaration of type. The type of the variable i
6 min read
Spring Boot Interview Questions and Answers Spring Boot is a Java-based framework used to develop stand-alone, production-ready applications with minimal configuration. Introduced by Pivotal in 2014, it simplifies the development of Spring applications by offering embedded servers, auto-configuration, and fast startup. Many top companies, inc
15+ min read