skip to Main Content

What’s the best way to get the IP addresses of the other kubernetes pods on a local network?

Currently, I’m using the following command and parsing the output: kubectl describe pods.

Unfortunately, the command above often takes many seconds to complete (at least 3, and often 30+ seconds) and if a number of requests happen nearly simultaneously, I get 503 style errors. I’ve built a caching system around this command to cache the IP addresses on the local pod, but when a 10 or so pods wake up and need to create this cache, there is a large delay and often many errors. I feel like I’m doing something wrong. Getting the IP addresses of other pods on a network seems like it should be a straightforward process. So what’s the best way to get them?

For added details, I’m using Google’s kubernetes system on their container engine. Running a standard Ubuntu image.


Context: To add context, I’m trying to put together a shared memcached between the pods on the cluster. To do that, they all need to know eachother’s IP address. If there’s an easier way to link pods/instances for the purposes of memcached, that would also be helpful.

2

Answers


  1. Have you tried

    kubectl get pods -o wide
    

    This also returns IP addresses of the pods. Since this does not return ALL information describe returns, this might be faster.

    Login or Signup to reply.
  2. For your described use case you should be using services. A headless service would allow you to reference them with my-svc.my-namespace.svc.cluster.local. This assumes you don’t need to know individual nodes, only how to reach one of them, as it will round robin between them.

    If you do need to have fixed network identities in your cluster attached to the pods you can setup a StatefulSet and reference them with: app-0.my-svc.my-namespace.svc.cluster.local, app-1.my-svc.my-namespace.svc.cluster.local and so on.

    You should never need to contact specific pod ip’s in other ways, specially since they can be rescheduled at any time and have their IPs changed.

    For your use case specifically, it might be easier to just use the memcache helm chart, which supports a cluster in a StatefulSet: https://github.com/kubernetes/charts/tree/master/stable/memcached

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search