Skip to content

Commit 1b2dc89

Browse files
Eason1118tengqm
andauthored
[zh-cn] sync dns-pod-service.md (#49662)
* [zh-cn] sync dns-pod-service.md * Update content/zh-cn/docs/concepts/services-networking/dns-pod-service.md Co-authored-by: Qiming Teng <[email protected]> --------- Co-authored-by: Qiming Teng <[email protected]>
1 parent 4ff30d1 commit 1b2dc89

File tree

1 file changed

+83
-55
lines changed

1 file changed

+83
-55
lines changed

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

Lines changed: 83 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -31,35 +31,35 @@ Kubernetes 为 Service 和 Pod 创建 DNS 记录。
3131

3232
<!--
3333
Kubernetes publishes information about Pods and Services which is used
34-
to program DNS. Kubelet configures Pods' DNS so that running containers
35-
can lookup Services by name rather than IP.
34+
to program DNS. kubelet configures Pods' DNS so that running containers
35+
can look up Services by name rather than IP.
3636
-->
3737
Kubernetes 发布有关 Pod 和 Service 的信息,用于配置 DNS。
38-
Kubelet 配置 Pod 的 DNS,使运行中的容器可以通过名称而不是 IP 地址来查找服务
38+
kubelet 配置 Pod 的 DNS,使运行中的容器可以通过名称而非 IP 查找 Service
3939

4040
<!--
4141
Services defined in the cluster are assigned DNS names. By default, a
4242
client Pod's DNS search list includes the Pod's own namespace and the
43-
cluster's default domain.
43+
cluster's default domain.
4444
-->
4545

4646
集群中定义的 Service 被赋予 DNS 名称。
4747
默认情况下,客户端 Pod 的 DNS 搜索列表包括 Pod 所在的命名空间和集群的默认域名。
4848

4949
<!--
50-
### Namespaces of Services
50+
### Namespaces of Services
5151
52-
A DNS query may return different results based on the namespace of the Pod making
53-
it. DNS queries that don't specify a namespace are limited to the Pod's
54-
namespace. Access Services in other namespaces by specifying it in the DNS query.
52+
A DNS query may return different results based on the namespace of the Pod making
53+
it. DNS queries that don't specify a namespace are limited to the Pod's
54+
namespace. Access Services in other namespaces by specifying it in the DNS query.
5555
5656
For example, consider a Pod in a `test` namespace. A `data` Service is in
57-
the `prod` namespace.
57+
the `prod` namespace.
5858
59-
A query for `data` returns no results, because it uses the Pod's `test` namespace.
59+
A query for `data` returns no results, because it uses the Pod's `test` namespace.
6060
61-
A query for `data.prod` returns the intended result, because it specifies the
62-
namespace.
61+
A query for `data.prod` returns the intended result, because it specifies the
62+
namespace.
6363
-->
6464
### Service 的命名空间 {#namespaces-of-services}
6565

@@ -74,11 +74,11 @@ Pod 查询 `data` 时没有返回结果,因为使用的是 Pod 所在的 `test
7474
Pod 查询 `data.prod` 时则会返回预期的结果,因为查询中指定了命名空间。
7575

7676
<!--
77-
DNS queries may be expanded using the Pod's `/etc/resolv.conf`. Kubelet
78-
configures this file for each Pod. For example, a query for just `data` may be
79-
expanded to `data.test.svc.cluster.local`. The values of the `search` option
80-
are used to expand queries. To learn more about DNS queries, see
81-
[the `resolv.conf` manual page.](https://www.man7.org/linux/man-pages/man5/resolv.conf.5.html)
77+
DNS queries may be expanded using the Pod's `/etc/resolv.conf`. kubelet
78+
configures this file for each Pod. For example, a query for just `data` may be
79+
expanded to `data.test.svc.cluster.local`. The values of the `search` option
80+
are used to expand queries. To learn more about DNS queries, see
81+
[the `resolv.conf` manual page.](https://www.man7.org/linux/man-pages/man5/resolv.conf.5.html).
8282
-->
8383
DNS 查询可以使用 Pod 中的 `/etc/resolv.conf` 展开。
8484
Kubelet 为每个 Pod 配置此文件。
@@ -93,7 +93,7 @@ options ndots:5
9393
```
9494

9595
<!--
96-
In summary, a Pod in the _test_ namespace can successfully resolve either
96+
In summary, a Pod in the _test_ namespace can successfully resolve either
9797
`data.prod` or `data.prod.svc.cluster.local`.
9898
-->
9999
概括起来,命名空间 _test_ 中的 Pod 可以成功地解析 `data.prod` 或者
@@ -103,6 +103,10 @@ In summary, a Pod in the _test_ namespace can successfully resolve either
103103
### DNS Records
104104
105105
What objects get DNS records?
106+
107+
1. Services
108+
1. Pods
109+
106110
-->
107111
### DNS 记录 {#dns-records}
108112

@@ -113,7 +117,7 @@ What objects get DNS records?
113117

114118
<!--
115119
The following sections detail the supported DNS record types and layout that is
116-
supported. Any other layout or names or queries that happen to work are
120+
supported. Any other layout or names or queries that happen to work are
117121
considered implementation details and are subject to change without warning.
118122
For more up-to-date specification, see
119123
[Kubernetes DNS-Based Service Discovery](https://github.com/kubernetes/dns/blob/master/docs/specification.md).
@@ -134,9 +138,9 @@ depending on the IP family or families of the Service, with a name of the form
134138
`my-svc.my-namespace.svc.cluster-domain.example`. This resolves to the cluster IP
135139
of the Service.
136140
137-
[Headless Services](/docs/concepts/services-networking/service/#headless-services)
141+
[Headless Services](/docs/concepts/services-networking/service/#headless-services)
138142
(without a cluster IP) are also assigned DNS A and/or AAAA records,
139-
with a name of the form `my-svc.my-namespace.svc.cluster-domain.example`. Unlike normal
143+
with a name of the form `my-svc.my-namespace.svc.cluster-domain.example`. Unlike normal
140144
Services, this resolves to the set of IPs of all of the Pods selected by the Service.
141145
Clients are expected to consume the set or else use standard round-robin
142146
selection from the set.
@@ -158,43 +162,54 @@ selection from the set.
158162
### SRV records
159163
160164
SRV Records are created for named ports that are part of normal or headless
161-
services. For each named port, the SRV record has the form
162-
`_port-name._port-protocol.my-svc.my-namespace.svc.cluster-domain.example`.
163-
For a regular Service, this resolves to the port number and the domain name:
164-
`my-svc.my-namespace.svc.cluster-domain.example`.
165-
For a headless Service, this resolves to multiple answers, one for each Pod
166-
that is backing the Service, and contains the port number and the domain name of the Pod
167-
of the form `hostname.my-svc.my-namespace.svc.cluster-domain.example`.
165+
services.
166+
167+
- For each named port, the SRV record has the form
168+
`_port-name._port-protocol.my-svc.my-namespace.svc.cluster-domain.example`.
169+
- For a regular Service, this resolves to the port number and the domain name:
170+
`my-svc.my-namespace.svc.cluster-domain.example`.
171+
- For a headless Service, this resolves to multiple answers, one for each Pod
172+
that is backing the Service, and contains the port number and the domain name of the Pod
173+
of the form `hostname.my-svc.my-namespace.svc.cluster-domain.example`.
174+
168175
-->
169176
#### SRV 记录 {#srv-records}
170177

171-
Kubernetes 根据普通 Service 或无头 Service
172-
中的命名端口创建 SRV 记录。每个命名端口,
173-
SRV 记录格式为 `_port-name._port-protocol.my-svc.my-namespace.svc.cluster-domain.example`
174-
对于普通 Service,该记录会被解析成端口号和域名:`my-svc.my-namespace.svc.cluster-domain.example`
175-
对于无头 Service,该记录会被解析成多个结果,及该服务的每个后端 Pod 各一个 SRV 记录,
176-
其中包含 Pod 端口号和格式为 `hostname.my-svc.my-namespace.svc.cluster-domain.example`
177-
的域名。
178+
Kubernetes 根据普通 Service 或无头 Service 中的命名端口创建 SRV 记录。
179+
180+
- 每个命名端口,SRV 记录的格式:`_port-name._port-protocol.my-svc.my-namespace.svc.cluster-domain.example`
181+
- 对于普通 Service,该记录会被解析成端口号和域名:`my-svc.my-namespace.svc.cluster-domain.example`
182+
- 对于无头 Service,该记录会被解析成多个结果,即该 Service 的每个后端 Pod 各一个 SRV 记录,
183+
其中包含 Pod 端口号和域名,格式为:`hostname.my-svc.my-namespace.svc.cluster-domain.example`
178184

179185
<!--
180-
## Pods-->
186+
## Pods
187+
-->
181188
## Pod
182189

183190
<!--
184191
### A/AAAA records
185192
186-
Kube-DNS versions, prior to the implementation of the [DNS specification](https://github.com/kubernetes/dns/blob/master/docs/specification.md), had the following DNS resolution:
193+
Kube-DNS versions, prior to the implementation of the
194+
[DNS specification](https://github.com/kubernetes/dns/blob/master/docs/specification.md),
195+
had the following DNS resolution:
187196
188-
`pod-ipv4-address.my-namespace.pod.cluster-domain.example`.
197+
```
198+
pod-ipv4-address.my-namespace.pod.cluster-domain.example
199+
```
189200
190201
For example, if a Pod in the `default` namespace has the IP address 172.17.0.3,
191202
and the domain name for your cluster is `cluster.local`, then the Pod has a DNS name:
192203
193-
`172-17-0-3.default.pod.cluster.local`.
204+
```
205+
172-17-0-3.default.pod.cluster.local
206+
```
194207
195-
Any Pods exposed by a Service have the following DNS resolution available:
208+
Some cluster DNS mechanisms, like [CoreDNS](https://coredns.io/), also provide `A` records for:
196209
197-
`pod-ipv4-address.service-name.my-namespace.svc.cluster-domain.example`.
210+
```
211+
<pod-ipv4-address>.<service-name>.<my-namespace>.svc.<cluster-domain.example>
212+
```
198213
-->
199214
### A/AAAA 记录 {#a-aaaa-records}
200215

@@ -208,9 +223,9 @@ Kube-DNS 版本使用以下 DNS 解析:
208223

209224
`172-17-0-3.default.pod.cluster.local`
210225

211-
通过 Service 暴露出来的所有 Pod 都会有如下 DNS 解析名称可用
226+
一些集群 DNS 机制(如 [CoreDNS](https://coredns.io/))还会为以下内容提供 `A` 记录
212227

213-
`pod-ipv4-address.service-name.my-namespace.svc.cluster-domain.example`
228+
`<pod-ipv4-address>.<service-name>.<my-namespace>.svc.<cluster-domain.example>.`
214229

215230
<!--
216231
### Pod's hostname and subdomain fields
@@ -325,15 +340,15 @@ the DNS hostname for any endpoint addresses, along with its IP.
325340
{{<glossary_tooltip term_id="endpoint-slice" text="EndpointSlice">}}
326341
对象可以为任何端点地址及其 IP 指定 `hostname`。
327342

343+
{{< note >}}
328344
<!--
329-
Because A and AAAA records are not created for Pod names, `hostname` is required for the Pod's A or AAAA
330-
record to be created. A Pod with no `hostname` but with `subdomain` will only create the
345+
A and AAAA records are not created for Pod names since `hostname` is missing for the Pod.
346+
A Pod with no `hostname` but with `subdomain` will only create the
331347
A or AAAA record for the headless Service (`busybox-subdomain.my-namespace.svc.cluster-domain.example`),
332348
pointing to the Pods' IP addresses. Also, the Pod needs to be ready in order to have a
333349
record unless `publishNotReadyAddresses=True` is set on the Service.
334350
-->
335-
{{< note >}}
336-
由于 A 和 AAAA 记录不是基于 Pod 名称创建,因此需要设置了 `hostname` 才会生成 Pod 的 A 或 AAAA 记录。
351+
由于 Pod 缺少 `hostname`,所以没有为这些 Pod 名称创建 A 和 AAAA 记录。
337352
没有设置 `hostname` 但设置了 `subdomain` 的 Pod 只会为
338353
无头 Service 创建 A 或 AAAA 记录(`busybox-subdomain.my-namespace.svc.cluster-domain.example`)
339354
指向 Pod 的 IP 地址。
@@ -351,8 +366,8 @@ record unless `publishNotReadyAddresses=True` is set on the Service.
351366
<!--
352367
When a Pod is configured to have fully qualified domain name (FQDN), its
353368
hostname is the short hostname. For example, if you have a Pod with the fully
354-
qualified domain name `busybox-1.busybox-subdomain.my-namespace.svc.cluster-domain.example`,
355-
then by default the `hostname` command inside that Pod returns `busybox-1` and the
369+
qualified domain name `busybox-1.busybox-subdomain.my-namespace.svc.cluster-domain.example`,
370+
then by default the `hostname` command inside that Pod returns `busybox-1` and the
356371
`hostname --fqdn` command returns the FQDN.
357372

358373
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.
@@ -369,7 +384,13 @@ When you set `setHostnameAsFQDN: true` in the Pod spec, the kubelet writes the P
369384
<!--
370385
In Linux, the hostname field of the kernel (the `nodename` field of `struct utsname`) is limited to 64 characters.
371386

372-
If a Pod enables this feature and its FQDN is longer than 64 character, it will fail to start. The Pod will remain in `Pending` status (`ContainerCreating` as seen by `kubectl`) generating error events, such as Failed to construct FQDN from Pod hostname and cluster domain, FQDN `long-FQDN` is too long (64 characters is the max, 70 characters requested). One way of improving user experience for this scenario is to create an [admission webhook controller](/docs/reference/access-authn-authz/extensible-admission-controllers/#what-are-admission-webhooks) to control FQDN size when users create top level objects, for example, Deployment.
387+
If a Pod enables this feature and its FQDN is longer than 64 character, it will fail to start.
388+
The Pod will remain in `Pending` status (`ContainerCreating` as seen by `kubectl`) generating
389+
error events, such as Failed to construct FQDN from Pod hostname and cluster domain,
390+
FQDN `long-FQDN` is too long (64 characters is the max, 70 characters requested).
391+
One way of improving user experience for this scenario is to create an
392+
[admission webhook controller](/docs/reference/access-authn-authz/extensible-admission-controllers/#what-are-admission-webhooks)
393+
to control FQDN size when users create top level objects, for example, Deployment.
373394
-->
374395
在 Linux 中,内核的主机名字段(`struct utsname` 的 `nodename` 字段)限定最多 64 个字符。
375396

@@ -405,7 +426,11 @@ following Pod-specific DNS policies. These policies are specified in the
405426
explicitly set its DNS policy to "`ClusterFirstWithHostNet`". Otherwise, Pods
406427
running with hostNetwork and `"ClusterFirst"` will fallback to the behavior
407428
of the `"Default"` policy.
408-
- Note: This is not supported on Windows. See [below](#dns-windows) for details
429+
430+
{{< note >}}
431+
This is not supported on Windows. See [below](#dns-windows) for details.
432+
{{< /note >}}
433+
409434
- "`None`": It allows a Pod to ignore DNS settings from the Kubernetes
410435
environment. All DNS settings are supposed to be provided using the
411436
`dnsConfig` field in the Pod Spec.
@@ -425,7 +450,11 @@ DNS 策略可以逐个 Pod 来设定。目前 Kubernetes 支持以下特定 Pod
425450
- "`ClusterFirstWithHostNet`": 对于以 hostNetwork 方式运行的 Pod,应将其 DNS 策略显式设置为
426451
"`ClusterFirstWithHostNet`"。否则,以 hostNetwork 方式和 `"ClusterFirst"` 策略运行的
427452
Pod 将会做出回退至 `"Default"` 策略的行为。
428-
- 注意:这在 Windows 上不支持。 有关详细信息,请参见[下文](#dns-windows)。
453+
454+
{{< note >}}
455+
这在 Windows 上不支持。有关详细信息,请参见[下文](#dns-windows)。
456+
{{< /note >}}
457+
429458
- "`None`": 此设置允许 Pod 忽略 Kubernetes 环境中的 DNS 设置。Pod 会使用其 `dnsConfig`
430459
字段所提供的 DNS 设置。
431460
参见 [Pod 的 DNS 配置](#pod-dns-config)节。
@@ -592,7 +621,7 @@ this problem.
592621
<!--
593622
## DNS resolution on Windows nodes {#dns-windows}
594623
595-
- ClusterFirstWithHostNet is not supported for Pods that run on Windows nodes.
624+
- `ClusterFirstWithHostNet` is not supported for Pods that run on Windows nodes.
596625
Windows treats all names with a `.` as a FQDN and skips FQDN resolution.
597626
- On Windows, there are multiple DNS resolvers that can be used. As these come with
598627
slightly different behaviors, using the
@@ -610,7 +639,7 @@ this problem.
610639
-->
611640
## Windows 节点上的 DNS 解析 {#dns-windows}
612641

613-
- 在 Windows 节点上运行的 Pod 不支持 ClusterFirstWithHostNet。
642+
- 在 Windows 节点上运行的 Pod 不支持 `ClusterFirstWithHostNet`
614643
Windows 将所有带有 `.` 的名称视为全限定域名(FQDN)并跳过全限定域名(FQDN)解析。
615644
- 在 Windows 上,可以使用的 DNS 解析器有很多。
616645
由于这些解析器彼此之间会有轻微的行为差别,建议使用
@@ -632,4 +661,3 @@ For guidance on administering DNS configurations, check
632661
-->
633662
有关管理 DNS 配置的指导,
634663
请查看[配置 DNS 服务](/zh-cn/docs/tasks/administer-cluster/dns-custom-nameservers/)
635-

0 commit comments

Comments
 (0)