Can Kubernetes pods that use host networking access Service resources by the service name and service port?

1/14/2020

Can Kubernetes pod that uses the host network send requests directly to a Service resource by using the service name and service port (incl. utilization of CoreDNS)? Or do I have to expose the service via nodePort on the host network?

-- Richard
hostnetwork
kubernetes
service

1 Answer

1/15/2020

If you want a pod to send requests directly to service resource you have to change pod's dnsPolicy to ClusterFirstWithHostNet. It should be used explicitly for pods running with hostNetwork: true. This way it will use cluster DNS and will be in host network.

You can check it in /etc/resolv.conf file. When you are using dnsPolicy: ClusterFirst this file is inherited by pod and uses host's DNS resolver. When you set dnsPolicy: ClusterFirstWithHostNet it will change DNS resolver to cluster's DNS.

-- KFC_
Source: StackOverflow