Kubernetes Deployment Guide for Node.js Applications
Step-by-step guide to deploying Node.js on Kubernetes — Deployments, Services, HPA, health checks, and zero-downtime rollouts.
Kubernetes is the industry standard for container orchestration. This guide covers deploying Node.js applications with production-grade configuration.
1. Deployment Manifest
apiVersion: apps/v1
kind: Deployment
metadata:
name: api-server
spec:
replicas: 3
selector:
matchLabels:
app: api-server
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
template:
metadata:
labels:
app: api-server
spec:
containers:
- name: api-server
image: ghcr.io/ventrarocket/api-server:1.0.0
ports:
- containerPort: 3000
resources:
requests:
cpu: "100m"
memory: "128Mi"
limits:
cpu: "500m"
memory: "512Mi"
livenessProbe:
httpGet:
path: /health
port: 3000
initialDelaySeconds: 15
periodSeconds: 20
readinessProbe:
httpGet:
path: /ready
port: 3000
initialDelaySeconds: 5
periodSeconds: 10
2. Service and ConfigMap
apiVersion: v1
kind: ConfigMap
metadata:
name: api-config
data:
NODE_ENV: "production"
PORT: "3000"
---
apiVersion: v1
kind: Service
metadata:
name: api-svc
spec:
selector:
app: api-server
ports:
- port: 80
targetPort: 3000
type: ClusterIP
3. Horizontal Pod Autoscaler
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: api-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: api-server
minReplicas: 2
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 60
4. Health Endpoints in Node.js
import express from "express";
import { db } from "./db";
const app = express();
app.get("/health", (req, res) => {
res.json({ status: "ok", uptime: process.uptime() });
});
app.get("/ready", async (req, res) => {
try {
await db.query("SELECT 1");
res.json({ status: "ready" });
} catch {
res.status(503).json({ status: "not ready" });
}
});
5. Zero-Downtime Rollout
# Update image tag, monitor, and rollback if needed
kubectl set image deployment/api-server api-server=ghcr.io/ventrarocket/api-server:1.1.0
kubectl rollout status deployment/api-server
kubectl rollout undo deployment/api-server # if issues arise
Conclusion
Kubernetes gives Node.js applications enterprise-grade reliability: rolling updates, autoscaling, self-healing. Ventra Rocket uses Kubernetes for all production microservices.
Related Articles
Docker and CI/CD Pipeline for Next.js Applications
A complete guide to containerising Next.js with Docker multi-stage builds and setting up a fully automated CI/CD pipeline with GitHub Actions for zero-downtime deployments.
Microservices Architecture with Docker and Message Queues
Design patterns for building microservices — service decomposition, async communication with RabbitMQ, circuit breakers, distributed tracing, and observability.
CI/CD with GitHub Actions: Build, Test, and Deploy Pipelines
Automating software delivery — build pipelines, testing, Docker image builds, deployment automation, and secrets management with GitHub Actions.