Skip to content

Commit f1e80a9

Browse files
authored
Merge pull request #26405 from geoffcline/gdc-patch-4
update guidance on DNS resolution for services
2 parents 7639bfb + 5ead4bf commit f1e80a9

File tree

2 files changed

+67
-12
lines changed

2 files changed

+67
-12
lines changed

content/en/docs/concepts/services-networking/dns-pod-service.md

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ content_type: concept
77
weight: 20
88
---
99
<!-- overview -->
10-
This page provides an overview of DNS support by Kubernetes.
11-
10+
Kubernetes creates DNS records for services and pods. You can contact
11+
services with consistent DNS names instead of IP addresses.
1212

1313
<!-- body -->
1414

@@ -18,19 +18,47 @@ Kubernetes DNS schedules a DNS Pod and Service on the cluster, and configures
1818
the kubelets to tell individual containers to use the DNS Service's IP to
1919
resolve DNS names.
2020

21-
### What things get DNS names?
22-
2321
Every Service defined in the cluster (including the DNS server itself) is
24-
assigned a DNS name. By default, a client Pod's DNS search list will
25-
include the Pod's own namespace and the cluster's default domain. This is best
26-
illustrated by example:
22+
assigned a DNS name. By default, a client Pod's DNS search list includes the
23+
Pod's own namespace and the cluster's default domain.
24+
25+
### Namespaces of Services
26+
27+
A DNS query may return different results based on the namespace of the pod making
28+
it. DNS queries that don't specify a namespace are limited to the pod's
29+
namespace. Access services in other namespaces by specifying it in the DNS query.
30+
31+
For example, consider a pod in a `test` namespace. A `data` service is in
32+
the `prod` namespace.
33+
34+
A query for `data` returns no results, because it uses the pod's `test` namespace.
35+
36+
A query for `data.prod` returns the intended result, because it specifies the
37+
namespace.
38+
39+
DNS queries may be expanded using the pod's `/etc/resolv.conf`. Kubelet
40+
sets this file for each pod. For example, a query for just `data` may be
41+
expanded to `data.test.cluster.local`. The values of the `search` option
42+
are used to expand queries. To learn more about DNS queries, see
43+
[the `resolv.conf` manual page.](https://www.man7.org/linux/man-pages/man5/resolv.conf.5.html)
44+
45+
```
46+
nameserver 10.32.0.10
47+
search <namespace>.svc.cluster.local svc.cluster.local cluster.local
48+
options ndots:5
49+
```
50+
51+
In summary, a pod in the _test_ namespace can successfully resolve either
52+
`data.prod` or `data.prod.cluster.local`.
53+
54+
### DNS Records
55+
56+
What objects get DNS records?
2757

28-
Assume a Service named `foo` in the Kubernetes namespace `bar`. A Pod running
29-
in namespace `bar` can look up this service by querying a DNS service for
30-
`foo`. A Pod running in namespace `quux` can look up this service by doing a
31-
DNS query for `foo.bar`.
58+
1. Services
59+
2. Pods
3260

33-
The following sections detail the supported record types and layout that is
61+
The following sections detail the supported DNS record types and layout that is
3462
supported. Any other layout or names or queries that happen to work are
3563
considered implementation details and are subject to change without warning.
3664
For more up-to-date specification, see

content/en/docs/tasks/administer-cluster/dns-debugging-resolution.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ kube-dns.
2525

2626
{{< codenew file="admin/dns/dnsutils.yaml" >}}
2727

28+
{{< note >}}
29+
This example creates a pod in the `default` namespace. DNS name resolution for
30+
services depends on the namespace of the pod. For more information, review
31+
[DNS for Services and Pods](/docs/concepts/services-networking/dns-pod-service/#what-things-get-dns-names).
32+
{{< /note >}}
33+
2834
Use that manifest to create a Pod:
2935

3036
```shell
@@ -247,6 +253,27 @@ linux/amd64, go1.10.3, 2e322f6
247253
172.17.0.18:41675 - [07/Sep/2018:15:29:11 +0000] 59925 "A IN kubernetes.default.svc.cluster.local. udp 54 false 512" NOERROR qr,aa,rd,ra 106 0.000066649s
248254
```
249255

256+
### Are you in the right namespace for the service?
257+
258+
DNS queries that don't specify a namespace are limited to the pod's
259+
namespace.
260+
261+
If the namespace of the pod and service differ, the DNS query must include
262+
the namespace of the service.
263+
264+
This query is limited to the pod's namespace:
265+
```shell
266+
kubectl exec -i -t dnsutils -- nslookup <service-name>
267+
```
268+
269+
This query specifies the namespace:
270+
```shell
271+
kubectl exec -i -t dnsutils -- nslookup <service-name>.<namespace>
272+
```
273+
274+
To learn more about name resolution, see
275+
[DNS for Services and Pods](/docs/concepts/services-networking/dns-pod-service/#what-things-get-dns-names).
276+
250277
## Known issues
251278

252279
Some Linux distributions (e.g. Ubuntu) use a local DNS resolver by default (systemd-resolved).

0 commit comments

Comments
 (0)