How can an application (inside a pod) reach out to daemonSet pod running with hostNetwork:true
without using status.hostIP
from env var? Thought of using dnsPolicy: ClusterFirstWithHostNet
in the daemonSet but could not resolve DNS. The caller pod does not know the daemonSet pod name or IP.
According to the official Kubernetes documentation
Some possible patterns for communicating with Pods in a DaemonSet are:
- Push: Pods in the DaemonSet are configured to send updates to another service, such as a stats database. They do not have clients.
- NodeIP and Known Port: Pods in the DaemonSet can use a hostPort, so that the pods are reachable via the node IPs. Clients know the list of node IPs somehow, and know the port by convention.
- DNS: Create a headless service with the same pod selector, and then discover DaemonSets using the endpoints resource or retrieve multiple A records from DNS.
- Service: Create a service with the same Pod selector, and use the service to reach a daemon on a random node. (No way to reach specific node.)
This thread may be also helpful.