1

I have my Kubernetes client which does this

public class Example {
    public static void main(String[] args) throws IOException, ApiException{
        ApiClient client = Config.defaultClient();
        Configuration.setDefaultApiClient(client);

        CoreV1Api api = new CoreV1Api();
        V1PodList list = api.listPodForAllNamespaces(null, null, null, null, null, null, null, null, null);
        for (V1Pod item : list.getItems()) {
        String generateName = item.getMetadata().getGenerateName();
            // if generated name that I need > get IP
        }
    }
}

In above example I can get all pods per namespace, per state, and get the IP of certain pod.

My question - is there any possibility not to go over all pods in namespace, but get ONLY endpoints of certain service?

liotur
  • 809
  • 2
  • 17
  • 36
  • 2
    I think you need to be a little more precise about your question. What exactly is it that you want to achieve? There are methods like `listServiceForAllNamespaces` - you could use this and make a match via the label selectors. If you simply want to get all endpoints within a cluster, there is also `listEndpointsForAllNamespaces`. – cvoigt Feb 16 '20 at 17:27
  • 1
    My main aim is to get IP of pods, related to specific deployment, of specific service... When I am using code above - I have all list with all my pods (219 items), I need iterate on each of them in order to find specific pods by name and get IP. So my question was is there more elegant way to do that, not iterate over the all pods? But get all pods of certain service or deployment, and get those ip's... Using listServices and listEndpoinds can I do that? – liotur Feb 17 '20 at 07:16
  • @liotur You are not the only one with this problem... https://discuss.kubernetes.io/t/determining-object-relations/14534 – Akito Feb 07 '21 at 13:22
  • can't you do that with a `labelSelector`? Yeah, not ideal, but still – Eugene Nov 15 '22 at 13:07

0 Answers0