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?
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.