Does NestJS Work With Kubernetes?

Fully CompatibleLast verified: 2026-02-20

NestJS applications run seamlessly on Kubernetes with proper containerization and configuration.

Quick Facts

Compatibility
full
Setup Difficulty
Easy
Official Integration
No — community maintained
Confidence
high
Minimum Versions
NestJS: 8.0.0
Kubernetes: 1.19.0

How NestJS Works With Kubernetes

NestJS is a Node.js framework that containerizes exceptionally well for Kubernetes deployments. You package your NestJS application in a Docker image, push it to a registry, and deploy it to Kubernetes using standard manifests. NestJS doesn't require special Kubernetes-aware code—it just needs proper health checks, graceful shutdown handling, and environment variable configuration. The framework's modular architecture aligns naturally with microservices patterns, making it ideal for multi-pod Kubernetes setups. Most teams use NestJS on Kubernetes for microservices, REST APIs, and GraphQL servers. The developer experience is straightforward: build your NestJS app normally, create a Dockerfile, define Kubernetes Deployments/Services, and use kubectl or Helm for orchestration. Considerations include implementing liveness and readiness probes for pod health detection, handling SIGTERM signals for graceful termination, and using ConfigMaps or Secrets for environment-specific configuration.

Best Use Cases

Microservices architecture with multiple NestJS services running independently in separate pods
Auto-scaling REST APIs that respond to traffic spikes using Kubernetes HPA (Horizontal Pod Autoscaler)
Multi-tenant SaaS applications deployed with Kubernetes namespaces and network policies
CI/CD pipelines deploying NestJS services on every commit using Kubernetes and GitOps tools like ArgoCD

NestJS with Kubernetes Deployment

bash
npm install @nestjs/common @nestjs/core @nestjs/platform-express
bash
# Dockerfile
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY dist ./dist
EXPOSE 3000
CMD ["node", "dist/main.js"]

---
# kubernetes-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nestjs-app
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nestjs-app
  template:
    metadata:
      labels:
        app: nestjs-app
    spec:
      containers:
      - name: nestjs
        image: myregistry/nestjs-app:1.0.0
        ports:
        - containerPort: 3000
        livenessProbe:
          httpGet:
            path: /health
            port: 3000
          initialDelaySeconds: 15
          periodSeconds: 10
        readinessProbe:
          httpGet:
            path: /health/ready
            port: 3000
          initialDelaySeconds: 5
          periodSeconds: 5
        terminationGracePeriodSeconds: 30

Known Issues & Gotchas

critical

Container exits immediately without liveness probe handling SIGTERM

Fix: Implement graceful shutdown in main.ts: await app.close() after listening. Set terminationGracePeriodSeconds in Kubernetes manifest to allow cleanup time.

warning

Readiness probe fails because database connection isn't ready during startup

Fix: Implement a HealthModule with TypeORM/Prisma checks. Use initialDelaySeconds and periodSeconds appropriately in readinessProbe configuration.

warning

Multi-instance NestJS apps accessing shared resources cause race conditions

Fix: Use distributed locking (Redis), message queues (RabbitMQ), or database-level constraints for shared state management across pod replicas.

info

Environment variables not loaded from ConfigMaps

Fix: Use @nestjs/config module and ensure ConfigMap keys match your .env file structure. Mount ConfigMaps as volumes or inject via env references in deployment spec.

Alternatives

  • Express.js with Kubernetes—more lightweight than NestJS but requires manual structure and middleware setup
  • FastAPI with Kubernetes—excellent for Python-based microservices with automatic OpenAPI documentation
  • Go microservices with Kubernetes—superior performance and smaller container images, steeper learning curve

Resources

Related Compatibility Guides

Explore more compatibility guides