简体   繁体   English

如何获取未链接到任何服务的Pod列表

[英]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 如何获取未链接到任何服务的Pod列表

Lets say i have pods: 可以说我有豆荚:

Svc1-green-xyz and svc1-blue-lmn Svc1-green-xyzsvc1-blue-lmn

Service svc1 is served by svc1-green-xyz . 服务svc1svc1-green-xyz With svc1-blue-lmn is a prior version of the same service and is not used. svc1-blue-lmn是同一服务的先前版本,因此未使用。

I want to select all such unused pods that are not serving any service and delete them. 我想选择所有不提供任何服务的未使用的Pod并将其删除。 How can this be done. 如何才能做到这一点。 Is there a helm command that can be used? 有可以使用的头盔命令吗?

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. Pod和服务之间并没有真正联系在一起 ,就像服务使用选择器来确定应将哪些Pod定位一样。 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. 因此,从理论上讲,您可以获取服务的所有端点的列表kubectl get endpoints ,根据IP地址进行过滤,并删除IP不在该列表中的所有Pod。 If you're going through all this, though, you're probably doing something wrong. 但是,如果您正在经历所有这些,则可能是您做错了什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM