0
votes

We run the following command in k8s

kubectl deployment our-deployment-name

And this seems to delete the deployment called our-deployment-name fine. However we also want to delete the replicasets and pods that below to 'our-deployment-name'.

Reading the documents it is not clear if the default behaviour should cascade delete replicasets and pods. Does anybody know how do delete the deployment and all related replicasets and pods? Or do I have to manually delete all of those resources as well?

When I delete a deployment I have an orphaned replicaset like this...

dev@jenkins:~$ kubectl describe replicaset.apps/wc-892-74697d58d9
Name:           wc-892-74697d58d9
Namespace:      default
Selector:       app=wc-892,pod-template-hash=74697d58d9
Labels:         app=wc-892
                pod-template-hash=74697d58d9
Annotations:    deployment.kubernetes.io/desired-replicas: 1
                deployment.kubernetes.io/max-replicas: 2
                deployment.kubernetes.io/revision: 1
Controlled By:  Deployment/wc-892
Replicas:       1 current / 1 desired
Pods Status:    1 Running / 0 Waiting / 0 Succeeded / 0 Failed
Pod Template:
  Labels:  app=wc-892
           pod-template-hash=74697d58d9
  Containers:
   wc-892:
    Image:      registry.digitalocean.com/galatea/wastecoordinator-wc-892:1
    Port:       8080/TCP
    Host Port:  0/TCP
    Limits:
      memory:           800Mi
    Environment:        <none>
    Mounts:             <none>
  Volumes:              <none>
  Priority Class Name:  dev-lower-priority
Events:
  Type    Reason            Age   From                   Message
  ----    ------            ----  ----                   -------
  Normal  SuccessfulCreate  11m   replicaset-controller  Created pod: wc-892-74697d58d9-jtj9t
dev@jenkins:~$
3
It should delete every replicasets & pods belong to it. did you change the labels in deployment? - Shahriar
What do you mean did I change labels? - benstpierre
Are there any related errors in controllermanager? kubectl logs -n kube-system kube-controller-manager. - Matt

3 Answers

0
votes

As you can see in the replicaset Controlled By: Deployment/wc-892 which means deleting the deployment wc-892 should delete the replicaset which would in turn delete the pods with label app=wc-892

0
votes

First get the deployments which you want to delete

kubectl get deployments

and delete the deployment which wou want

kubectl delete deployment yourdeploymentname

This will delete the replicaset and pods associted with it.

-1
votes

kubectl delete deployment <deployment> will delete all ReplicaSets associated with the deployment AND the active pods associated with those ReplicaSets.

The controller-manager or API Server might be having issue handling the delete request. So I'd advise looking at those logs to verify.

Note, it's possible the older replicasets are attached to something else in the namespace? Try listing and look at the metadata. Using kubectl describe rs <rs> or kubectl get rs -o yaml