We have a java application (microservice) that would be deployed on kubernetes using k8s deployment and one of the requirements is that each pod needs to know all the other pods running that application. So, in other words, we would need a way by which application layer retrieve all the pods that are part of the k8s deployment.
One custom implementation could be to have a persistant data store like database and have each of the pods send a hearbeat entry to indicate its liveness and manage the entries by listening to application lifecycle events
I know that any clustering technology satisfies this requirement. But I am looking for a minimal readymade library that does only this node discovery (and/or) management in kubernetes ?
I would suggest here to use the liveness probe and readiness probe for the POD whenever pod get join respective DNS entry will be auto-updated rather checking the liveness using custom solution.
to getting the list of all PODs IP you can use the Kubernetes service with type headless. you have to use
spec.clusterIP
as None.Example service YAMl :
from your custom solution code you have send request to kuberneets service which type if headless :
<servicename>.<namespace>.svc.cluster.local
.code example for mongo :
extra document : https://medium.com/swlh/discovering-running-pods-by-using-dns-and-headless-services-in-kubernetes-7002a50747f4