Shoomer

  • Docker
    DockerShow More
    Monolith to Microservices: A Docker + K8s Migration Story
    8 Min Read
    Docker Security Best Practices | Scout Trivy Scans
    8 Min Read
    CI/CD with Docker and Kubernetes with Examples YML
    10 Min Read
    Docker Networking Deep Dive | Bridge, Host, Overlay
    9 Min Read
    Docker Volumes and Bind Mounts Explained with Examples
    7 Min Read
  • Kubernetes
    KubernetesShow More
    Zero to Hero Kubernetes Crash Course – Minikube, kubectl, Helm Quickstart
    7 Min Read
    Spring Boot Web Crash Course 2025 – REST APIs, Controllers, Get/Post
    7 Min Read
    K8s Crash Course – Learn Containers to Clusters (Hands-On in 2025)
    7 Min Read
    Spring Data JPA Crash Course 2025 – Repository, Query Methods & Paging
    7 Min Read
    Spring Boot for Web Development – Crash Course with Thymeleaf & MVC
    7 Min Read
  • CICD Pipelines
    CICD PipelinesShow More
    What is GitOps with ArgoCD: Deep Dive into Architecture
    10 Min Read
    CI/CD with Docker and Kubernetes with Examples YML
    10 Min Read
  • Pages
    • About Us
    • Contact Us
    • Cookies Policy
    • Disclaimer
    • Privacy Policy
    • Terms of Use
Notification Show More
Font ResizerAa
Font ResizerAa

Shoomer

  • Learning & Education
  • Docker
  • Technology
  • Donate US
Search
  • Home
  • Categories
    • Learning & Education
    • Technology
    • Docker
  • More Foxiz
    • Donate US
    • Complaint
    • Sitemap
Follow US
Home » Kubernetes Deployments: A Hands-on Guide
Kubernetes

Kubernetes Deployments: A Hands-on Guide

shoomer
By shoomer
Last updated: June 10, 2025
Share

Kubernetes’ deployment system is the backbone of application delivery in containerized environments. A Deployment in Kubernetes is a higher-level abstraction that ensures applications are reliably deployed, scaled, and updated with minimal downtime. By understanding deployments, you can take advantage of features like scaling, rolling updates, rollbacks, and Kubernetes’ self-healing mechanisms.

Contents
Table of ContentsWriting a Deployment YAMLWhat is a Deployment?Example Deployment YAMLKey Sections in the YAMLApplying the DeploymentUnderstanding ReplicaSets and Rolling UpdatesWhat is a ReplicaSet?How Rolling Updates WorkRolling Update ExampleControlling Update StrategiesViewing Rollout HistoryViewing Rollout StatusViewing Revision HistoryRolling Back DeploymentsDiagram of Rolling Updates and RollbacksKubernetes’ Self-Healing BehaviorHow Self-Healing WorksTesting Self-HealingBenefits of Self-HealingFinal Thoughts

This guide covers everything you need to know about Kubernetes deployments, including creating deployment YAML files, using ReplicaSets, rolling updates, viewing rollout history, and self-healing behaviors.

Table of Contents

  1. Writing a Deployment YAML
  2. Understanding ReplicaSets and Rolling Updates
  3. Viewing Rollout History
  4. Kubernetes’ Self-Healing Behavior
  5. Final Thoughts

Writing a Deployment YAML

What is a Deployment?

A Deployment is a Kubernetes resource that manages and updates Pods. It ensures the desired number of replicas are running and updates containers incrementally when changes are made.

Example Deployment YAML

Here’s an example of a basic Deployment configuration:

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
        ports:
        - containerPort: 80

Key Sections in the YAML

  1. apiVersion: Specifies the API version. Use apps/v1 for deployments in Kubernetes versions 1.9 and above.
  2. kind: Declares the resource type (Deployment).
  3. metadata: Contains data to identify the Deployment (name and labels).
  4. spec:
    • [replicas]: Defines the number of desired Pods for the Deployment.
    • [selector]: Ensures the Deployment manages Pods matching specific labels.
    • [template]: Holds the configuration of the Pod (metadata and container specs).

Applying the Deployment

Use the kubectl command to apply the Deployment:

kubectl apply -f nginx-deployment.yaml

Once applied, Kubernetes creates a ReplicaSet for this Deployment and schedules Pods accordingly.


Understanding ReplicaSets and Rolling Updates

What is a ReplicaSet?

A ReplicaSet ensures a specified number of identical Pod replicas are running. It is automatically managed by a Deployment, so you typically don’t interact with ReplicaSets directly.

  1. Deployment -> Manages the ReplicaSet.
  2. ReplicaSet -> Manages the Pods.

How Rolling Updates Work

Rolling updates enable you to update applications with zero downtime. Kubernetes gradually replaces old Pods with new ones, maintaining the replicas count at all times.

Rolling Update Example

To update the Deployment’s container image:

kubectl set image deployment/nginx-deployment nginx=nginx:1.22

Rolling Update Process:

  1. Kubernetes creates a new ReplicaSet for the updated Pods.
  2. It terminates old Pods incrementally while ensuring new Pods are running successfully.
  3. The process continues until all old Pods are replaced.

