What is a Deployment?
- Docker & Kubernetes course
- Intermediate
- Lesson 25/82
- 4 min
Learn that a Deployment manages Pods.
What is a Deployment?
A Deployment is the standard way to run stateless applications. You give the desired pod template and replica count; the Deployment creates a ReplicaSet, and the ReplicaSet creates the pods. When you change the image, the Deployment opens a new ReplicaSet and gradually replaces the old pods with new ones.
Deployment (web)
└── ReplicaSet (web-7c5b9f6d8)
├── Pod web-7c5b9f6d8-abcde
├── Pod web-7c5b9f6d8-fghij
└── Pod web-7c5b9f6d8-klmnoSeeing the hierarchy
To list the three levels together and see the ownership chain:
$ kubectl get deploy,rs,pods -l app=web
NAME READY UP-TO-DATE AVAILABLE
deployment.apps/web 3/3 3 3
NAME DESIRED CURRENT READY
replicaset.apps/web-7c5b9f6d8 3 3 3
$ kubectl get pod web-7c5b9f6d8-abcde -o jsonpath='{.metadata.ownerReferences[0].kind}'
ReplicaSetPractice Create a deployment
Write two commands: create an api deployment with 2 replicas using the api:1.0 image; then list the deployments, ReplicaSets and pods labelled app=api in one command.
Starter code
# buraya yazSample solution
kubectl create deployment api --image=api:1.0 --replicas=2
kubectl get deploy,rs,pods -l app=apiExpected output
deployment.apps/api created NAME READY UP-TO-DATE AVAILABLE AGE deployment.apps/api 2/2 2 2 12s NAME DESIRED CURRENT READY AGE replicaset.apps/api-5d8f7c9b4 2 2 2 12s NAME READY STATUS RESTARTS AGE pod/api-5d8f7c9b4-qrstu 1/1 Running 0 12s pod/api-5d8f7c9b4-vwxyz 1/1 Running 0 12s
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 In the pod name web-7c5b9f6d8-abcde, what does 7c5b9f6d8 show?
- The node name
- The image version
- A random number
- The ReplicaSet ID derived from a hash of the pod template Correct answer
Explanation: When the template changes, a new hash means a new ReplicaSet.
2 List the deployments, ReplicaSets and pods together.
kubectl get deploy,____,pods -l app=web
kubectl get deploy,rs,pods -l app=web
Explanation: rs is the abbreviation of replicasets.
3 Match.
| Term | Meaning |
|---|---|
Deployment |
Manages versions and updates |
ReplicaSet |
Keeps the replica count |
Pod |
Runs the containers |
ownerReferences |
Ownership chain |