Home > Mobile >  How do we get the dns of another node in Kubernetes?
How do we get the dns of another node in Kubernetes?

Time:02-21

I have a Prometheus custom exporter which scraps the metrics off an application pod within the same node. I want to use the url (dns) and not the ip address of the target application.

Each node in the cluster will have a deployment of 1 such application and 1 exporter. How does each exporter know the dns of its corresponding application pod?

The application nodes are name my-app-1, my-app-2, ...

CodePudding user response:

so I figured that you are trying to monitor your application by letting prometheus scrape a metrics exporter for it. this metrics exporter runs in another pod on the same cluster as your application pod does, but because the metrics exporter runs on another pod, it has to find the applications pod to be able to generate the metrics for it.

I propose that you follow the kubernetes sidecar pattern and let the metrics exporter run in the same pod as your applications container. this way you avoid the need to let the metrics exporter discover your applications pod because it already knows where it runs, because containers in the same pod discover each other via localhost and their individual ports. this way, you can always predict where your application runs and you can configure your metrics exporter reliably in the same way for each application pod.

check https://kubernetes.io/docs/concepts/workloads/pods/#workload-resources-for-managing-pods to see how containers in the same pod interact with each other and how the sidecar pattern works.

  • Related