Understanding Kubernetes Deployments on Azure AKS
Deployments are a fundamental Kubernetes resource that provides declarative updates for Pods and ReplicaSets. A Deployment manages a desired state for your applications, ensuring that a specified number of Pod replicas are running and available at all times.
Core Concepts of Deployments
A Deployment consists of the following key components:
- ReplicaSet: A ReplicaSet ensures that a specified number of pod replicas are running at any given time. Deployments manage ReplicaSets.
- Pods: The smallest deployable units in Kubernetes, representing a group of one or more containers.
- Desired State: You define the desired state of your application (e.g., the container image, number of replicas) in a Deployment manifest. Kubernetes controllers work to achieve this state.
Creating a Deployment
You can create a Deployment using a YAML manifest file. Here's a simple example for deploying a basic Nginx web server:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3 # Specifies the desired number of pods
selector:
matchLabels:
app: nginx # Selects pods with this label
template:
metadata:
labels:
app: nginx # Labels applied to the pods created by this deployment
spec:
containers:
- name: nginx
image: nginx:1.21.6 # The container image to use
ports:
- containerPort: 80 # The port the container listens on
To apply this manifest, save it to a file (e.g., nginx-deployment.yaml
) and run:
kubectl apply -f nginx-deployment.yaml
Deployment Strategies
Deployments support different update strategies to manage application rollouts:
1. Rolling Update (Default)
This strategy gradually updates Pods by deleting old Pods and creating new ones. It ensures that there are always a specified number of available Pods during the update. You can control the pace of the rollout using maxUnavailable
and maxSurge
parameters.
spec:
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 25% # Max pods unavailable during rollout
maxSurge: 25% # Max pods that can be created over the desired amount
2. Recreate
This strategy terminates all existing Pods before creating new ones. This can lead to downtime.
spec:
strategy:
type: Recreate
Managing Deployments
You can use kubectl
commands to manage your Deployments:
- View Deployments:
kubectl get deployments
- View Pods managed by a Deployment:
kubectl get pods -l app=nginx
- Scale a Deployment:
kubectl scale deployment nginx-deployment --replicas=5
- Rollout History:
kubectl rollout history deployment nginx-deployment
- Rollback to a previous version:
kubectl rollout undo deployment nginx-deployment --to-revision=2
- Describe a Deployment:
kubectl describe deployment nginx-deployment

Key Benefits of Using Deployments
- Declarative Updates: Define your desired application state, and Kubernetes handles the rest.
- Rollback Capabilities: Easily revert to previous versions of your application if an update causes issues.
- Zero Downtime Deployments: Strategies like Rolling Update ensure your application remains available during updates.
- Automated Scaling and Self-Healing: Deployments, in conjunction with ReplicaSets, ensure the desired number of replicas are always running.
Conclusion
Deployments are a cornerstone of managing applications on Azure Kubernetes Service. By leveraging Deployments, you can achieve robust, reliable, and scalable application deployments with ease.