Skip to content

Commit f762aaa

Browse files
authored
Merge pull request #34064 from TinySong/dns-pod-service
[zh] resync dns-pod-service.md
2 parents d0c8ed8 + 8ffb79d commit f762aaa

File tree

1 file changed

+65
-67
lines changed

1 file changed

+65
-67
lines changed

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

Lines changed: 65 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ weight: 20
1515
<!-- overview -->
1616

1717
<!--
18-
Kubernetes creates DNS records for services and pods. You can contact
19-
services with consistent DNS names instead of IP addresses.
18+
Kubernetes creates DNS records for Services and Pods. You can contact
19+
Services with consistent DNS names instead of IP addresses.
2020
-->
21-
Kubernetes 为服务和 Pods 创建 DNS 记录。
22-
你可以使用一致的 DNS 名称而非 IP 地址来访问服务
21+
Kubernetes 为 Service 和 Pod 创建 DNS 记录。
22+
你可以使用一致的 DNS 名称而非 IP 地址访问 Service
2323

2424
<!-- body -->
2525

@@ -30,40 +30,39 @@ Kubernetes DNS schedules a DNS Pod and Service on the cluster, and configures
3030
the kubelets to tell individual containers to use the DNS Service's IP to
3131
resolve DNS names.
3232
-->
33-
## 介绍
33+
## 介绍 {#introduction}
3434

35-
Kubernetes DNS 在集群上调度 DNS Pod 和服务,并配置 kubelet 以告知各个容器
36-
使用 DNS 服务的 IP 来解析 DNS 名称。
35+
Kubernetes DNS 除了在集群上调度 DNS Pod 和 Service,
36+
还配置 kubelet 以告知各个容器使用 DNS Service 的 IP 来解析 DNS 名称。
3737

3838
<!--
3939
Every Service defined in the cluster (including the DNS server itself) is
4040
assigned a DNS name. By default, a client Pod's DNS search list includes the
4141
Pod's own namespace and the cluster's default domain.
4242
-->
4343
集群中定义的每个 Service (包括 DNS 服务器自身)都被赋予一个 DNS 名称。
44-
默认情况下,客户端 Pod 的 DNS 搜索列表会包含 Pod 自身的名字空间和集群
45-
的默认域。
44+
默认情况下,客户端 Pod 的 DNS 搜索列表会包含 Pod 自身的名字空间和集群的默认域。
4645

4746
<!--
4847
### Namespaces of Services
4948
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.
49+
A DNS query may return different results based on the namespace of the Pod making
50+
it. DNS queries that don't specify a namespace are limited to the Pod's
51+
namespace. Access Services in other namespaces by specifying it in the DNS query.
5352
54-
For example, consider a pod in a `test` namespace. A `data` service is in
53+
For example, consider a Pod in a `test` namespace. A `data` service is in
5554
the `prod` namespace.
5655
57-
A query for `data` returns no results, because it uses the pod's `test` namespace.
56+
A query for `data` returns no results, because it uses the Pod's `test` namespace.
5857
5958
A query for `data.prod` returns the intended result, because it specifies the
6059
namespace.
6160
-->
62-
### Service 的名字空间
61+
### Service 的名字空间 {#namespaces-of-services}
6362

6463
DNS 查询可能因为执行查询的 Pod 所在的名字空间而返回不同的结果。
6564
不指定名字空间的 DNS 查询会被限制在 Pod 所在的名字空间内。
66-
要访问其他名字空间中的服务,需要在 DNS 查询中给出名字空间
65+
要访问其他名字空间中的 Service,需要在 DNS 查询中指定名字空间
6766

6867
例如,假定名字空间 `test` 中存在一个 Pod,`prod` 名字空间中存在一个服务
6968
`data`
@@ -73,8 +72,8 @@ Pod 查询 `data` 时没有返回结果,因为使用的是 Pod 的名字空间
7372
Pod 查询 `data.prod` 时则会返回预期的结果,因为查询中指定了名字空间。
7473