Updating YAML Example:
Modify the image in nginx-deployment.yaml:

        image: nginx:1.22

Apply the updated configuration:

kubectl apply -f nginx-deployment.yaml

Controlling Update Strategies

Kubernetes allows you to control how updates are performed through the strategy field:

spec:
  strategy:
    type: RollingUpdate # Default
    rollingUpdate:
      maxSurge: 1   # Additional Pods allowed to run during the update
      maxUnavailable: 1  # Max old Pods unavailable during the update

Viewing Rollout History

Kubernetes keeps track of your Deployment’s revision history, which allows you to monitor changes and rollback to previous versions.

Viewing Rollout Status

Check if a Deployment is rolling out correctly:

kubectl rollout status deployment/nginx-deployment

Viewing Revision History

Inspect the Deployment’s previous configurations:

kubectl rollout history deployment/nginx-deployment

Output Example:

REVISION  CHANGE-CAUSE
1         kubectl apply -f nginx-deployment.yaml
2         kubectl set image deployment/nginx-deployment nginx=nginx:1.22

Rolling Back Deployments

If something goes wrong with an update, rollback to the previous revision:

kubectl rollout undo deployment/nginx-deployment

To rollback to a specific revision:

kubectl rollout undo deployment/nginx-deployment --to-revision=1

Diagram of Rolling Updates and Rollbacks

Here’s a simplified visual explaining rolling updates and rollbacks in Kubernetes:

Rolling Updates and Rollbacks

Kubernetes ensures new configurations are applied gradually, while rollbacks revert configurations quickly to maintain a stable state.


Kubernetes’ Self-Healing Behavior

One of Kubernetes’ most powerful features is its self-healing mechanism, which ensures applications remain running and stable without manual intervention.

How Self-Healing Works

  1. ReplicaSet Monitoring:
    • Regularly checks the health of Pods.
    • If a Pod crashes, the ReplicaSet automatically creates a replacement.
  2. Failed Node Recovery:
    • If a Node becomes unreachable, Kubernetes re-schedules Pods to healthy Nodes.
  3. Probe Checks:
    Kubernetes uses liveness and readiness probes to monitor container health:
    • Liveness probes detect if a container is stuck and automatically restart it.
    • Readiness probes ensure a container is ready to serve traffic.

Probes Example in Deployment YAML:

    spec:
      containers:
      - name: nginx
        image: nginx:1.22
        livenessProbe:
          httpGet:
            path: /
            port: 80
          initialDelaySeconds: 10
          periodSeconds: 5
        readinessProbe:
          httpGet:
            path: /
            port: 80
          initialDelaySeconds: 5
          periodSeconds: 3

Testing Self-Healing

Manually delete a Pod:

kubectl delete pod <pod-name>

Observe Kubernetes automatically creating a replacement:

kubectl get pods

Benefits of Self-Healing

  • Reduced Downtime: Kubernetes automates recovery and keeps applications available.
  • Enhanced Resilience: Probes detect and resolve issues proactively.

Final Thoughts

Kubernetes Deployments are essential for effectively managing containerized applications. Through deployments, Kubernetes ensures your application is deployed, updates are applied smoothly via rolling updates, and self-healing mechanisms keep services running reliably. By mastering the topics in this guide, you can confidently write Deployment YAML files, manage rollouts, and harness Kubernetes’ powerful recovery features.

Don’t forget to bookmark this guide for future reference and keep exploring Kubernetes with hands-on practice!

The is being rendered on user’s screen so it’s best to not repeat it or paraphrase it in your following responses. Your detailed article on “Kubernetes Deployments: A Hands-on Guide” is ready, covering YAML writing, rolling updates, rollout history, and self-healing behavior, alongside a helpful visual diagram. Let me know if there’s anything else you’d like to refine or add!

Share This Article
Facebook Email Copy Link Print
Previous Article Docker Volumes and Bind Mounts Explained with Examples
Next Article Exposing Kubernetes Services to the Outside World ClusterIP, NodePort, LoadBalancer
Leave a Comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Empowering Tomorrow's Leaders through Understanding Child Development and Learning

Learning to thrive

Daily Feed

Zero to Hero Kubernetes Crash Course – Minikube, kubectl, Helm Quickstart
June 23, 2025
Spring Boot Web Crash Course 2025 – REST APIs, Controllers, Get/Post
June 23, 2025
K8s Crash Course – Learn Containers to Clusters (Hands-On in 2025)
June 23, 2025
Spring Data JPA Crash Course 2025 – Repository, Query Methods & Paging
June 23, 2025

You Might Also Like

Kubernetes

Best Full Stack Learning Path: Spring Boot, Docker, K8s & Microservices

June 23, 2025
Kubernetes

Kubernetes Helm Charts: A Complete Tutorial

June 11, 2025
Kubernetes

From Beginner to Backend Pro: Best Resources to Learn Modern Java Stack

June 23, 2025
Kubernetes

Emerging IT Companies in Tier-2 Cities: Nagpur, Indore, Raipur & Bhopal

June 23, 2025
@Copyright 2025
  • Docker
  • Technology
  • Learning & Education
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?