Kubernetes: How to delete a deployment but keeping it’s associated containers running.

When we use the --cascade=false option in kubernetes along with kubectl delete , we can delete a replication controller without removing it associated pods or resource managed by the controller.

Jacksparrow:~ babatundeolu-isa$ kubectl get deploy
NAME      DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
nginx     2         2         2            2           47m
Jacksparrow:~ babatundeolu-isa$ kubectl get pods
NAME                     READY     STATUS    RESTARTS   AGE
nginx-65899c769f-r7tgm   1/1       Running   0          47m
nginx-65899c769f-svf8d   1/1       Running   0          47m
Jacksparrow:~ babatundeolu-isa$ kubectl delete deploy nginx --cascade=false
deployment.extensions "nginx" deleted
Jacksparrow:~ babatundeolu-isa$ kubectl get pods
NAME                     READY     STATUS    RESTARTS   AGE
nginx-65899c769f-r7tgm   1/1       Running   0          47m
nginx-65899c769f-svf8d   1/1       Running   0          47m

as you can see, the deployment has been deleted and he associated pods still remain in the cluster.

Leave a Reply

Your email address will not be published. Required fields are marked *