Home > Blockchain >  Is DaemonSet is available for other DaemonSet via localhost in kubernetes?
Is DaemonSet is available for other DaemonSet via localhost in kubernetes?

Time:08-15

I have two daemonsets that consists of Prometheus Server, which runs on port 9090 and API for delivering metrics on port 9000, My Question is: Can I Send Requests to my Prometheus DaemonSet via localhost from my Metrics API, (which is also is a DaemonSet), but not using local dns address like: prometheus.namespace.svc.cluster.local:port ?

CodePudding user response:

You can create a NodePort service for your Prometheus server Daemonset, K8S will assign a static port on each node, then you can access the Prometheus pods via <Node IP>:<Assigned port> (you can choose this port and you need to do that to use it in your pods).

To let the API pod (or any other pod) know the node port, you can create an environment variable with the value status.hostIP:

env:
- name: HOST_IP
  valueFrom:
    fieldRef:
      fieldPath: status.hostIP

Then in your pod, you can call the url $HOST_IP:<the port you chose>

  • Related