0

How to get list of pods that are not linked to any service

Lets say i have pods:

Svc1-green-xyz and svc1-blue-lmn

Service svc1 is served by svc1-green-xyz. With svc1-blue-lmn is a prior version of the same service and is not used.

I want to select all such unused pods that are not serving any service and delete them. How can this be done. Is there a helm command that can be used?

PjoterS
  • 12,841
  • 1
  • 22
  • 54
lr-pal
  • 339
  • 2
  • 6
  • 20
  • Deleting specific services is not a feature of helm. helm can manage entities tagged as a "release" which will include the services it has deployed previously. So if this service was part of an old release that was removed, helm should have done that. – Matt Aug 13 '19 at 00:26

1 Answers1

1

This is possible, but very hacky. Pods and services aren't really linked, so much as services use selectors to determine which pods they should target. What's really happening is that services keep track of a list of endpoints they need to forward traffic to. So, you could theoretically get a list of all endpoints for a service kubectl get endpoints, filter based on IP address, and remove all pods whose IPs are not in that list. If you're going through all this, though, you're probably doing something wrong.

Grant David Bachman
  • 2,158
  • 3
  • 21
  • 32
  • It might be easier looking up the pods to be removed with the service selectors as the APIs/kubectl support querying that way... Still going to end up with some parsing and filtering either way. – Matt Aug 13 '19 at 01:23