liotur
liotur

Reputation: 923

How to collect all ip's of pods by specific name filter

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:

  1. Is it correct way to work? Any other options? (without changing legacy code)
  2. Is there any ready solution for this? If not, how can I get information about needed pods inside my rest service?

Upvotes: 0

Views: 452

Answers (2)

EnzoAT_
EnzoAT_

Reputation: 391

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

Upvotes: 2

prometherion
prometherion

Reputation: 2299

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.

Upvotes: 0

Related Questions