Deployment

A Deployment in Kubernetes is a higher-level controller that manages ReplicaSets and provides declarative updates for Pods and applications.

In simpler terms →
👉 Deployment = Automated management + scaling + rolling updates for your Pods.


⚙️ Definition

A Deployment defines the desired state of your application (like number of replicas, container image, etc.), and Kubernetes automatically manages that state — creating or updating Pods as needed.


🧩 Core Features

  1. Declarative Updates — You describe what you want (e.g., 5 replicas, new image), and Kubernetes makes it so.
  2. Rolling Updates — Deploy new versions of your app gradually without downtime.
  3. Rollback — Easily revert to a previous stable version if something goes wrong.
  4. Self-Healing — Automatically replaces crashed or unresponsive Pods.
  5. Scaling — Adjust replicas manually or via autoscaling.

🧾 Example YAML

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

Explanation:

  • replicas: 3 → ensures 3 Pods are running.
  • selector.matchLabels → connects the Deployment to its Pods.
  • template → defines the Pod specification (containers, images, ports, etc.).

🔄 How It Works Internally

  1. You create or update a Deployment.
  2. The Deployment creates a ReplicaSet to manage the Pods.
  3. During an update:
    • A new ReplicaSet is created with the new configuration.
    • Pods from the old ReplicaSet are gradually replaced with Pods from the new one.
  4. Kubernetes ensures zero downtime through this rolling update process.
  5. You can rollback to a previous ReplicaSet if needed.

📊 Typical Workflow

  1. Deploy your application with a Deployment.
  2. Scale it (e.g., kubectl scale deployment myapp-deployment --replicas=5).
  3. Update the image version (e.g., kubectl set image deployment myapp-deployment nginx-container=nginx:1.26).
  4. Monitor rollout status (kubectl rollout status deployment myapp-deployment).
  5. Rollback if necessary (kubectl rollout undo deployment myapp-deployment).

🧠 Key Differences

ConceptDescriptionManages
PodSmallest deployable unit (one or more containers)Containers
ReplicaSetEnsures the desired number of PodsPods
DeploymentManages ReplicaSets and enables rolling updatesReplicaSets

🚀 Common Use Cases

  • Deploying stateless applications (e.g., web servers, APIs).
  • Performing zero-downtime application upgrades.
  • Scaling workloads up/down based on demand.
  • Managing multiple versions of an application safely.

Leave a Reply