@@ -15,11 +15,11 @@ weight: 20
15
15
<!-- overview -->
16
16
17
17
<!--
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.
20
20
-->
21
- Kubernetes 为服务和 Pods 创建 DNS 记录。
22
- 你可以使用一致的 DNS 名称而非 IP 地址来访问服务 。
21
+ Kubernetes 为 Service 和 Pod 创建 DNS 记录。
22
+ 你可以使用一致的 DNS 名称而非 IP 地址访问 Service 。
23
23
24
24
<!-- body -->
25
25
@@ -30,40 +30,39 @@ Kubernetes DNS schedules a DNS Pod and Service on the cluster, and configures
30
30
the kubelets to tell individual containers to use the DNS Service's IP to
31
31
resolve DNS names.
32
32
-->
33
- ## 介绍
33
+ ## 介绍 {#introduction}
34
34
35
- Kubernetes DNS 在集群上调度 DNS Pod 和服务,并配置 kubelet 以告知各个容器
36
- 使用 DNS 服务的 IP 来解析 DNS 名称。
35
+ Kubernetes DNS 除了在集群上调度 DNS Pod 和 Service,
36
+ 还配置 kubelet 以告知各个容器使用 DNS Service 的 IP 来解析 DNS 名称。
37
37
38
38
<!--
39
39
Every Service defined in the cluster (including the DNS server itself) is
40
40
assigned a DNS name. By default, a client Pod's DNS search list includes the
41
41
Pod's own namespace and the cluster's default domain.
42
42
-->
43
43
集群中定义的每个 Service (包括 DNS 服务器自身)都被赋予一个 DNS 名称。
44
- 默认情况下,客户端 Pod 的 DNS 搜索列表会包含 Pod 自身的名字空间和集群
45
- 的默认域。
44
+ 默认情况下,客户端 Pod 的 DNS 搜索列表会包含 Pod 自身的名字空间和集群的默认域。
46
45
47
46
<!--
48
47
### Namespaces of Services
49
48
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.
53
52
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
55
54
the `prod` namespace.
56
55
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.
58
57
59
58
A query for `data.prod` returns the intended result, because it specifies the
60
59
namespace.
61
60
-->
62
- ### Service 的名字空间
61
+ ### Service 的名字空间 {#namespaces-of-services}
63
62
64
63
DNS 查询可能因为执行查询的 Pod 所在的名字空间而返回不同的结果。
65
64
不指定名字空间的 DNS 查询会被限制在 Pod 所在的名字空间内。
66
- 要访问其他名字空间中的服务 ,需要在 DNS 查询中给出名字空间 。
65
+ 要访问其他名字空间中的 Service ,需要在 DNS 查询中指定名字空间 。
67
66
68
67
例如,假定名字空间 ` test ` 中存在一个 Pod,` prod ` 名字空间中存在一个服务
69
68
` data ` 。
@@ -73,8 +72,8 @@ Pod 查询 `data` 时没有返回结果,因为使用的是 Pod 的名字空间
73
72
Pod 查询 ` data.prod ` 时则会返回预期的结果,因为查询中指定了名字空间。
74
73
75
74
<!--
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
78
77
expanded to `data.test.svc.cluster.local`. The values of the `search` option
79
78
are used to expand queries. To learn more about DNS queries, see
80
79
[the `resolv.conf` manual page.](https://www.man7.org/linux/man-pages/man5/resolv.conf.5.html)
@@ -91,7 +90,7 @@ options ndots:5
91
90
```
92
91
93
92
<!--
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
95
94
`data.prod` or `data.prod.svc.cluster.local`.
96
95
-->
97
96
概括起来,名字空间 ` test ` 中的 Pod 可以成功地解析 ` data.prod ` 或者
@@ -116,7 +115,7 @@ considered implementation details and are subject to change without warning.
116
115
For more up-to-date specification, see
117
116
[Kubernetes DNS-Based Service Discovery](https://github.com/kubernetes/dns/blob/master/docs/specification.md).
118
117
-->
119
- 以下各节详细介绍了被支持的 DNS 记录类型和被支持的布局 。
118
+ 以下各节详细介绍已支持的 DNS 记录类型和布局 。
120
119
其它布局、名称或者查询即使碰巧可以工作,也应视为实现细节,
121
120
将来很可能被更改而且不会因此发出警告。
122
121
有关最新规范请查看
@@ -128,29 +127,29 @@ For more up-to-date specification, see
128
127
### A/AAAA records
129
128
130
129
"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
132
131
`my-svc.my-namespace.svc.cluster-domain.example`. This resolves to the cluster IP
133
132
of the Service.
134
133
135
134
"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
137
136
`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.
139
138
Clients are expected to consume the set or else use standard round-robin
140
139
selection from the set.
141
140
-->
142
- ### 服务 {#services}
141
+ ### Services
143
142
144
- #### A/AAAA 记录
143
+ #### A/AAAA 记录 {#a-aaaa-records}
145
144
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。
149
148
150
- “无头(Headless)” 服务 (没有集群 IP)也会以
149
+ “无头(Headless)” Service (没有集群 IP)也会以
151
150
` my-svc.my-namespace.svc.cluster-domain.example ` 这种名字的形式被指派一个 DNS A 或 AAAA 记录,
152
- 具体取决于服务的 IP 协议族。
153
- 与普通服务不同,这一记录会被解析成对应服务所选择的 Pod 集合的 IP 。
151
+ 具体取决于 Service 的 IP 协议族。
152
+ 与普通 Service 不同,这一记录会被解析成对应 Service 所选择的 Pod IP 的集合 。
154
153
客户端要能够使用这组 IP,或者使用标准的轮转策略从这组 IP 中进行选择。
155
154
156
155
<!--
@@ -160,41 +159,42 @@ SRV Records are created for named ports that are part of normal or [Headless
160
159
Services](/docs/concepts/services-networking/service/#headless-services).
161
160
For each named port, the SRV record would have the form
162
161
`_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:
164
163
`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
167
166
of the form `auto-generated-name.my-svc.my-namespace.svc.cluster-domain.example`.
168
167
-->
169
168
#### SRV 记录 {#srv-records}
170
169
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 `
177
177
的域名。
178
178
179
179
## Pods
180
180
181
181
<!--
182
182
### A/AAAA records
183
183
184
- In general a pod has the following DNS resolution:
184
+ In general a Pod has the following DNS resolution:
185
185
186
186
`pod-ip-address.my-namespace.pod.cluster-domain.example`.
187
187
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,
189
189
and the domain name for your cluster is `cluster.local`, then the Pod has a DNS name:
190
190
191
191
`172-17-0-3.default.pod.cluster.local`.
192
192
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:
194
194
195
195
`pod-ip-address.service-name.my-namespace.svc.cluster-domain.example`.
196
196
-->
197
- ### A/AAAA 记录
197
+ ### A/AAAA 记录 {#a-aaaa-records}
198
198
199
199
一般而言,Pod 会对应如下 DNS 名字解析:
200
200
@@ -212,11 +212,11 @@ Any pods exposed by a Service have the following DNS resolution available:
212
212
<!--
213
213
### Pod's hostname and subdomain fields
214
214
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.
216
216
217
217
The Pod spec has an optional `hostname` field, which can be used to specify the
218
218
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
220
220
"`my-host`", the Pod will have its hostname set to "`my-host`".
221
221
222
222
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`".
226
226
227
227
Example:
228
228
-->
229
- ### Pod 的 hostname 和 subdomain 字段
229
+ ### Pod 的 hostname 和 subdomain 字段 {#pod-s-hostname-and-subdomain-fields}
230
230
231
231
当前,创建 Pod 时其主机名取自 Pod 的 ` metadata.name ` 值。
232
232
@@ -290,21 +290,21 @@ spec:
290
290
` ` `
291
291
292
292
<!--
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
294
294
the same name as the subdomain, the cluster's DNS Server also returns an A or AAAA
295
295
record for the Pod's fully qualified hostname.
296
296
For example, given a Pod with the hostname set to "` busybox-1`" and the subdomain set to
297
297
" `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
299
299
" `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
301
301
" `busybox2`" can have their distinct A or AAAA records.
302
302
-->
303
- 如果某无头服务与某 Pod 在同一个名字空间中,且它们具有相同的子域名,
303
+ 如果某无头 Service 与某 Pod 在同一个名字空间中,且它们具有相同的子域名,
304
304
集群的 DNS 服务器也会为该 Pod 的全限定主机名返回 A 记录或 AAAA 记录。
305
305
例如,在同一个名字空间中,给定一个主机名为 “busybox-1”、
306
306
子域名设置为 “default-subdomain” 的 Pod,和一个名称为 “`default-subdomain`”
307
- 的无头服务 ,Pod 将看到自己的 FQDN 为
307
+ 的无头 Service ,Pod 将看到自己的 FQDN 为
308
308
" `busybox-1.default-subdomain.my-namespace.svc.cluster-domain.example`" 。
309
309
DNS 会为此名字提供一个 A 记录或 AAAA 记录,指向该 Pod 的 IP。
310
310
“`busybox1`” 和 “`busybox2`” 这两个 Pod 分别具有它们自己的 A 或 AAAA 记录。
@@ -318,16 +318,14 @@ Endpoints 对象可以为任何端点地址及其 IP 指定 `hostname`。
318
318
<!--
319
319
Because A or AAAA records are not created for Pod names, `hostname` is required for the Pod's A or AAAA
320
320
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`),
322
322
pointing to the Pod's IP address. Also, Pod needs to become ready in order to have a
323
323
record unless `publishNotReadyAddresses=True` is set on the Service.
324
324
-->
325
325
{{< note >}}
326
- 因为没有为 Pod 名称创建 A 记录或 AAAA 记录,所以要创建 Pod 的 A 记录
327
- 或 AAAA 记录需要 `hostname`。
328
-
326
+ 由于不是为 Pod 名称创建 A 或 AAAA 记录的,因此 Pod 的 A 或 AAAA 需要 `hostname`。
329
327
没有设置 `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`)
331
329
指向 Pod 的 IP 地址。
332
330
另外,除非在服务上设置了 `publishNotReadyAddresses=True`,否则只有 Pod 进入就绪状态
333
331
才会有与之对应的记录。
@@ -359,15 +357,15 @@ When you set `setHostnameAsFQDN: true` in the Pod spec, the kubelet writes the P
359
357
<!--
360
358
In Linux, the hostname field of the kernel (the `nodename` field of `struct utsname`) is limited to 64 characters.
361
359
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.
363
361
-->
364
362
在 Linux 中,内核的主机名字段(`struct utsname` 的 `nodename` 字段)限定
365
363
最多 64 个字符。
366
364
367
365
如果 Pod 启用这一特性,而其 FQDN 超出 64 字符,Pod 的启动会失败。
368
366
Pod 会一直出于 `Pending` 状态(通过 `kubectl` 所看到的 `ContainerCreating`),
369
367
并产生错误事件,例如
370
- " Failed to construct FQDN from pod hostname and cluster domain, FQDN
368
+ " Failed to construct FQDN from Pod hostname and cluster domain, FQDN
371
369
`long-FQDN` is too long (64 characters is the max, 70 characters requested)."
372
370
(无法基于 Pod 主机名和集群域名构造 FQDN,FQDN `long-FQDN` 过长,至多 64
373
371
字符,请求字符数为 70)。
@@ -379,12 +377,12 @@ Pod 会一直出于 `Pending` 状态(通过 `kubectl` 所看到的 `ContainerC
379
377
<!--
380
378
# ## Pod's DNS Policy
381
379
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
384
382
` dnsPolicy` field of a Pod Spec.
385
383
386
384
- " `Default` " : The Pod inherits the name resolution configuration from the node
387
- that the pods run on.
385
+ that the Pods run on.
388
386
See [related discussion](/docs/tasks/administer-cluster/dns-custom-nameservers)
389
387
for more details.
390
388
- " `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.
572
570
<!--
573
571
## DNS resolution on Windows nodes {#dns-windows}
574
572
575
- - ClusterFirstWithHostNet is not supported for pods that run on Windows nodes.
573
+ - ClusterFirstWithHostNet is not supported for Pods that run on Windows nodes.
576
574
Windows treats all names with a `.` as a FQDN and skips FQDN resolution.
577
575
- On Windows, there are multiple DNS resolvers that can be used. As these come with
578
576
slightly different behaviors, using the
@@ -581,10 +579,10 @@ a list of search domains of up to 2048 characters.
581
579
- On Linux, you have a DNS suffix list, which is used after resolution of a name as fully
582
580
qualified has failed.
583
581
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
586
584
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`
588
586
and `kubernetes`, but not the partially qualified names (`kubernetes.default` or
589
587
`kubernetes.default.svc`).
590
588
-->
@@ -599,7 +597,7 @@ a list of search domains of up to 2048 characters.
599
597
- 在 Linux 上,有一个 DNS 后缀列表,当解析全名失败时可以使用。
600
598
在 Windows 上,你只能有一个 DNS 后缀,
601
599
即与该 Pod 的命名空间相关联的 DNS 后缀(例如:` mydns.svc.cluster.local ` )。
602
- Windows 可以解析全限定域名(FQDN),和使用了该 DNS 后缀的服务名称或者网络名称 。
600
+ Windows 可以解析全限定域名(FQDN),和使用了该 DNS 后缀的 Services 或者网络名称 。
603
601
例如,在 ` default ` 命名空间中生成一个 Pod,该 Pod 会获得的 DNS 后缀为 ` default.svc.cluster.local ` 。
604
602
在 Windows 的 Pod 中,你可以解析 ` kubernetes.default.svc.cluster.local ` 和 ` kubernetes ` ,
605
603
但是不能解析部分限定名称(` kubernetes.default ` 和 ` kubernetes.default.svc ` )。
0 commit comments