0
0
Kubernetesdevops~10 mins

Creating Deployments with YAML in Kubernetes - Visual Walkthrough

Choose your learning style9 modes available
Process Flow - Creating Deployments with YAML
Write YAML file
kubectl apply -f file.yaml
Kubernetes API Server receives
Deployment object created
ReplicaSet created
Pods created and running
Deployment ready
The flow starts with writing a YAML file, then applying it with kubectl, which creates a Deployment object. Kubernetes then creates ReplicaSets and Pods until the Deployment is ready.
Execution Sample
Kubernetes
apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp-deployment
spec:
  replicas: 2
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
      - name: myapp-container
        image: nginx:1.21
This YAML defines a Deployment named 'myapp-deployment' with 2 replicas running nginx version 1.21.
Process Table
StepActionResource CreatedState ChangeOutput/Status
1kubectl apply -f deployment.yamlDeployment 'myapp-deployment'Deployment object created in clusterdeployment.apps/myapp-deployment created
2Kubernetes creates ReplicaSetReplicaSet for 'myapp-deployment'ReplicaSet object createdreplicaset.apps/myapp-deployment-xxxxx created
3ReplicaSet creates Pods2 Pods with label app=myappPods created and startingpod/myapp-deployment-xxxxx-1 created pod/myapp-deployment-xxxxx-2 created
4Pods start runningPods status changesPods become Readypod/myapp-deployment-xxxxx-1 Ready pod/myapp-deployment-xxxxx-2 Ready
5Deployment status updatedDeployment reports ready replicasDeployment ready with 2 replicasdeployment.apps/myapp-deployment available
💡 Deployment is ready when all replicas are running and available.
Status Tracker
ResourceInitialAfter Step 1After Step 2After Step 3After Step 4Final
DeploymentNoneCreatedCreatedCreatedCreatedReady with 2 replicas
ReplicaSetNoneNoneCreatedCreatedCreatedActive with 2 pods
PodsNoneNoneNoneCreated (2 pods)Running (2 pods)Ready (2 pods)
Key Moments - 3 Insights
Why does the Deployment create a ReplicaSet before Pods?
The Deployment manages ReplicaSets to control Pods. As shown in execution_table step 2, the ReplicaSet is created first to manage the desired number of Pods.
What does 'kubectl apply' do with the YAML file?
It sends the YAML to Kubernetes API Server to create or update resources. Execution_table step 1 shows the Deployment object creation after applying the YAML.
When is the Deployment considered ready?
When all Pods are running and available. Execution_table step 5 shows the Deployment status updated to ready with 2 replicas.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what resource is created immediately after applying the YAML file?
ADeployment
BPods
CReplicaSet
DService
💡 Hint
Check execution_table step 1 for the resource created by 'kubectl apply'.
At which step do the Pods become Ready according to the execution_table?
AStep 2
BStep 4
CStep 3
DStep 5
💡 Hint
Look at the 'Pods start running' action in execution_table step 4.
If the replicas count in YAML is changed from 2 to 3, what changes in the variable_tracker for Pods?
APods remain at 2 throughout
BPods increase to 3 after Step 1
CPods increase to 3 after Step 3
DPods increase to 3 after Step 5
💡 Hint
Pods are created by ReplicaSet after Step 2, see variable_tracker Pods row.
Concept Snapshot
Creating a Deployment with YAML:
- Write a YAML file with apiVersion, kind: Deployment, metadata, and spec.
- Use 'kubectl apply -f file.yaml' to create the Deployment.
- Kubernetes creates a ReplicaSet to manage Pods.
- Pods are created and run the specified container image.
- Deployment is ready when all replicas are running.
Full Transcript
To create a Deployment in Kubernetes, you write a YAML file describing the Deployment resource, including the number of replicas and container details. Then you run 'kubectl apply -f' with that YAML file. Kubernetes creates the Deployment object, which in turn creates a ReplicaSet. The ReplicaSet manages the Pods, creating the specified number of Pods running the container image. When all Pods are running and ready, the Deployment status updates to ready. This process ensures your application runs with the desired number of instances.