7574
<!--
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
75+
DNS queries may be expanded using the Pod's `/etc/resolv.conf`. Kubelet
76+
sets this file for each Pod. For example, a query for just `data` may be
7877
expanded to `data.test.svc.cluster.local`. The values of the `search` option
7978
are used to expand queries. To learn more about DNS queries, see
8079
[the `resolv.conf` manual page.](https://www.man7.org/linux/man-pages/man5/resolv.conf.5.html)
@@ -91,7 +90,7 @@ options ndots:5
9190
```
9291

9392
<!--
94-
In summary, a pod in the _test_ namespace can successfully resolve either
93+
In summary, a Pod in the `test` namespace can successfully resolve either
9594
`data.prod` or `data.prod.svc.cluster.local`.
9695
-->
9796
概括起来,名字空间 `test` 中的 Pod 可以成功地解析 `data.prod` 或者
@@ -116,7 +115,7 @@ considered implementation details and are subject to change without warning.
116115
For more up-to-date specification, see
117116
[Kubernetes DNS-Based Service Discovery](https://github.com/kubernetes/dns/blob/master/docs/specification.md).
118117
-->
119-
以下各节详细介绍了被支持的 DNS 记录类型和被支持的布局
118+
以下各节详细介绍已支持的 DNS 记录类型和布局
120119
其它布局、名称或者查询即使碰巧可以工作,也应视为实现细节,
121120
将来很可能被更改而且不会因此发出警告。
122121
有关最新规范请查看
@@ -128,29 +127,29 @@ For more up-to-date specification, see
128127
### A/AAAA records
129128
130129
"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
130+
depending on the IP family of the Service, for a name of the form
132131
`my-svc.my-namespace.svc.cluster-domain.example`. This resolves to the cluster IP
133132
of the Service.
134133
135134
"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
135+
depending on the IP family of the Service, for a name of the form
137136
`my-svc.my-namespace.svc.cluster-domain.example`. Unlike normal
138-
Services, this resolves to the set of IPs of the pods selected by the Service.
137+
Services, this resolves to the set of IPs of the Pods selected by the Service.
139138
Clients are expected to consume the set or else use standard round-robin
140139
selection from the set.
141140
-->
142-
### 服务 {#services}
141+
### Services
143142

144-
#### A/AAAA 记录
143+
#### A/AAAA 记录 {#a-aaaa-records}
145144

146-
“普通” 服务(除了无头服务)会以 `my-svc.my-namespace.svc.cluster-domain.example`
147-
这种名字的形式被分配一个 DNS A 或 AAAA 记录,取决于服务的 IP 协议族。
148-
该名称会解析成对应服务的集群 IP。
145+
“普通” Service(除了无头 Service)会以 `my-svc.my-namespace.svc.cluster-domain.example`
146+
这种名字的形式被分配一个 DNS A 或 AAAA 记录,取决于 Service 的 IP 协议族。
147+
该名称会解析成对应 Service 的集群 IP。
149148

150-
“无头(Headless)” 服务(没有集群 IP)也会以
149+
“无头(Headless)” Service (没有集群 IP)也会以
151150
`my-svc.my-namespace.svc.cluster-domain.example` 这种名字的形式被指派一个 DNS A 或 AAAA 记录,
152-
具体取决于服务的 IP 协议族。
153-
与普通服务不同,这一记录会被解析成对应服务所选择的 Pod 集合的 IP
151+
具体取决于 Service 的 IP 协议族。
152+
与普通 Service 不同,这一记录会被解析成对应 Service 所选择的 Pod IP 的集合
154153
客户端要能够使用这组 IP,或者使用标准的轮转策略从这组 IP 中进行选择。
155154

156155
<!--
@@ -160,41 +159,42 @@ SRV Records are created for named ports that are part of normal or [Headless
160159
Services](/docs/concepts/services-networking/service/#headless-services).
161160
For each named port, the SRV record would have the form
162161
`_my-port-name._my-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:
162+
For a regular Service, this resolves to the port number and the domain name:
164163
`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
164+
For a headless Service, this resolves to multiple answers, one for each Pod
165+
that is backing the Service, and contains the port number and the domain name of the Pod
167166
of the form `auto-generated-name.my-svc.my-namespace.svc.cluster-domain.example`.
168167
-->
169168
#### SRV 记录 {#srv-records}
170169

171-
Kubernetes 会为命名端口创建 SRV 记录,这些端口是普通服务或
172-
[无头服务](/zh/docs/concepts/services-networking/service/#headless-services)的一部分。
173-
对每个命名端口,SRV 记录具有 `_my-port-name._my-port-protocol.my-svc.my-namespace.svc.cluster-domain.example` 这种形式。
174-
对普通服务,该记录会被解析成端口号和域名:`my-svc.my-namespace.svc.cluster-domain.example`
175-
对无头服务,该记录会被解析成多个结果,服务对应的每个后端 Pod 各一个;
176-
其中包含 Pod 端口号和形为 `auto-generated-name.my-svc.my-namespace.svc.cluster-domain.example`
170+
Kubernetes 根据普通 Service 或
171+
[Headless Service](/zh/docs/concepts/services-networking/service/#headless-services)
172+
中的命名端口创建 SRV 记录。每个命名端口,
173+
SRV 记录格式为 `_my-port-name._my-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 端口号和格式为 `auto-generated-name.my-svc.my-namespace.svc.cluster-domain.example`
177177
的域名。
178178

179179
## Pods
180180

181181
<!--
182182
### A/AAAA records
183183
184-
In general a pod has the following DNS resolution:
184+
In general a Pod has the following DNS resolution:
185185
186186
`pod-ip-address.my-namespace.pod.cluster-domain.example`.
187187
188-
For example, if a pod in the `default` namespace has the IP address 172.17.0.3,
188+
For example, if a Pod in the `default` namespace has the IP address 172.17.0.3,
189189
and the domain name for your cluster is `cluster.local`, then the Pod has a DNS name:
190190
191191
`172-17-0-3.default.pod.cluster.local`.
192192
193-
Any pods exposed by a Service have the following DNS resolution available:
193+
Any Pods exposed by a Service have the following DNS resolution available:
194194
195195
`pod-ip-address.service-name.my-namespace.svc.cluster-domain.example`.
196196
-->
197-
### A/AAAA 记录
197+
### A/AAAA 记录 {#a-aaaa-records}
198198

199199
一般而言,Pod 会对应如下 DNS 名字解析:
200200

@@ -212,11 +212,11 @@ Any pods exposed by a Service have the following DNS resolution available:
212212
<!--
213213
### Pod's hostname and subdomain fields
214214
215-
Currently when a pod is created, its hostname is the Pod's `metadata.name` value.
215+
Currently when a Pod is created, its hostname is the Pod's `metadata.name` value.
216216
217217
The Pod spec has an optional `hostname` field, which can be used to specify the
218218
Pod's hostname. When specified, it takes precedence over the Pod's name to be
219-
the hostname of the pod. For example, given a Pod with `hostname` set to
219+
the hostname of the Pod. For example, given a Pod with `hostname` set to
220220
"`my-host`", the Pod will have its hostname set to "`my-host`".
221221
222222
The Pod spec also has an optional `subdomain` field which can be used to specify
@@ -226,7 +226,7 @@ domain name (FQDN) "`foo.bar.my-namespace.svc.cluster-domain.example`".
226226
227227
Example:
228228
-->
229-
### Pod 的 hostname 和 subdomain 字段
229+
### Pod 的 hostname 和 subdomain 字段 {#pod-s-hostname-and-subdomain-fields}
230230

231231
当前,创建 Pod 时其主机名取自 Pod 的 `metadata.name` 值。
232232

@@ -290,21 +290,21 @@ spec:
290290
```
291291
292292
<!--
293-
If there exists a headless service in the same namespace as the pod and with
293+
If there exists a headless Service in the same namespace as the Pod and with
294294
the same name as the subdomain, the cluster's DNS Server also returns an A or AAAA
295295
record for the Pod's fully qualified hostname.
296296
For example, given a Pod with the hostname set to "`busybox-1`" and the subdomain set to
297297
"`default-subdomain`", and a headless Service named "`default-subdomain`" in
298-
the same namespace, the pod will see its own FQDN as
298+
the same namespace, the Pod will see its own FQDN as
299299
"`busybox-1.default-subdomain.my-namespace.svc.cluster-domain.example`". DNS serves an
300-
A or AAAA record at that name, pointing to the Pod's IP. Both pods "`busybox1`" and
300+
A or AAAA record at that name, pointing to the Pod's IP. Both Pods "`busybox1`" and
301301
"`busybox2`" can have their distinct A or AAAA records.
302302
-->
303-
如果某无头服务与某 Pod 在同一个名字空间中,且它们具有相同的子域名,
303+
如果某无头 Service 与某 Pod 在同一个名字空间中,且它们具有相同的子域名,
304304
集群的 DNS 服务器也会为该 Pod 的全限定主机名返回 A 记录或 AAAA 记录。
305305
例如,在同一个名字空间中,给定一个主机名为 “busybox-1”、
306306
子域名设置为 “default-subdomain” 的 Pod,和一个名称为 “`default-subdomain`”
307-
的无头服务,Pod 将看到自己的 FQDN 为
307+
的无头 Service,Pod 将看到自己的 FQDN 为
308308
"`busybox-1.default-subdomain.my-namespace.svc.cluster-domain.example`"
309309
DNS 会为此名字提供一个 A 记录或 AAAA 记录,指向该 Pod 的 IP。
310310
“`busybox1`” 和 “`busybox2`” 这两个 Pod 分别具有它们自己的 A 或 AAAA 记录。
@@ -318,16 +318,14 @@ Endpoints 对象可以为任何端点地址及其 IP 指定 `hostname`。
318318
<!--
319319
Because A or AAAA records are not created for Pod names, `hostname` is required for the Pod's A or AAAA
320320
record to be created. A Pod with no `hostname` but with `subdomain` will only create the
321-
A or AAAA 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`),
322322
pointing to the Pod's IP address. Also, Pod needs to become ready in order to have a
323323
record unless `publishNotReadyAddresses=True` is set on the Service.
324324
-->
325325
{{< note >}}
326-
因为没有为 Pod 名称创建 A 记录或 AAAA 记录,所以要创建 Pod 的 A 记录
327-
或 AAAA 记录需要 `hostname`。
328-
326+
由于不是为 Pod 名称创建 A 或 AAAA 记录的,因此 Pod 的 A 或 AAAA 需要 `hostname`。
329327
没有设置 `hostname` 但设置了 `subdomain` 的 Pod 只会为
330-
无头服务创建 A 或 AAAA 记录(`default-subdomain.my-namespace.svc.cluster-domain.example`)
328+
无头 Service 创建 A 或 AAAA 记录(`default-subdomain.my-namespace.svc.cluster-domain.example`)
331329
指向 Pod 的 IP 地址。
332330
另外,除非在服务上设置了 `publishNotReadyAddresses=True`,否则只有 Pod 进入就绪状态
333331
才会有与之对应的记录。
@@ -359,15 +357,15 @@ When you set `setHostnameAsFQDN: true` in the Pod spec, the kubelet writes the P
359357
<!--
360358
In Linux, the hostname field of the kernel (the `nodename` field of `struct utsname`) is limited to 64 characters.
361359

