Deploy Node.js application using local kubernetes cluster

Satish Mali
1 min readMar 20, 2024

Objectives

  • Create a kubernetes cluster using Minikube.
  • Configure deployment YML file.
  • Deploy application.

Create a kubernetes cluster using Minikube

Install Minikube

curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube

Install kubectl

  • Download the latest release
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
  • Validate the binary
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256"
  • Validate the kubectl binary against the checksum file
echo "$(cat kubectl.sha256)  kubectl" | sha256sum --check
  • Install kubectl
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
  • Test to ensure the version you installed is up-to-date
kubectl version --client

Start cluster

minikube start

Configure deployment YML file

Create file e.g deployment.yml
Note: node-demo:latest is the docker image name that we want to deploy

apiVersion: apps/v1
kind: Deployment
metadata:
name: node-demo
spec:
replicas: 1
selector:
matchLabels:
app: node-demo
template:
metadata:
labels:
app: node-demo
spec:
containers:
- name: app
image: node-demo:latest
ports:
- containerPort: 3000
imagePullPolicy: IfNotPresent

Deploy application

If serving local docker image then need to load image inside Minikube

minikube image load node-demo

Apply resource definitions to Kubernetes

kubectl apply -f deployment.yml

Verify pod

kubectl get pods

This will create a deployment with one replica and a container named node-demo, which uses the node-demo Docker image.

✌️!

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Satish Mali
Satish Mali

No responses yet

Write a response