0Pricing
DevOps Bootcamp · Lesson

Understanding Deployments

Learn how Deployments automate the management of Pods and ReplicaSets for stateless applications.

Understanding Deployments is a free DevOps Bootcamp 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 DevOps Bootcamp learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

What are Deployments?

Welcome! In Kubernetes, managing applications means managing their Pods. But directly managing individual Pods or even ReplicaSets can get complex.

A Deployment is a higher-level object that simplifies managing stateless applications. Think of it as your application's manager.

  • It defines the desired state for your application.
  • It ensures that state is maintained, even if Pods fail.
  • It automates updates and rollbacks.

Why Use Deployments?

Deployments bring significant advantages for running applications reliably in Kubernetes:

  • Automated Management: They handle the creation, scaling, and deletion of Pods.
  • Self-Healing: If a Pod crashes, the Deployment automatically replaces it to maintain the desired number of replicas.
  • Declarative Updates: You describe the desired new state, and the Deployment figures out how to get there (e.g., rolling out new versions).

They are the recommended way to manage stateless applications.

Deployment's Core Role

At its heart, a Deployment manages ReplicaSets. A ReplicaSet's job is to ensure a specified number of Pod replicas are running at all times.

So, a Deployment uses ReplicaSets to achieve its goal: to ensure your application has the correct number of healthy Pods running according to your definition.

This abstraction makes it much easier to define and maintain the lifecycle of your application.

Anatomy of a Deployment YAML

Like most Kubernetes objects, Deployments are defined using YAML. Here are the key sections you'll typically find:

  • apiVersion and kind: Identifies the object type (Deployment).
  • metadata: Name, labels, etc. for the Deployment itself.
  • spec: The core definition, including:
    • replicas: The desired number of Pods.
    • selector: How the Deployment finds the Pods it manages.
    • template: The blueprint for the Pods to be created.

The Pod Template

The template field within a Deployment's spec is incredibly important. It's essentially a complete Pod definition.

Any Pods created by this Deployment will use this template. This means you define:

  • The container images to use.
  • Ports to expose.
  • Environment variables.
  • Resource requests and limits.
  • And more!

Changes to this template trigger updates to your application.

Creating a Simple Deployment

Let's define a Deployment for a simple Nginx web server. We want 3 replicas.

Notice how the selector.matchLabels must match the template.metadata.labels. This tells the Deployment which Pods it owns.

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

Applying the Deployment

To create this Deployment in your Kubernetes cluster (e.g., Minikube), you use the kubectl apply command. Save the YAML above as nginx-deployment.yaml.

kubectl will create the Deployment object. The Deployment controller then sees this object and takes action, creating a ReplicaSet, which then creates the 3 Nginx Pods.

kubectl apply -f nginx-deployment.yaml

Inspecting Your Deployment

Once applied, you can check the status of your Deployment and the Pods it manages:

  • kubectl get deployments: Shows your Deployment.
  • kubectl get replicasets: Shows the ReplicaSet created by the Deployment.
  • kubectl get pods -l app=nginx: Shows the Pods managed by the Deployment (via its label selector).
  • kubectl describe deployment my-nginx-deployment: Provides detailed information about the Deployment, including events.
kubectl get deployments
kubectl get pods -l app=nginx
kubectl describe deployment my-nginx-deployment

Maintaining Desired State

One of the most powerful features of Deployments is their ability to maintain the desired state. If you defined replicas: 3, the Deployment will ensure 3 Pods are always running.

Try deleting one of the Nginx Pods manually (kubectl delete pod <pod-name>). You'll see the Deployment quickly create a new one to replace it! This is self-healing in action.

Quick Check

A Deployment is primarily used to manage which type of application?

Recap: Understanding Deployments

Great job! You've taken your first steps with Kubernetes Deployments.

  • Deployments are high-level objects for managing stateless applications.
  • They automate the creation, scaling, and self-healing of Pods by managing ReplicaSets.
  • You define a Deployment using a YAML manifest, specifying the desired number of replicas and a template for the Pods.
  • kubectl apply creates the Deployment, and kubectl get/describe help you monitor it.

Next, we'll dive deeper into ReplicaSets and how they guarantee your desired Pod count!

Frequently asked questions

Is the “Understanding Deployments” lesson free?

Yes — the full text of “Understanding Deployments” is free to read here on the web, and the DevOps Bootcamp 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 DevOps Bootcamp course, upgrade to CoddyKit PRO.

What will I learn in “Understanding Deployments”?

Learn how Deployments automate the management of Pods and ReplicaSets for stateless applications. You practise DevOps Bootcamp 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 DevOps Bootcamp?

No prior experience is required. DevOps Bootcamp 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 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 DevOps Bootcamp lesson?

Yes. Every DevOps Bootcamp 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 Deployments
  2. Scaling Applications with ReplicaSets
  3. Rolling Updates and Rollbacks
  4. Deployment Strategies: Blue-Green and Canary
← Back to DevOps Bootcamp