kubernetes / dns

Kubernetes DNS service
Apache License 2.0
930 stars 467 forks source link

kube-dns disregards stubDomains option while resolving externalName service #243

Open thockin opened 6 years ago

thockin commented 6 years ago

Was https://github.com/kubernetes/kubernetes/issues/63821 @driusha

/kind bug

What happened: I have:

When i try to resolve name "foo", i get NXDOMAIN. If i try to create externalName (ex. mail -> mail.google.com) without stubDomains, everything works.

Environment:

bradleybluebean commented 6 years ago

Also seeing this issue with kube-dns 1.14.10

bradleybluebean commented 6 years ago

One way to fix this, if you're using Kubernetes 1.9 or above, is to change the dnsPolicy of the kube-dns pod.

https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/#pods

In the authoritative template, this is set to Default.

https://github.com/kubernetes/kubernetes/blob/master/cluster/addons/dns/kube-dns/kube-dns.yaml.base#L212

This means the pod inherits the nameserver settings from the underlying node that the pod runs on. The kube-dns process then uses this nameserver to try to resolve the externalName host (foo.example.com above). If the inherited nameserver is not also able to resolve the stubdomain (example.com above), the lookup will fail. By changing the dnsPolicy to None and adding a dnsConfig, we can make the kube-dns process query the dnsmasq process (i.e., localhost) instead of an inherited nameserver.

  dnsPolicy: None
  dnsConfig:
    nameservers:
    - 127.0.0.1

Since dnsmasq won't be getting upstream nameservers from the underlying host, the kube-dns ConfigMap should also include an upstreamNameservers setting.

https://kubernetes.io/docs/tasks/administer-cluster/dns-custom-nameservers/#configure-stub-domain-and-upstream-dns-servers

chrisohaver commented 6 years ago

Since dnsmasq won't be getting upstream nameservers from the underlying host, the kube-dns ConfigMap should also include an upstreamNameservers setting.

s/should/must/ .... Without setting an upstreamNameserver, i believe you'd have an infinite lookup loop for external domain names that don't fall in a stub domain.

You can also get into trouble (loop forever) if you try to query a member of a CNAME chain loop (e.g. two external names that point at each other).

Note that moving to CoreDNS is another option. It similarly feeds CNAME targets to itself when looking them up, but does so more internally, and also has CNAME chain loop detection.

fejta-bot commented 6 years ago

Issues go stale after 90d of inactivity. Mark the issue as fresh with /remove-lifecycle stale. Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta. /lifecycle stale

fejta-bot commented 5 years ago

Stale issues rot after 30d of inactivity. Mark the issue as fresh with /remove-lifecycle rotten. Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta. /lifecycle rotten

bowei commented 5 years ago

/lifecycle frozen

jhcook-ag commented 5 years ago

/remove-lifecycle stale