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
How to Deploy Java Application in Kubernetes? Kubernetes is a platform for automating deployment, scaling, and management of containerized applications. Pods are basic units that hold one or more containers. Deployments manage application deployment and updates. Services provide stable endpoints for accessing pods. Ingress manages external acce
9 min read
How To Deploy Python Application In Kubernetes ? In today's IT world we are moving from the monolithic to microservice architecture to make our applications highly available and scalable to bring fault tolerance. In this transformation, containerization i.e., containerizing the application are a fundamental aspect of this micro services. In this a
6 min read
Deploying A Node.js Application In kubernetes Kubernetes, or K8s, is an open-sourced container orchestration technology that is used to automate the manual processes of deploying, managing, and scaling applications with the help of containers. Kubernetes was originally developed by engineers at Google, and In 2015, it was donated to CNCF (Cloud
9 min read
How To Deploy PHP Application On Kubernetes ? Prologue to deploying a PHP applications on Kubernetes starts with understanding the containerization, where applications and their libraries are packaged into convenient, lightweight containers. Docker is generally utilized for this reason. Kubernetes then deals with these containers, abstracting a
9 min read
How to Deploy Spring Boot Application in Kubernetes ? The Spring Boot framework provides an assortment of pre-configured templates and tools to make the development of Java-based applications simpler. With little configuration, it enables developers to quickly design production-ready, stand-alone apps. Kubernetes, commonly referred to as K8s, is an ope
7 min read