I have some legacy application, which deployed on clustered environment. When one of the application nodes receives call it gets from some configuration file static list of all application nodes where application is deployed.
When all ip's collected it communicates with each app node over jmx.
Current aim is to migrate to k8s, so in this case list of application pods is dynamic and can be just stored as is. Need to implement something like service discovery.
Current thoughts is to implement some simple rest service that will run in separate pod, main aim of which is always return some list of ips (entrypoints) of application pods filtered by some predicate.
So I have few questions:
Looks you're running a clustered application, so probably you need a Headless Service combined with a StatefulSet.
With this, you will be able to reach your replicas using simple DNS like replicas-[0-9].namespace.svc
without need to extract IP addresses from endpoints query.
Define a service with a scope selector so all your special pods are included then you can list all your endpoints IP's asking the apiservice.
You can check it's working with the command.
kubectl get endpoints
After that remains how to execute this command inside your pod. That's another story. This link explain that matter https://kubernetes.io/docs/tasks/administer-cluster/access-cluster-api/#accessing-the-api-from-a-pod