Docker Certified Associate Exam Course
Kubernetes
Demo Deployments
In this walkthrough, you’ll learn how to convert an existing ReplicaSet into a fully managed Deployment. Deployments offer declarative updates, rollbacks, and scaling capabilities—making them the recommended way to run replicas in production. We’ll:
- Prepare the project structure
- Create the Deployment manifest
- Apply the Deployment
- Verify the rollout and inspect resources
1. Prepare the directories and files
- From your project root, create a folder named
deployments
. - Inside
deployments
, create a file calleddeployment.yaml
.
To see what we’re building on, here’s the reference ReplicaSet we defined earlier:
# replicaset.yaml (for reference)
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: myapp-replicaset
labels:
app: myapp
spec:
selector:
matchLabels:
app: myapp
replicas: 4
template:
metadata:
labels:
app: myapp
spec:
containers:
- name: nginx
image: nginx
2. Create the Deployment manifest
Copy the spec from the ReplicaSet into deployments/deployment.yaml
, then:
- Change
kind
toDeployment
- Set
metadata.name
and labels to match your application - Adjust
replicas
to 3 (or your desired count)
# deployments/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp-deployment
labels:
tier: frontend
app: myapp
spec:
replicas: 3
selector:
matchLabels:
app: myapp
template:
metadata:
labels:
app: myapp
spec:
containers:
- name: nginx
image: nginx
Note
The selector.matchLabels
field must exactly match the labels on the Pod template. Otherwise, Kubernetes won’t know which Pods belong to this Deployment.
3. Apply the Deployment
Run:
kubectl apply -f deployments/deployment.yaml
Or, if you prefer create
:
kubectl create -f deployments/deployment.yaml
4. Verify the rollout and inspect resources
You can quickly see the status of your Deployment and its Pods:
Action | Command | Description |
---|---|---|
List Deployments | kubectl get deployments | Show READY, UP-TO-DATE, AVAILABLE columns |
List all Pods | kubectl get pods | Confirm your Pods are Running |
Describe a Deployment | kubectl describe deployment myapp-deployment | View events, strategy, and replica counts |
List all resources | kubectl get all | Get Pods, Services, Deployments, ReplicaSets |
Check the Deployment status
kubectl get deployments
Example output:
NAME READY UP-TO-DATE AVAILABLE AGE myapp-deployment 3/3 3 3 10s
List the Pods
kubectl get pods
Example output:
NAME READY STATUS RESTARTS AGE myapp-deployment-5d8fcb5b6c-abc 1/1 Running 0 30s myapp-deployment-5d8fcb5b6c-def 1/1 Running 0 30s myapp-deployment-5d8fcb5b6c-ghi 1/1 Running 0 30s
Describe the Deployment
kubectl describe deployment myapp-deployment
You’ll see details such as desired vs. available replicas, rollout strategy, and recent events:
View all objects in the namespace
kubectl get all
Example output:
NAME READY STATUS RESTARTS AGE pod/myapp-deployment-5d8fcb5b6c-abc 1/1 Running 0 1m pod/myapp-deployment-5d8fcb5b6c-def 1/1 Running 0 1m pod/myapp-deployment-5d8fcb5b6c-ghi 1/1 Running 0 1m NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 15m NAME READY UP-TO-DATE AVAILABLE AGE deployment.apps/myapp-deployment 3/3 3 3 1m NAME DESIRED CURRENT READY AGE replicaset.apps/myapp-deployment-5d8fcb5b6c 3 3 3 1m
Next Steps
To roll out updates, modify spec.template.spec.containers[].image
and run:
kubectl apply -f deployments/deployment.yaml
Then track progress with:
kubectl rollout status deployment/myapp-deployment
Links and References
Watch Video
Watch video content