362-
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/#admission-webhooks) to control FQDN size when users create top level objects, for example, Deployment.
360+
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/#admission-webhooks) to control FQDN size when users create top level objects, for example, Deployment.
363361
-->
364362
在 Linux 中,内核的主机名字段(`struct utsname` 的 `nodename` 字段)限定
365363
最多 64 个字符。
366364

367365
如果 Pod 启用这一特性,而其 FQDN 超出 64 字符,Pod 的启动会失败。
368366
Pod 会一直出于 `Pending` 状态(通过 `kubectl` 所看到的 `ContainerCreating`),
369367
并产生错误事件,例如
370-
"Failed to construct FQDN from pod hostname and cluster domain, FQDN
368+
"Failed to construct FQDN from Pod hostname and cluster domain, FQDN
371369
`long-FQDN` is too long (64 characters is the max, 70 characters requested)."
372370
(无法基于 Pod 主机名和集群域名构造 FQDN,FQDN `long-FQDN` 过长,至多 64
373371
字符,请求字符数为 70)。
@@ -379,12 +377,12 @@ Pod 会一直出于 `Pending` 状态(通过 `kubectl` 所看到的 `ContainerC
379377
<!--
380378
### Pod's DNS Policy
381379

382-
DNS policies can be set on a per-pod basis. Currently Kubernetes supports the
383-
following pod-specific DNS policies. These policies are specified in the
380+
DNS policies can be set on a per-Pod basis. Currently Kubernetes supports the
381+
following Pod-specific DNS policies. These policies are specified in the
384382
`dnsPolicy` field of a Pod Spec.
385383

386384
- "`Default`": The Pod inherits the name resolution configuration from the node
387-
that the pods run on.
385+
that the Pods run on.
388386
See [related discussion](/docs/tasks/administer-cluster/dns-custom-nameservers)
389387
for more details.
390388
- "`ClusterFirst`": Any DNS query that does not match the configured cluster
@@ -572,7 +570,7 @@ a list of search domains of up to 2048 characters.
572570
<!--
573571
## DNS resolution on Windows nodes {#dns-windows}
574572
575-
- ClusterFirstWithHostNet is not supported for pods that run on Windows nodes.
573+
- ClusterFirstWithHostNet is not supported for Pods that run on Windows nodes.
576574
Windows treats all names with a `.` as a FQDN and skips FQDN resolution.
577575
- On Windows, there are multiple DNS resolvers that can be used. As these come with
578576
slightly different behaviors, using the
@@ -581,10 +579,10 @@ a list of search domains of up to 2048 characters.
581579
- On Linux, you have a DNS suffix list, which is used after resolution of a name as fully
582580
qualified has failed.
583581
On Windows, you can only have 1 DNS suffix, which is the DNS suffix associated with that
584-
pod's namespace (example: `mydns.svc.cluster.local`). Windows can resolve FQDNs, services,
585-
or network name which can be resolved with this single suffix. For example, a pod spawned
582+
Pod's namespace (example: `mydns.svc.cluster.local`). Windows can resolve FQDNs, Services,
583+
or network name which can be resolved with this single suffix. For example, a Pod spawned
586584
in the `default` namespace, will have the DNS suffix `default.svc.cluster.local`.
587-
Inside a Windows pod, you can resolve both `kubernetes.default.svc.cluster.local`
585+
Inside a Windows Pod, you can resolve both `kubernetes.default.svc.cluster.local`
588586
and `kubernetes`, but not the partially qualified names (`kubernetes.default` or
589587
`kubernetes.default.svc`).
590588
-->
@@ -599,7 +597,7 @@ a list of search domains of up to 2048 characters.
599597
- 在 Linux 上,有一个 DNS 后缀列表,当解析全名失败时可以使用。
600598
在 Windows 上,你只能有一个 DNS 后缀,
601599
即与该 Pod 的命名空间相关联的 DNS 后缀(例如:`mydns.svc.cluster.local`)。
602-
Windows 可以解析全限定域名(FQDN),和使用了该 DNS 后缀的服务名称或者网络名称
600+
Windows 可以解析全限定域名(FQDN),和使用了该 DNS 后缀的 Services 或者网络名称
603601
例如,在 `default` 命名空间中生成一个 Pod,该 Pod 会获得的 DNS 后缀为 `default.svc.cluster.local`
604602
在 Windows 的 Pod 中,你可以解析 `kubernetes.default.svc.cluster.local``kubernetes`
605603
但是不能解析部分限定名称(`kubernetes.default``kubernetes.default.svc`)。

0 commit comments

Comments
 (0)