Nginx Deployment with Health Checks

Build a production-ready Nginx Deployment manifest with replicas, resource limits, liveness and readiness probes, and proper labeling for Kubernetes services.

Web Servers

Detailed Explanation

Production Nginx Deployment

A production Nginx deployment needs more than just the container image. You need health checks to ensure pods are serving traffic, resource limits to prevent noisy-neighbor problems, and proper labels for service discovery.

Key Configuration

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
  namespace: web
  labels:
    app: "nginx"
    tier: "frontend"
spec:
  replicas: 3
  selector:
    matchLabels:
      app: "nginx"
  template:
    spec:
      containers:
        - name: nginx
          image: nginx:1.25-alpine
          ports:
            - name: http
              containerPort: 80
              protocol: TCP
          resources:
            requests:
              cpu: "50m"
              memory: "64Mi"
            limits:
              cpu: "200m"
              memory: "128Mi"
          livenessProbe:
            httpGet:
              path: /
              port: 80
            initialDelaySeconds: 5
            periodSeconds: 10
          readinessProbe:
            httpGet:
              path: /
              port: 80
            initialDelaySeconds: 3
            periodSeconds: 5

Why Alpine?

Using nginx:1.25-alpine instead of the full image reduces the container size from ~140MB to ~40MB. This means faster pulls, less storage, and a smaller attack surface. Alpine-based images are the standard for production Kubernetes deployments.

Resource Sizing

For a typical Nginx reverse proxy serving static files:

  • Requests (guaranteed resources): 50m CPU, 64Mi memory
  • Limits (maximum allowed): 200m CPU, 128Mi memory

These values ensure the scheduler places pods appropriately while preventing any single pod from consuming excessive cluster resources. Adjust based on your traffic patterns and page sizes.

Health Checks

The liveness probe checks if Nginx is responding on port 80. If it fails 3 consecutive checks (default failureThreshold), Kubernetes restarts the container. The readiness probe determines when the pod is ready to receive traffic from a Service.

Use Case

Deploying a production Nginx web server or reverse proxy in Kubernetes with proper health checks, resource management, and high availability through multiple replicas.

Try It — K8s Pod Spec Builder

Open full tool