← Back to Templates
Kubernetes Next.js Deployment
Production Kubernetes Deployment + Service + HPA for Next.js. Includes resource limits, health checks, and rolling update strategy.
kubernetesadvanced
Next.jsKubernetesDocker
Template Code
k8s-nextjs-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nextjs-app
namespace: production
labels:
app: nextjs-app
version: "1.0"
spec:
replicas: 2
selector:
matchLabels:
app: nextjs-app
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
template:
metadata:
labels:
app: nextjs-app
spec:
containers:
- name: nextjs
image: ghcr.io/your-org/nextjs-app:latest
ports:
- containerPort: 3000
env:
- name: NODE_ENV
value: production
resources:
requests:
cpu: "100m"
memory: "256Mi"
limits:
cpu: "500m"
memory: "512Mi"
livenessProbe:
httpGet:
path: /api/health
port: 3000
initialDelaySeconds: 15
periodSeconds: 20
readinessProbe:
httpGet:
path: /api/health
port: 3000
initialDelaySeconds: 5
periodSeconds: 10
---
apiVersion: v1
kind: Service
metadata:
name: nextjs-app
namespace: production
spec:
selector:
app: nextjs-app
ports:
- protocol: TCP
port: 80
targetPort: 3000
---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: nextjs-app
namespace: production
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: nextjs-app
minReplicas: 2
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70