Kubernetes Deployments Explained: Strategies and Examples

What is a Kubernetes Deployment?

A Kubernetes Deployment is a controller that manages the lifecycle of your application’s pods. It ensures that a specified number of replicas are running at all times, allows you to update your application safely, and provides the ability to roll back when something goes wrong.

In short, it’s the foundation for running stateless applications in Kubernetes—automated, versioned, and scalable.

If you’re manually applying Pod specs in production, you’re doing it wrong. Deployments are how real-world Kubernetes apps are managed.

Why Deployments Matter

Deployments solve a handful of common challenges:

They’re the safest and most repeatable way to roll out workloads in a Kubernetes environment.

Anatomy of a Deployment

Let’s start with a simple Deployment YAML:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello-world
spec:
  replicas: 3
  selector:
    matchLabels:
      app: hello
  template:
    metadata:
      labels:
        app: hello
    spec:
      containers:
      - name: hello-container
        image: nginx:1.25
        ports:
        - containerPort: 80

Key parts:

Apply it with:

kubectl apply -f deployment.yaml

And scale it with:

kubectl scale deployment hello-world --replicas=5

Deployment Strategies in Kubernetes

Kubernetes Deployments support several rollout strategies, each with trade-offs in speed, availability, and risk. Choosing the right one depends on your app’s criticality, how tolerant it is to downtime, and whether you can test updates safely before going live.

1. Rolling Update (Default)

The default and most commonly used strategy. It updates pods incrementally to avoid downtime.

strategy:
  type: RollingUpdate
  rollingUpdate:
    maxSurge: 1
    maxUnavailable: 1

Use when:

2. Recreate

Stops all old pods before starting new ones. Good for workloads that can’t run multiple instances at once.

strategy:
  type: Recreate

Use when:

3. Blue-Green Deployment (requires extra setup)

Run both old and new versions side-by-side, and switch traffic once the new version is validated.

Tools needed:

Use when:

4. Canary Deployment (requires additional tools)

Gradually route traffic to the new version in small percentages (10%, 50%, etc.).

Recommended tools:

Use when:

Rollbacks

Mistakes happen. Rollbacks let you revert to a stable version instantly:

kubectl rollout undo deployment hello-world

List history:

kubectl rollout history deployment hello-world

Best Practices for Using Deployments

1. Use Readiness Probes

Avoid sending traffic to pods that aren’t ready:

readinessProbe:
  httpGet:
    path: /
    port: 80
  initialDelaySeconds: 5
  periodSeconds: 10

2. Use Immutable Image Tags

Avoid :latest. Always tag with explicit versions:

image: nginx:1.25.1

3. Define Resource Requests and Limits

resources:
  requests:
    memory: "64Mi"
    cpu: "250m"
  limits:
    memory: "128Mi"
    cpu: "500m"

4. Separate Secrets and Config

Use ConfigMaps and Secrets instead of baking config into Deployments.

5. Avoid Label Mismatch

Ensure that selector.matchLabels matches template.metadata.labels exactly. Otherwise, your Deployment won’t manage pods correctly.

Monitoring and Observability

Check Deployment status with:

kubectl get deployment hello-world
kubectl rollout status deployment hello-world

Use tools like:

Final Thoughts

A Kubernetes Deployment is one of the most powerful tools in your toolbox. It gives you a clean way to scale, update, and recover your application with minimal disruption.

Whether you’re deploying to dev, staging, or production, the same controller handles it all. Use it well, and your updates will be safer, your rollouts cleaner, and your apps more resilient.