---
title: "Deploying and exposing a Node.js application on Kubernetes  - Fairbanks"
description: "This guides walks you through deploying and exposing a Node.js application on Kubernetes"
url: "https://fairbanks-upgrade.ubo-dev.nl/deploying-and-exposing-a-node-js-application-on-kubernetes/"
language: "en"
---

Blog

# Deploying and exposing a Node.js application on Kubernetes

Technology

October 4, 2023

Author: Elvira Dautović

In this post

[Prerequisites](https://fairbanks-upgrade.ubo-dev.nl/deploying-and-exposing-a-node-js-application-on-kubernetes#section-1-1)[Create the Node.js Application:&nbsp;](https://fairbanks-upgrade.ubo-dev.nl/deploying-and-exposing-a-node-js-application-on-kubernetes#section-1-2)[Deploy to Kubernetes:&nbsp;](https://fairbanks-upgrade.ubo-dev.nl/deploying-and-exposing-a-node-js-application-on-kubernetes#section-1-3)[Concluding the Node.js deployment](https://fairbanks-upgrade.ubo-dev.nl/deploying-and-exposing-a-node-js-application-on-kubernetes#section-1-4)

Share this post

In this tutorial, we will walk through the process of deploying a simple “Hello World” Node.js application on a Kubernetes cluster. Kubernetes is a powerful container orchestration platform that helps manage and scale containerized applications.

## Prerequisites

- Basic understanding of containers and Docker.
- Docker desktop installed.
- A running Kubernetes cluster (locally using tools like Minikube or remotely).
- Start your Minikube cluster.
- Kubernetes command-line tool (kubectl) installed and configured to interact with your cluster.

## Create the Node.js Application:&nbsp;

For this tutorial, we’ll create a simple Node.js application that responds with “Hello, Kubernetes!” when accessed. 

`npm init -y `

Create a **app.js** file and add the following code, 

`// app.js `

`const http = require('http'); `

`const server = http.createServer((req, res) => { `

` res.writeHead(200, { 'Content-Type': 'text/plain' }); `

` res.end('Hello, Kubernetes!n'); `

`}); `

`const PORT = process.env.PORT || 3000; `

`server.listen(PORT, () => { `

``  console.log(`Server listening on port ${PORT}`);  ``

`}); `

Now, you can run the application with the following command:

`node app.js `

You should see your application running on your localhost 3000\. 

**Let’s Dockerize the application:** 

Create a Dockerfile in your application’s root directory to define how the application should be packaged as a Docker container. 

`FROM node:14 `

`WORKDIR /app `

`COPY package*.json ./ `

`RUN npm install `

`COPY . . `

`EXPOSE 3000 `

`CMD [ "node", "app.js" ] `

**Build the Docker image:** 

`docker build -t hello-k8s-app . `

Tag and push the Docker image to DockerHub 

`docker tag hello-k8s-app your-dockerhub-username/hello-k8s-app `

Replace your-dockerhub-username with your actual Docker Hub username. 

You need to authenticate with Docker Hub to be able to push images. 

`docker login `

Push the tagged image to your Docker Hub repository. 

`docker push your-dockerhub-username/hello-k8s-app `

## Deploy to Kubernetes:&nbsp;

Create a Kubernetes deployment configuration to manage the application’s replicas. 

`# deployment.yaml `

`apiVersion: apps/v1 `

`kind: Deployment `

`metadata: `

` name: hello-k8s-deployment `

`spec: `

` replicas: 3 `

` selector: `

` matchLabels: `

`app: hello-k8s `

` template: `

` metadata: `

` labels: `

` app: hello-k8s `

` spec: `

` containers: `

` - name: hello-k8s-container `

` image: your-dockerhub-username/hello-k8s-app `

` ports: `

` - containerPort: 3000 `

Apply the deployment to your cluster: 

`kubectl apply -f deployment.yaml`

**Expose the application:** 

To make the application accessible from outside the cluster, you can expose it using a Kubernetes service. 

`# service.yaml `

`apiVersion: v1 `

`kind: Service `

`metadata: `

` name: hello-k8s-service `

`spec: `

` selector: `

` app: hello-k8s `

` ports: `

` - protocol: TCP `

` port: 80 `

` targetPort: 3000 `

` type: LoadBalancer `

Apply the service configuration: 

`kubectl apply -f service.yaml `

**Access the application:** 

Once the service is created and an external IP is assigned, you can access the application in your browser using the external IP. 

**Cleanup:** 

To clean up resources after you’re done: 

`kubectl delete deployment hello-k8s-deployment   
kubectl delete service hello-k8s-service` 

## Concluding the Node.js deployment

**_Congratulations!_** You’ve successfully deployed a simple Node.js application on Kubernetes and exposed it to the internet. 

Kubernetes has revolutionized the way we deploy and manage applications, providing a powerful and flexible platform for container orchestration. In this and the [previous](https://fairbanks.nl/how-monitoring-works-in-kubernetes/) tutorial, we’ve covered the basics of setting up a local Kubernetes cluster using Minikube, creating deployments, managing pods, and exposing applications through services. This of course is just the tip of the iceberg – Kubernetes offers a wealth of advanced features for handling complex scenarios in production environments. 

As you continue your journey with Kubernetes, consider exploring features such as namespaces, persistent storage, configuration management, and more. The Kubernetes documentation and online tutorials are excellent resources to deepen your knowledge and become a proficient Kubernetes user. With practice and dedication, you’ll be well on your way to mastering the art of container orchestration and streamlining your application deployment processes. 

If you have remarks or questions let me know. We also provide free health checks for companies using Kubernetes or OKD, OpenShift, Rancher so if you would like to have a chat, let me know.

![Michiel](https://fairbanks-upgrade.ubo-dev.nl/media/uploads/2025/06/Michiel.jpeg?width=500 "Michiel")

## Want to know more about open source private cloud

Let’s talk with Michiel Manten

[Let's talk](https://fairbanks-upgrade.ubo-dev.nl/contact/?subject=Deploying%20and%20exposing%20a%20Node.js%20application%20on%20Kubernetes)

Insights & resources

## Latest blogs & news

[Insights & resources](https://fairbanks-upgrade.ubo-dev.nl/insights-resources/)

[KeynoteSustainable private cloud: how to balance energy, performance and business impact![Post background](https://fairbanks-upgrade.ubo-dev.nl/static/background_column.jpg)Sustainable private cloud: how to balance energy, performance and business impactEvent](https://fairbanks-upgrade.ubo-dev.nl/sustainable-private-cloud/)

[BlogOpenStack Hibiscus is here: What’s new in the latest release![Post background](https://fairbanks-upgrade.ubo-dev.nl/static/background_column.jpg)October 20, 2026OpenStack Hibiscus is here: What’s new in the latest releaseTechnology](https://fairbanks-upgrade.ubo-dev.nl/openstack-hibiscus-is-here-whats-new-in-the-latest-release/)

[KeynoteHow Kubernetes and Talos make OpenStack easier to upgrade, manage and scale![Post background](https://fairbanks-upgrade.ubo-dev.nl/static/background_column.jpg)How Kubernetes and Talos make OpenStack easier to upgrade, manage and scaleEvent](https://fairbanks-upgrade.ubo-dev.nl/how-kubernetes-and-talos-make-openstack-easier-to-upgrade-manage-and-scale/)

[KeynoteFrom infrastructure complexity to cloud control: how to orchestrate your datacenter with software![Post background](https://fairbanks-upgrade.ubo-dev.nl/static/background_column.jpg)From infrastructure complexity to cloud control: how to orchestrate your datacenter with softwareEvent](https://fairbanks-upgrade.ubo-dev.nl/from-infrastructure-complexity-to-cloud-control-how-to-orchestrate-your-datacenter-with-software/)

[BlogDigital autonomy: looking beyond the cloud![Post background](https://fairbanks-upgrade.ubo-dev.nl/static/background_column.jpg)September 9, 2026Digital autonomy: looking beyond the cloudTechnology](https://fairbanks-upgrade.ubo-dev.nl/digital-autonomy-looking-beyond-the-cloud/)

[BlogUpgrading OpenStack: why containerization and Kubernetes are the answer![Post background](https://fairbanks-upgrade.ubo-dev.nl/static/background_column.jpg)August 26, 2026Upgrading OpenStack: why containerization and Kubernetes are the answerTechnology](https://fairbanks-upgrade.ubo-dev.nl/upgrading-openstack-containerization-kubernetes/)

[BlogCloud infrastructure migration: what are your options and where do you start?![Post background](https://fairbanks-upgrade.ubo-dev.nl/static/background_column.jpg)July 24, 2026Cloud infrastructure migration: what are your options and where do you start?Technology](https://fairbanks-upgrade.ubo-dev.nl/cloud-infrastructure-migration-what-are-your-options-and-where-do-you-start/)

[BlogFairbanks named as a representative vendor in the 2026 Gartner® Market Guide![Post background](https://fairbanks-upgrade.ubo-dev.nl/static/background_column.jpg)July 21, 2026Fairbanks named as a representative vendor in the 2026 Gartner® Market Guide for cloud infrastructure sovereign solutionsTechnology](https://fairbanks-upgrade.ubo-dev.nl/fairbanks-named-as-a-representative-vendor-in-the-2026-gartner-market-guide-for-cloud-infrastructure-sovereign-solutions/)

[BlogMutable vs. immutable infrastructure![Post background](https://fairbanks-upgrade.ubo-dev.nl/static/background_column.jpg)June 18, 2026Mutable vs. immutable infrastructure: What it means for your datacenterTechnology](https://fairbanks-upgrade.ubo-dev.nl/mutable-vs-immutable-infrastructure-what-it-means-for-your-datacenter/)

[BlogPress release![Post background](https://fairbanks-upgrade.ubo-dev.nl/static/background_column.jpg)June 10, 2026Press releaseEvent](https://fairbanks-upgrade.ubo-dev.nl/press-release/)

Newsletter
