Understanding Kubernetes Deployment — A Beginner’s Guide
A Deep Dive into Kubernetes Deployments

Find Complete mind map of A Beginner’s Guide to Kubernetes
In Kubernetes, a Deployment is a resource object that defines the desired state of an application or workload. It provides a way to declaratively manage the deployment and scaling of containerized applications.
Deployments help to manage the lifecycle of replica sets and pods. They ensure that the desired number of replicas are always available and in the desired state.
They also help to simplify updates and rollbacks to the application.
Check out “Understanding Kubernetes — A Beginner’s Guide” for the comprehensive series🚀
Why Do We Need Deployments in Kubernetes?
In a Kubernetes cluster, Pods are ephemeral and can be replaced by newer instances as they become available. This replacement can be caused by various factors, such as scaling the application, node failure, or pod failure. Deployments help to ensure that the desired number of replica pods is always available and that the replacement of pods is done gracefully, without any downtime or interruption to the application.
Creating a Deployment in Kubernetes

You can create a Deployment in Kubernetes either imperatively (using command-line tools like kubectl
) or declaratively (using a YAML file).
You can create a deployment in Kubernetes using either the imperative or declarative approach.
Imperative Approach
To create a deployment using the imperative approach, you can use the kubectl create deployment
command. Here's an example:
kubectl create deployment nginx --image=nginx:latest
This command creates a deployment named “nginx” with the latest version of the Nginx image.
Declarative Approach
To create a deployment using the declarative approach, you can create a YAML file that defines the desired state of the deployment. Here’s an example:
apiVersion: apps/v1
kind: Deployment
metadata:
name: example-deployment
spec:
replicas: 3
selector:
matchLabels:
app: example
template:
metadata:
labels:
app: example
spec:
containers:
- name: example-container
image: nginx:latest
ports:
- containerPort: 80
In this example, we are creating a Deployment named example-deployment
with three replicas of an nginx container. The selector
field in the spec ensures that the replicas are selected based on the labels specified in the matchLabels
field. The template
field specifies the pod template that will be used to create the replicas. Each replica Pod in a ReplicaSet is created from the same Pod template, which defines the configuration of the container(s) that run in the Pod.
How Deployment works with ReplicaSets and Pods ?
When you create a Deployment, it creates a ReplicaSet to manage the desired number of replicas specified in the spec.
The ReplicaSet then creates and manages the Pods that match the labels specified in the matchLabels
field.
Deployments help to ensure that the application is always available and in the desired state.
They achieve this by monitoring the state of the replicas and performing actions such as creating new replicas, updating existing replicas, or scaling up or down the number of replicas based on the desired state.
Benefits of using Deployment
There are several benefits of using Deployments in Kubernetes:
- Simplified updates and rollbacks: Deployments provide a way to update the application without downtime by rolling out new replicas gradually while rolling back any failed replicas. This helps to ensure that the application remains available and responsive during the update process.
- Self-healing: Deployments help to ensure that the application is always available and in the desired state by automatically replacing failed replicas with new ones.
- Scaling: Deployments make it easy to scale up or down the number of replicas based on demand. This helps to ensure that the application can handle increased traffic or load without downtime.
- Versioning: Deployments provide a way to manage different versions of the application by creating different deployments with different versions. This helps to simplify testing and rollback of changes.
Overall, Deployments are a key feature of Kubernetes that provide a way to declaratively manage the deployment and scaling of containerized applications.
They help to ensure that the application is always available and in the desired state, and they simplify updates and rollbacks to the application.
🔔 Stay tuned or subscribe to my series: “Understanding Kubernetes — A Beginner’s Guide” to explore everything about Kubernetes. 🚀
📝 Have questions or suggestions? Leave a comment or message me through Medium. Let’s connect!
Thank you for your support! 🌟