@@ -37,27 +37,27 @@ Kubernetes DNS 在集群上调度 DNS Pod 和服务,并配置 kubelet 以告
37
37
38
38
<!--
39
39
Every Service defined in the cluster (including the DNS server itself) is
40
- assigned a DNS name. By default, a client Pod's DNS search list includes the
41
- Pod's own namespace and the cluster's default domain.
40
+ assigned a DNS name. By default, a client Pod's DNS search list includes the
41
+ Pod's own namespace and the cluster's default domain.
42
42
-->
43
43
集群中定义的每个 Service (包括 DNS 服务器自身)都被赋予一个 DNS 名称。
44
44
默认情况下,客户端 Pod 的 DNS 搜索列表会包含 Pod 自身的名字空间和集群
45
45
的默认域。
46
46
47
47
<!--
48
- ### Namespaces of Services
48
+ ### Namespaces of Services
49
49
50
- A DNS query may return different results based on the namespace of the pod making
51
- it. DNS queries that don't specify a namespace are limited to the pod's
52
- namespace. Access services in other namespaces by specifying it in the DNS query.
50
+ A DNS query may return different results based on the namespace of the pod making
51
+ it. DNS queries that don't specify a namespace are limited to the pod's
52
+ namespace. Access services in other namespaces by specifying it in the DNS query.
53
53
54
- For example, consider a pod in a `test` namespace. A `data` service is in
55
- the `prod` namespace.
54
+ For example, consider a pod in a `test` namespace. A `data` service is in
55
+ the `prod` namespace.
56
56
57
- A query for `data` returns no results, because it uses the pod's `test` namespace.
57
+ A query for `data` returns no results, because it uses the pod's `test` namespace.
58
58
59
- A query for `data.prod` returns the intended result, because it specifies the
60
- namespace.
59
+ A query for `data.prod` returns the intended result, because it specifies the
60
+ namespace.
61
61
-->
62
62
### Service 的名字空间
63
63
@@ -73,11 +73,11 @@ Pod 查询 `data` 时没有返回结果,因为使用的是 Pod 的名字空间
73
73
Pod 查询 ` data.prod ` 时则会返回预期的结果,因为查询中指定了名字空间。
74
74
75
75
<!--
76
- DNS queries may be expanded using the pod's `/etc/resolv.conf`. Kubelet
77
- sets this file for each pod. For example, a query for just `data` may be
78
- expanded to `data.test.cluster.local`. The values of the `search` option
79
- are used to expand queries. To learn more about DNS queries, see
80
- [the `resolv.conf` manual page.](https://www.man7.org/linux/man-pages/man5/resolv.conf.5.html)
76
+ DNS queries may be expanded using the pod's `/etc/resolv.conf`. Kubelet
77
+ sets this file for each pod. For example, a query for just `data` may be
78
+ expanded to `data.test.svc. cluster.local`. The values of the `search` option
79
+ are used to expand queries. To learn more about DNS queries, see
80
+ [the `resolv.conf` manual page.](https://www.man7.org/linux/man-pages/man5/resolv.conf.5.html)
81
81
-->
82
82
DNS 查询可以使用 Pod 中的 ` /etc/resolv.conf ` 展开。kubelet 会为每个 Pod
83
83
生成此文件。例如,对 ` data ` 的查询可能被展开为 ` data.test.svc.cluster.local ` 。
@@ -91,7 +91,7 @@ options ndots:5
91
91
```
92
92
93
93
<!--
94
- In summary, a pod in the _test_ namespace can successfully resolve either
94
+ In summary, a pod in the _test_ namespace can successfully resolve either
95
95
`data.prod` or `data.prod.svc.cluster.local`.
96
96
-->
97
97
概括起来,名字空间 ` test ` 中的 Pod 可以成功地解析 ` data.prod ` 或者
@@ -127,12 +127,14 @@ For more up-to-date specification, see
127
127
128
128
### A/AAAA records
129
129
130
- "Normal" (not headless) Services are assigned a DNS A or AAAA record for a name of the
131
- form `my-svc.my-namespace.svc.cluster-domain.example`. This resolves to the cluster IP
130
+ "Normal" (not headless) Services are assigned a DNS A or AAAA record,
131
+ depending on the IP family of the service, for a name of the form
132
+ `my-svc.my-namespace.svc.cluster-domain.example`. This resolves to the cluster IP
132
133
of the Service.
133
134
134
- "Headless" (without a cluster IP) Services are also assigned a DNS A record for
135
- a name of the form `my-svc.my-namespace.svc.cluster-domain.example`. Unlike normal
135
+ "Headless" (without a cluster IP) Services are also assigned a DNS A or AAAA record,
136
+ depending on the IP family of the service, for a name of the form
137
+ `my-svc.my-namespace.svc.cluster-domain.example`. Unlike normal
136
138
Services, this resolves to the set of IPs of the pods selected by the Service.
137
139
Clients are expected to consume the set or else use standard round-robin
138
140
selection from the set.
@@ -314,9 +316,9 @@ along with its IP.
314
316
Endpoints 对象可以为任何端点地址及其 IP 指定 `hostname`。
315
317
316
318
<!--
317
- Because A records are not created for Pod names, `hostname` is required for the Pod's A
319
+ Because A or AAAA records are not created for Pod names, `hostname` is required for the Pod's A or AAAA
318
320
record to be created. A Pod with no `hostname` but with `subdomain` will only create the
319
- A record for the headless service (`default-subdomain.my-namespace.svc.cluster-domain.example`),
321
+ A or AAAA record for the headless service (`default-subdomain.my-namespace.svc.cluster-domain.example`),
320
322
pointing to the Pod's IP address. Also, Pod needs to become ready in order to have a
321
323
record unless `publishNotReadyAddresses=True` is set on the Service.
322
324
-->
@@ -341,12 +343,13 @@ record unless `publishNotReadyAddresses=True` is set on the Service.
341
343
{{< feature-state for_k8s_version="v1.22" state="stable" >}}
342
344
343
345
<!--
344
- When a Pod is configured to have fully qualified domain name (FQDN), its hostname is the short hostname. For example, if you have a Pod with the fully qualified domain name `busybox-1.default-subdomain.my-namespace.svc.cluster-domain.example`, then by default the `hostname` command inside that Pod returns `busybox-1` and the `hostname -fqdn` command returns the FQDN.
346
+ When a Pod is configured to have fully qualified domain name (FQDN), its hostname is the short hostname. For example, if you have a Pod with the fully qualified domain name `busybox-1.default-subdomain.my-namespace.svc.cluster-domain.example`, then by default the `hostname` command inside that Pod returns `busybox-1` and the `hostname --fqdn` command returns the FQDN.
347
+
348
+ When you set `setHostnameAsFQDN : true` in the Pod spec, the kubelet writes the Pod's FQDN into the hostname for that Pod's namespace. In this case, both `hostname` and `hostname --fqdn` return the Pod's FQDN.
345
349
-->
346
- **前置条件**:`SetHostnameAsFQDN`
347
- [特性门控](/zh/docs/reference/command-line-tools-reference/feature-gates/)
348
- 必须在 {{< glossary_tooltip text="API 服务器" term_id="kube-apiserver" >}}
349
- 上启用。
350
+ 当 Pod 配置为具有全限定域名 (FQDN) 时,其主机名是短主机名。
351
+ 例如,如果你有一个具有完全限定域名 `busybox-1.default-subdomain.my-namespace.svc.cluster-domain.example` 的 Pod,
352
+ 则默认情况下,该 Pod 内的 `hostname` 命令返回 `busybox-1`,而 `hostname --fqdn` 命令返回 FQDN。
350
353
351
354
当你在 Pod 规约中设置了 `setHostnameAsFQDN : true` 时,kubelet 会将 Pod
352
355
的全限定域名(FQDN)作为该 Pod 的主机名记录到 Pod 所在名字空间。
@@ -392,10 +395,11 @@ following pod-specific DNS policies. These policies are specified in the
392
395
for details on how DNS queries are handled in those cases.
393
396
- " `ClusterFirstWithHostNet` " : For Pods running with hostNetwork, you should
394
397
explicitly set its DNS policy "`ClusterFirstWithHostNet`".
398
+ - Note : This is not supported on Windows. See [below](#dns-windows) for details
395
399
- " `None` " : It allows a Pod to ignore DNS settings from the Kubernetes
396
400
environment. All DNS settings are supposed to be provided using the
397
401
` dnsConfig` field in the Pod Spec.
398
- See [Pod's DNS config](#pod-s- dns-config) subsection below.
402
+ See [Pod's DNS config](#pod-dns-config) subsection below.
399
403
-->
400
404
# ## Pod 的 DNS 策略 {#pod-s-dns-policy}
401
405
@@ -411,6 +415,7 @@ DNS 策略可以逐个 Pod 来设定。目前 Kubernetes 支持以下特定 Pod
411
415
了解在这些场景中如何处理 DNS 查询的信息。
412
416
- " `ClusterFirstWithHostNet`" :对于以 hostNetwork 方式运行的 Pod,应显式设置其 DNS 策略
413
417
" `ClusterFirstWithHostNet`" 。
418
+ - 注意:这在 Windows 上不支持。 有关详细信息,请参见[下文](#dns-windows)。
414
419
- " `None` " : 此设置允许 Pod 忽略 Kubernetes 环境中的 DNS 设置。Pod 会使用其 `dnsConfig` 字段
415
420
所提供的 DNS 设置。
416
421
参见 [Pod 的 DNS 配置](#pod-dns-config)节。
@@ -450,7 +455,7 @@ spec:
450
455
` ` `
451
456
452
457
<!--
453
- # ## Pod's DNS Config
458
+ # ## Pod's DNS Config {#pod-dns-config}
454
459
455
460
{{< feature-state for_k8s_version="v1.14" state="stable" >}}
456
461
@@ -535,8 +540,7 @@ kubectl exec -it dns-example -- cat /etc/resolv.conf
535
540
<!--
536
541
The output is similar to this:
537
542
-->
538
- 输出类似于
539
-
543
+ 输出类似于:
540
544
```
541
545
nameserver fd00:79:30::a
542
546
search default.svc.cluster-domain.example svc.cluster-domain.example cluster-domain.example
@@ -565,6 +569,42 @@ a list of search domains of up to 2048 characters.
565
569
如果启用 kube-apiserver 和 kubelet 的特性门控 ` ExpandedDNSConfig ` ,Kubernetes 将可以有最多 32 个
566
570
搜索域以及一个最多 2048 个字符的搜索域列表。
567
571
572
+ <!--
573
+ ## DNS resolution on Windows nodes {#dns-windows}
574
+ -->
575
+ ## Windows 节点上的 DNS 解析 {#dns-windows}
576
+
577
+ <!--
578
+ - ClusterFirstWithHostNet is not supported for pods that run on Windows nodes.
579
+ Windows treats all names with a `.` as a FQDN and skips FQDN resolution.
580
+ - On Windows, there are multiple DNS resolvers that can be used. As these come with
581
+ slightly different behaviors, using the
582
+ [`Resolve-DNSName`](https://docs.microsoft.com/powershell/module/dnsclient/resolve-dnsname)
583
+ powershell cmdlet for name query resolutions is recommended.
584
+ - On Linux, you have a DNS suffix list, which is used after resolution of a name as fully
585
+ qualified has failed.
586
+ On Windows, you can only have 1 DNS suffix, which is the DNS suffix associated with that
587
+ pod's namespace (example: `mydns.svc.cluster.local`). Windows can resolve FQDNs, services,
588
+ or network name which can be resolved with this single suffix. For example, a pod spawned
589
+ in the `default` namespace, will have the DNS suffix `default.svc.cluster.local`.
590
+ Inside a Windows pod, you can resolve both `kubernetes.default.svc.cluster.local`
591
+ and `kubernetes`, but not the partially qualified names (`kubernetes.default` or
592
+ `kubernetes.default.svc`).
593
+ -->
594
+ - 在 Windows 节点上运行的 Pod 不支持 ClusterFirstWithHostNet。
595
+ Windows 将所有带有 ` . ` 的名字视为 FQDN 并跳过 FQDN 解析。
596
+ - 在 Windows 上,可以使用多个 DNS 解析器。由于这些解析器的行为上略有不同,建议使用
597
+ [ ` Resolve-DNSName ` ] ( https://docs.microsoft.com/powershell/module/dnsclient/resolve-dnsname )
598
+ 这个 PowerShell cmdlet 进行名字查询解析。
599
+ - 在 Linux 上,你会有一个 DNS 后缀列表,在全限定域名解析失败之后会使用这里的后缀。
600
+ 在 Windows 上,你只能有 1 个 DNS 后缀,即与 Pod 的命名空间关联的 DNS
601
+ 后缀(例如:` mydns.svc.cluster.local ` )。 Windows 可以解析能够使用此唯一后缀解析的
602
+ FQDN、服务与网络名字。
603
+ 例如,在 ` default ` 命名空间中产生的某个 Pod 将具有 DNS 后缀 ` default.svc.cluster.local ` 。
604
+ 在 Windows Pod 中,你可以解析 ` kubernetes.default.svc.cluster.local `
605
+ 和 ` kubernetes ` ,但无法解析部分限定名称(` kubernetes.default ` 或
606
+ ` kubernetes.default.svc ` )。
607
+
568
608
## {{% heading "whatsnext" %}}
569
609
570
610
<!--
0 commit comments