0Pricing
Docker & Kubernetes for Developers · Lesson

Understanding Kubernetes Deployments

Learn how Deployments manage the desired state of your application, enabling rolling updates and rollbacks.

Understanding Kubernetes Deployments is a free Docker & Kubernetes for Developers lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Docker & Kubernetes for Developers learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Meet Kubernetes Deployments

Welcome to the world of Kubernetes Deployments! After learning about Pods, you might wonder how to manage many identical Pods reliably.

Deployments are a powerful Kubernetes resource that helps you declare and manage the desired state of your applications.

Why Deployments are Essential

Imagine running a web server. You need multiple copies (replicas) for high availability and to handle traffic. If one crashes, you need another to take its place.

Deployments automate these tasks:

  • Self-Healing: Replaces failed Pods automatically.
  • Scaling: Easily adjust the number of Pod replicas.
  • Updates: Perform rolling updates without downtime.
  • Rollbacks: Revert to previous versions if something goes wrong.

Desired State in Action

The core concept behind a Deployment is its desired state. You tell Kubernetes what you want your application to look like, and it works to make it happen.

For example, if you say "I want 3 Nginx Pods running version 1.21," the Deployment will ensure exactly 3 Pods with Nginx 1.21 are running, even if some fail.

Deployments and ReplicaSets

Under the hood, Deployments use another Kubernetes resource called a ReplicaSet.

  • A ReplicaSet ensures a specified number of Pod replicas are running at all times.
  • When you create a Deployment, it automatically creates a ReplicaSet.
  • When you update a Deployment, it creates a new ReplicaSet and gracefully scales down the old one while scaling up the new one.

Building a Deployment Manifest

Like most Kubernetes resources, Deployments are defined using YAML. Key fields include:

  • apiVersion: apps/v1 (for Deployments)
  • kind: Deployment
  • metadata: Name, labels to identify the Deployment.
  • spec:
    • replicas: The desired number of Pods.
    • selector: How the Deployment finds its Pods (using labels).
    • template: The Pod definition (just like a standalone Pod YAML!).

Example: Nginx Deployment

Let's create a simple Deployment for Nginx. This YAML specifies 3 replicas of an Nginx web server.

You would typically save this as nginx-deployment.yaml and apply it using kubectl apply -f nginx-deployment.yaml.

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

Checking Deployment Status

Once you've applied your Deployment, you can check its status using kubectl commands:

  • kubectl get deployments: Shows a summary of your deployments.
  • kubectl get pods -l app=nginx: See the Pods managed by your Nginx deployment.
  • kubectl describe deployment nginx-deployment: Get detailed information, including events and associated ReplicaSets.

Seamless App Updates

One of the best features of Deployments is rolling updates. This allows you to update your application version without downtime.

When you change the image or configuration in your Deployment's YAML, Kubernetes:

  1. Creates new Pods with the updated version.
  2. Gradually terminates old Pods as new ones become ready.

This ensures your application remains available throughout the update process.

Performing a Rolling Update

Let's update our Nginx Deployment to a newer version. You would edit your nginx-deployment.yaml file and change the image to nginx:1.22.1.

Then, apply the changes: kubectl apply -f nginx-deployment.yaml. Kubernetes will perform a rolling update!

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.22.1 # Changed from 1.21.6
        ports:
        - containerPort: 80

Reverting Changes

Sometimes an update goes wrong. Deployments allow you to easily rollback to a previous stable version.

Kubernetes keeps a history of your Deployments' revisions. You can see this history and revert to an earlier state if needed, minimizing the impact of bad deployments.

  • kubectl rollout history deployment nginx-deployment: View past revisions.
  • kubectl rollout undo deployment nginx-deployment --to-revision=1: Revert to a specific revision.

Deployment Knowledge Check

You've learned about the power of Kubernetes Deployments!

Which of the following capabilities is NOT directly provided by a Kubernetes Deployment?

Deployment Power-Up!

Congratulations! You've successfully understood Kubernetes Deployments.

We covered:

  • What Deployments are and why they are crucial for managing applications.
  • The concept of desired state and how Deployments use ReplicaSets.
  • How to create, inspect, update, and rollback Deployments.

Next, we'll explore how to make your applications accessible using Kubernetes Services!

Frequently asked questions

Is the “Understanding Kubernetes Deployments” lesson free?

Yes — the full text of “Understanding Kubernetes Deployments” is free to read here on the web, and the Docker & Kubernetes for Developers course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Docker & Kubernetes for Developers course, upgrade to CoddyKit PRO.

What will I learn in “Understanding Kubernetes Deployments”?

Learn how Deployments manage the desired state of your application, enabling rolling updates and rollbacks. You practise Docker & Kubernetes for Developers with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Docker & Kubernetes for Developers?

No prior experience is required. Docker & Kubernetes for Developers on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Understanding Kubernetes Deployments” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Docker & Kubernetes for Developers lesson?

Yes. Every Docker & Kubernetes for Developers lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Understanding Kubernetes Deployments
  2. Exposing Applications with Services
  3. Scaling & Self-Healing Applications
  4. Rolling Updates and Rollbacks
← Back to Docker & Kubernetes for Developers