$ kubectl create namespace test
namespace/test created


$ kubectl -n test apply -f - << EOF
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
EOF

The output would be :-
deployment.apps/my-nginx created
service/my-nginx created


$ kubectl get all -n test
NAME                           READY   STATUS    RESTARTS   AGE
pod/my-nginx-6db65dfc4-dxtwl   1/1     Running   0          10s
pod/my-nginx-6db65dfc4-zvzlr   1/1     Running   0          10s

NAME               TYPE           CLUSTER-IP    EXTERNAL-IP   PORT(S)        AGE
service/my-nginx   LoadBalancer   10.0.192.30   <pending>     80:30608/TCP   9s

NAME                       READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/my-nginx   2/2     2            2           10s

NAME                                 DESIRED   CURRENT   READY   AGE
replicaset.apps/my-nginx-6db65dfc4   2         2         2       10s


$ kubectl -n test delete -f - << EOF
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
EOF

The output would be :-
deployment.apps "my-nginx" deleted
service "my-nginx" deleted


$ kubectl get all -n test
No resources found in test namespace.


$ kubectl delete ns test
namespace "test" deleted



[LINKS]
https://discuss.kubernetes.io/t/when-kubernetes-deployment-is-deleted-replicasets-are-not-being-deleted/24625
