Here is a full description of the problem.
# create test namespace
kubectl create namespace test
# change yaml file (image: nginx:1.16.0) and apply
kubectl -f nginx-deployment.yaml -n test apply
# 1 service, 1 deployment, 1 replicaset and 2 pods created.
kubectl get all -n test
NAME READY STATUS RESTARTS AGE
pod/my-nginx-5899859b88-8l8t8 1/1 Running 0 14m
pod/my-nginx-5899859b88-r88rr 1/1 Running 0 14m
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/my-nginx 2/2 2 2 14m
NAME DESIRED CURRENT READY AGE
replicaset.apps/my-nginx-5899859b88 2 2 2 14m
# delete resource with yaml
kubectl -f nginx-deployment.yaml -n test delete
# deployment and service are removed, replicasSet and pods are still there.
kubectl get all -n test
NAME READY STATUS RESTARTS AGE
pod/my-nginx-5899859b88-8l8t8 1/1 Running 0 15m
pod/my-nginx-5899859b88-r88rr 1/1 Running 0 15m
NAME DESIRED CURRENT READY AGE
replicaset.apps/my-nginx-5899859b88 2 2 2 15m
nb028:gl-helm-enhancements arif.hussain$
# change yaml file (image: nginx:1.17.0) and apply
kubectl -f nginx-deployment.yaml -n test apply
# 1 service, 1 deployment, 1 replicaset and 2 pods created. (old replicaSet and Pods are also there)
kps@pockube-ma01:~$ kubectl get all -n test
NAME READY STATUS RESTARTS AGE
pod/my-nginx-5899859b88-cftq5 1/1 Running 0 5m36s
pod/my-nginx-5899859b88-jv5c7 1/1 Running 0 5m36s
pod/my-nginx-6c8fb56bf7-6m8nv 1/1 Running 0 2m31s
pod/my-nginx-6c8fb56bf7-mbrpg 1/1 Running 0 2m31s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/my-nginx LoadBalancer 10.98.42.5 10.10.20.182 80:32541/TCP 2m31s
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/my-nginx 2/2 2 2 2m32s
NAME DESIRED CURRENT READY AGE
replicaset.apps/my-nginx-5899859b88 2 2 2 5m37s
replicaset.apps/my-nginx-6c8fb56bf7 2 2 2 2m32s
Problem: When we delete deployment, replicaSet and Pods are not being deleted. Hence there is on services and 4 four pods. 2 pods are on version 1.16.0 and two pods are on version 1.17.0. ReplicaSet and Pods must be deleted along with deployment.
nginx-deployment.yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-nginx
spec:
revisionHistoryLimit: 0
selector:
matchLabels:
run: my-nginx
replicas: 2
template:
metadata:
labels:
run: my-nginx
spec:
containers:
- name: my-nginx
image: nginx:1.16.0
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: my-nginx
labels:
run: my-nginx
spec:
type: LoadBalancer
ports:
- port: 80
targetPort: 80
protocol: TCP
selector:
run: my-nginx