lr-pal
lr-pal

Reputation: 389

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

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?

Upvotes: 0

Views: 592

Answers (1)

Grant David Bachman
Grant David Bachman

Reputation: 2248

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.

Upvotes: 1

Related Questions