DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Node and Capacity Spillover: What Happens When Kubernetes Runs Out of Room
  • Zero-Downtime Deployments for Java Apps on Kubernetes
  • Kubernetes Scheduler Plugins: Optimizing AI/ML Workloads
  • Why Your "Stateless" Services Are Lying to You

Trending

  • Introduction to Error Prone: How to Catch Bugs at Compile Time
  • Searching Kafka Without an Index: Lessons From Building Message Search for Kafdrop
  • Beyond Manual Mapping: AI-Orchestrated Governance for Hybrid Cloud
  • Build a Voice Assistant With Gemini Live API

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

How to Delete all Pods in a ReplicaSet

ReplicaSet keeps a constant number of pods running. Learn how to delete pods quickly without complicated commands imperatively!

By 
Hrittik Roy
·
Nov. 27, 21 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
20.7K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

I recently got into the Cloud Native Foundations Scholarship Program by Udacity, and with that, my day-to-day interaction with Kubernetes has 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 trial and error with 20 commands to find the one. In addition to that, pasting random finalizers that 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 10 times.

Delete All Pods in ReplicaSet (My Approach)

The purpose of a ReplicaSet is to keep a consistent number of Pods 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 0 on the ReplicaSet.

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

kubectl scale rs/new-replica-set --replicas=0

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 desired 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 the ReplicaSet you want to delete.

kubectl delete rs new-replica-set

Happy Learning!

pods

Published at DZone with permission of Hrittik Roy. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Node and Capacity Spillover: What Happens When Kubernetes Runs Out of Room
  • Zero-Downtime Deployments for Java Apps on Kubernetes
  • Kubernetes Scheduler Plugins: Optimizing AI/ML Workloads
  • Why Your "Stateless" Services Are Lying to You

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook