Delete All ReplicaSet Pods

How to Delete all Pods in ReplicaSet

by | 12.10.2021 | Tutorial

I recently got into Cloud Native Foundations Scholarship Program by Udacity, and with that, my day to day interaction with Kubernetes increased. The exposure is good because I am learning Kubernetes and patching problems and sharing some tricks to solve my problems here.

One of them is to delete all pods in a ReplicaSet. I went through many StackOverflow questions with one line finalizers that would do the job instantly, but it was all hit and try with 20 commands to find the one. In addition to that, pasting random finalizers which you don’t understand on the terminal is not recommended.  

Also, even if I am a massive fan of googling stuff out, I get tired of googling the same queries ten times.

Delete all pods in ReplicaSet (My Approach)

The purpose of a ReplicaSet is to keep a consistent number of Pods are always running. As a result, you can scale the number of pods (declaratively/imperatively) to anything that your server can manage.

Theoretically, you can scale your ReplicaSet to zero pods, and that’s what I did using the subcommand scale by scaling the number of pods to Zero on the ReplicaSet.

The following imperative command helped me to remove all the pods in a ReplicaSet without deleting the ReplicaSet.

kubectl scale rs/new-replica-set --replicas=0
 Delete All ReplicaSet Pods
Delete All ReplicaSet Pods (Quick Snap)

Here new-replica-set would be replaced by the ReplicaSet whose pods you want to delete. You can deploy new pods via the ReplicaSet using the above command with the value in --replicas as your desire number of pods or via declarative way using kubectl edit replicaset new-replica-set .

Delete ReplicaSet + Pods

This is a standard and straightforward approach if you want to delete the ReplicaSet as well as the pods together by using subcommand delete with new-replica-set replaced with the name of ReplicaSet you want to delete.

kubectl delete rs new-replica-set

Thanks for reading this post! Feel free to share it with your friends/colleagues if this was of any help! Consider subscribing to our newsletter if you want Tutorials and Articles delivered to your inbox weekly.

Read more from us here:

Happy Learning!


The DevOps Awareness Program

Subscribe to the newsletter

Join 100+ cloud native ethusiasts


Join the community Slack

Discuss all things Kubernetes, DevOps and Cloud Native

Related articles6

Delete namespace stuck in Terminating State

Delete namespace stuck in Terminating State

Deleting a namespace is just a line of command, but when it is stuck in a Terminating state it starts to give you a headache. In this small tutorial, we would go on to how to delete a namespace that’s stuck.  What’s is a stuck Namespace? Whenever you find your...

How to Install Portainer on Remote Server ft. VSCode?

How to Install Portainer on Remote Server ft. VSCode?

Portainer is one of the most popular and trusted GUI for managing Docker, Swarms, ACIs and Kubernetes. The company boasts on its’ website for having 500K users, and there’s no doubt to the number looking at how easy it makes managing the tools. This post goes on the...

How To Install Docker on Ubuntu 20.04?

How To Install Docker on Ubuntu 20.04?

Docker is an open-source tool that makes managing application processes in containers much easier. Containers allow you to run your programmes in separate processes with their own resources. Containers are comparable to virtual machines, except they're more portable,...