简体   繁体   English

有没有办法在 Java 中获取活动 Kubernetes Pod 的数量

[英]Is there a way to get number of active Kubernetes Pods in Java

We are building a rate limiter and calculate config values based on number of pods available at that moment.我们正在构建一个速率限制器,并根据当时可用的 pod 数量计算配置值。 Is there any way to get the number of pods that are active in any instance from a java application?有什么方法可以从 Java 应用程序中获取在任何实例中处于活动状态的 Pod 数量? Also, is it possible to get the number of tasks in the case of AWS Fargate from a Java application?另外,是否可以从 Java 应用程序获取 AWS Fargate 的任务数量?

You need to request this info from the Kubernetes API Server.您需要从 Kubernetes API 服务器请求此信息。 You can do it with Java with kubernetes-client/java .您可以通过kubernetes-client/java使用 Java 来实现 See InClusterClientExample请参见InClusterClient 示例

You are interested in the pods in Ready state matching a specific label that is representing (matching) your "application".您对处于Ready状态的 Pod 与代表(匹配)您的“应用程序”的特定label相匹配感兴趣。

If you are only interesting in the number of Ready pods for a specific application, you can also request the Deployment directly instead of pods be a label.如果您只对特定应用程序的Ready pod数量感兴趣,您也可以直接请求Deployment而不是 pod 是标签。

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

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