Is it possible to configure a pod to prioritize using `hostNetwork` but still reference internal service endpoints?

6/29/2021

I have a statefulset that I need to run using the host network, purely for performance reasons. But I also want to be able to reference service-name endpoints. Is it possible to do this? ClusterFirstWithHostNet does not work because it doesn't prioritize using the host's network. The dnsConfig configuration might be promising, but I don't know how I would configure it to do what I'm asking about.

-- Mike
amazon-eks
kubernetes
kubernetes-dns

1 Answer

8/3/2021

This is a community wiki answer. Feel free to expand it.

It might be possible if the app can select random port to listen during start and change if port is busy. However, Kubernetes is not involved in the selecting port for the application.

Statefulset requires a headless service, so it doesn't have an IP and works as a set of DNS records in coredns. A record would probably contain the same IP for the replicas on the same node, but SRV record may actually provide a proper endpoint.

For further reference, please take a look at the below sources:

-- WytrzymaƂy Wiktor
Source: StackOverflow