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

12/12/2019

We are building a rate limiter and calculate config values based on number of pods available at that moment. Is there any way to get the number of pods that are active in any instance from a java application? Also, is it possible to get the number of tasks in the case of AWS Fargate from a Java application?

-- Venkat
aws-fargate
java
kubernetes

1 Answer

12/12/2019

You need to request this info from the Kubernetes API Server. You can do it with Java with kubernetes-client/java. See InClusterClientExample

You are interested in the pods in Ready state matching a specific label that is representing (matching) your "application".

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.

-- Jonas
Source: StackOverflow