Can we use kube-dns service to resolve external domain names

1.1k Views Asked by At

As I am new to kubernetes and its DNS service, it would be great if someone helps to clarify the question below. I understand from the kubernetes documentation that kube-dns supports 'services' and 'pods' records and uses to resolve domain names of services or pods.

In a pod, few containers are running. I need those containers to resolve few external domains using kube-dns. Now, how can I use kube-dns to make containers to resolve such external domain names? Do the kubernetes provides dns server only for the resolution of domains within kubernetes? Or is there a way to customize kubernetes provided dns to resolve external domains? If so how to customize it?

It could be really helpful if someone helps to unblock my queries. Thanks in advance!!!

1

There are 1 best solutions below

1
Ramazan Kilimci On

You should take a look first pod's DNS Policy. From the documentation, I shared below.

DNS policies can be set on a per-pod basis. Currently Kubernetes supports the following pod-specific DNS policies. These policies are specified in the dnsPolicy field of a Pod Spec.

  • "Default": The Pod inherits the name resolution configuration from the node that the pods run on. See related discussion for more details.
  • "ClusterFirst": Any DNS query that does not match the configured cluster domain suffix, such as "www.kubernetes.io", is forwarded to the upstream nameserver inherited from the node. Cluster administrators may have extra stub-domain and upstream DNS servers configured. See related discussion for details on how DNS queries are handled in those cases.
  • "ClusterFirstWithHostNet": For Pods running with hostNetwork, you should explicitly set its DNS policy "ClusterFirstWithHostNet". "None": It allows a Pod to ignore DNS settings from the Kubernetes environment. All DNS settings are supposed to be provided using the dnsConfig field in the Pod Spec. See Pod's DNS config subsection below.
  • Note: "Default" is not the default DNS policy. If dnsPolicy is not explicitly specified, then "ClusterFirst" is used.

Then you can configure CoreDNS configmap forward option according to your needs. This documentation will help you to understand.

forward: Any queries that are not within the cluster domain of Kubernetes will be forwarded to predefined resolvers (/etc/resolv.conf).