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

8/12/2019

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?

-- lr-pal
kubernetes
kubernetes-helm
odk
openshift
redhat

1 Answer

8/12/2019

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
Source: StackOverflow