A Deployment provides declarative updates for Pods and ReplicaSets, enabling application scaling, rolling updates, and rollbacks. It maintains the desired state of applications and ensures that the right number of Pods are always running.
Deployments use a default RollingUpdate strategy for seamless version transitions but can also use the Recreate strategy for disruptive updates. When a Deployment is updated (e.g., changing the image version), it creates a new ReplicaSet while gradually replacing Pods from the old ReplicaSet.
Example YAML manifest:
apiVersion: apps/v1kind: Deploymentmetadata: name: nginx-deployment labels: app: nginx-deploymentspec: replicas: 3 selector: matchLabels: app: nginx-deployment template: metadata: labels: app: nginx-deployment spec: containers: - name: nginx image: nginx:1.20.2 ports: - containerPort: 80Key commands:
kubectl create -f def-deploy.yamlkubectl create deployment nginx-deployment \--image=nginx:1.20.2 --port=80 --replicas=3
kubectl create deployment nginx-deployment \--image=nginx:1.20.2 --port=80 --replicas=3 \--dry-run=client -o yaml > nginx-deploy.yaml
kubectl create -f nginx-deploy.yamlkubectl create -f nginx-deploy.jsonDeployment updates result in new ReplicaSets being created (e.g., updating from image 1.20.2 to 1.21.5), transitioning Pods from one revision to the next through a rolling update process.