A Deployment controller object controls a ReplicaSet where as a ReplicaSet controls Pods

When we create a deployment controller it creates a ReplicaSet as well
When we create a ReplicaSet, it creates Pods according to the no. of Pod replicas specified

Let’s start with a clean environment with zero Pods

[root@master cka]# kubectl get deployment
No resources found.
[root@master cka]# kubectl get rs
No resources found.
[root@master cka]# kubectl get pods
No resources found.

Let’s define a deployment configuration

NewImage

Let’s create the deployment
[root@master cka]# kubectl create -f ex7.yml
deployment.apps/deployment7 created

To check the status of creation
[root@master cka]# kubectl rollout status deployment.v1.apps/deployment7
deployment "deployment7" successfully rolled out

To see the list of Deployments
[root@master cka]# kubectl get deployment
NAME READY UP-TO-DATE AVAILABLE AGE
deployment7 3/3 3 3 17s

This is the ReplicaSet that the Deployment has created
[root@master cka]# kubectl get rs
NAME DESIRED CURRENT READY AGE
deployment7-5f4f9cf99d 3 3 3 75s

These are the Pods that the ReplicaSet has created
[root@master cka]# kubectl get pods
NAME READY STATUS RESTARTS AGE
deployment7-5f4f9cf99d-2s4wn 1/1 Running 0 113s
deployment7-5f4f9cf99d-69xfl 1/1 Running 0 113s
deployment7-5f4f9cf99d-d5wbl 1/1 Running 0 113s

If we delete the Pods, new replacement Pods will be automatically recreated by the ReplicaSet
[root@master cka]# kubectl delete pods --all
pod "deployment7-5f4f9cf99d-2s4wn" deleted
pod "deployment7-5f4f9cf99d-69xfl" deleted
pod "deployment7-5f4f9cf99d-d5wbl" deleted

[root@master cka]# kubectl get pods
NAME READY STATUS RESTARTS AGE
deployment7-5f4f9cf99d-9dlwn 1/1 Running 0 21s
deployment7-5f4f9cf99d-xtn7z 1/1 Running 0 21s
deployment7-5f4f9cf99d-xvvdz 1/1 Running 0 21s

Similarly if we delete the ReplicaSet, a new replacement will be automatically created by the deployment controller
[root@master cka]# kubectl delete rs --all
replicaset.extensions "deployment7-5f4f9cf99d" deleted

[root@master cka]# kubectl get replicaset
NAME DESIRED CURRENT READY AGE
deployment7-5f4f9cf99d 3 3 3 11s

Let’s try to change the container image to nginx
NewImage

Let’s check the existing Pod names
[root@master cka]# kubectl get pods
NAME READY STATUS RESTARTS AGE
deployment7-5f4f9cf99d-2dqj8 1/1 Running 0 8m33s
deployment7-5f4f9cf99d-p2rwf 1/1 Running 0 8m33s
deployment7-5f4f9cf99d-x2tzs 1/1 Running 0 8m33s

Let’s apply this configuration to the Deployment
[root@master cka]# kubectl apply -f ex7.yml
Warning: kubectl apply should be used on resource created by either kubectl create --save-config or kubectl apply
deployment.apps/deployment7 configured

The Deployment has deleted the old ReplicaSet and created a new ReplicaSet and as a result old Pods are replaced with new ones as the container image has changed, this is evident from the Pod names
The string after the deployment name (75b544658b)helps identifying the change in ReplicaSet name and the string after the last hyphen (ex: 6blpw) helps identifying the Pod name
[root@master cka]# kubectl get pods
NAME READY STATUS RESTARTS AGE
deployment7-75b544658b-6blpw 1/1 Running 0 25s
deployment7-75b544658b-84tcb 1/1 Running 0 19s
deployment7-75b544658b-wk459 1/1 Running 0 16s

Deleting a Deployment will delete the associated ReplicaSet and all the Pods controlled by the ReplicaSet

kubectl delete deployment/deployment7

[root@master cka]# kubectl get deployment
No resources found.
[root@master cka]# kubectl get rs
No resources found.
[root@master cka]# kubectl get pods
No resources found.

--end-of-post--