0
0
Kubernetesdevops~10 mins

Deployment as higher-level abstraction in Kubernetes - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Deployment as higher-level abstraction
Write Deployment YAML
kubectl apply -f deployment.yaml
Kubernetes API Server receives request
Deployment Controller checks desired state
ReplicaSet created/updated
ReplicaSet manages Pods
Pods created/updated to match desired replicas
Deployment status updated
User sees updated app running
This flow shows how a Deployment YAML is applied, triggering Kubernetes controllers to create ReplicaSets and Pods to match the desired state.
Execution Sample
Kubernetes
apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp-deployment
spec:
  replicas: 3
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
      - name: myapp-container
        image: nginx:1.21
This Deployment YAML defines 3 replicas of an nginx container labeled 'myapp'.
Process Table
StepActionKubernetes ObjectState ChangeResult
1Apply Deployment YAMLDeployment 'myapp-deployment'Deployment object created in clusterDeployment registered with desired replicas=3
2Deployment Controller checks DeploymentDeployment 'myapp-deployment'ReplicaSet created with selector matching DeploymentReplicaSet created to manage Pods
3ReplicaSet creates PodsReplicaSet for 'myapp-deployment'3 Pods created with label app=myappPods starting containers nginx:1.21
4Pods become ReadyPods managed by ReplicaSetPods report Ready statusDeployment status updated to available=3
5User accesses appPodsPods serve trafficApp running with 3 replicas
6Update Deployment (e.g., image version)Deployment 'myapp-deployment'Deployment spec updatedRolling update triggered
7ReplicaSet creates new PodsNew ReplicaSetNew Pods created with updated imageOld Pods terminated gradually
8New Pods become ReadyNew PodsReady status reportedDeployment status updated with new version
9ExitDeploymentDesired state matches actual stateDeployment stable with updated Pods
💡 Deployment reaches desired state with all Pods ready and updated
Status Tracker
VariableStartAfter Step 2After Step 3After Step 4After Step 7Final
Deployment replicasundefined33333
ReplicaSet Pods count00333 (old) + 3 (new)3 (new)
Pods statusnonenonestartingReadystarting (new), terminating (old)Ready (new)
Deployment statusnonecreatedcreating Podsavailable=3rolling updateavailable=3
Key Moments - 3 Insights
Why does the Deployment create a ReplicaSet instead of Pods directly?
The Deployment manages ReplicaSets to handle rolling updates and scaling smoothly. The ReplicaSet ensures the correct number of Pods are running. See execution_table rows 2 and 3.
What happens during a rolling update when the Deployment spec changes?
A new ReplicaSet is created with the updated spec. New Pods start while old Pods are terminated gradually to avoid downtime. See execution_table rows 6 to 8.
How does Kubernetes know when the Deployment is stable?
When the number of Ready Pods matches the desired replicas and the Deployment status reflects this, it is stable. See execution_table row 9.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, at which step are the Pods first created?
AStep 2
BStep 3
CStep 4
DStep 1
💡 Hint
Check the 'Action' and 'State Change' columns in execution_table row 3.
According to variable_tracker, what is the Pods status after Step 4?
AReady
Bnone
Cstarting
Dterminating
💡 Hint
Look at the 'Pods status' row under 'After Step 4' in variable_tracker.
If the Deployment spec is updated, what happens next according to the execution_table?
APods are deleted immediately
BDeployment is deleted
CA rolling update is triggered with new Pods created
DNothing changes
💡 Hint
See execution_table rows 6 to 8 describing update and rolling update.
Concept Snapshot
Deployment is a Kubernetes object that manages ReplicaSets and Pods.
You define desired state in Deployment YAML (replicas, template).
Applying Deployment creates/updates ReplicaSet which manages Pods.
Deployment enables rolling updates and scaling.
Pods are created/updated to match Deployment's desired replicas.
Deployment status shows current state of Pods and rollout.
Full Transcript
A Kubernetes Deployment is a higher-level object that manages ReplicaSets and Pods to keep your app running as you want. You write a Deployment YAML file specifying how many copies (replicas) of your app you want and what container image to use. When you apply this YAML with kubectl, Kubernetes creates a Deployment object. The Deployment controller then creates a ReplicaSet that matches the Deployment's selector. The ReplicaSet creates the Pods that run your containers. The Deployment keeps checking that the number of Pods matches the desired replicas. If you update the Deployment, Kubernetes performs a rolling update by creating new Pods with the updated spec and gradually removing old Pods. This process ensures your app stays available during updates. The Deployment status shows when all Pods are ready and the update is complete.