Skip to content

Commit 32cf18e

Browse files
authored
Merge pull request #25017 from tengqm/zh-sync-5
[zh] Sync changes from English site (5)
2 parents de92c57 + e97677e commit 32cf18e

File tree

7 files changed

+425
-327
lines changed

7 files changed

+425
-327
lines changed

content/zh/docs/concepts/services-networking/add-entries-to-pod-etc-hosts-with-host-aliases.md

Lines changed: 54 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,67 +2,76 @@
22
title: 使用 HostAliases 向 Pod /etc/hosts 文件添加条目
33
content_type: concept
44
weight: 60
5+
min-kubernetes-server-version: 1.7
56
---
67

7-
{{< toc >}}
8+
<!--
9+
reviewers:
10+
- rickypai
11+
- thockin
12+
title: Adding entries to Pod /etc/hosts with HostAliases
13+
content_type: concept
14+
weight: 60
15+
min-kubernetes-server-version: 1.7
16+
-->
817

918
<!-- overview -->
1019

1120
<!--
12-
Adding entries to a Pod's /etc/hosts file provides Pod-level override of hostname resolution when DNS and other options are not applicable. In 1.7, users can add these custom entries with the HostAliases field in PodSpec.
21+
Adding entries to a Pod's /etc/hosts file provides Pod-level override of hostname resolution when DNS and other options are not applicable. You can add these custom entries with the HostAliases field in PodSpec.
1322
1423
Modification not using HostAliases is not suggested because the file is managed by Kubelet and can be overwritten on during Pod creation/restart.
1524
-->
25+
当 DNS 配置以及其它选项不合理的时候,通过向 Pod 的 /etc/hosts 文件中添加条目,
26+
可以在 Pod 级别覆盖对主机名的解析。你可以通过 PodSpec 的 HostAliases
27+
字段来添加这些自定义条目。
1628

17-
当 DNS 配置以及其它选项不合理的时候,通过向 Pod 的 /etc/hosts 文件中添加条目,可以在 Pod 级别覆盖对主机名的解析。在 1.7 版本,用户可以通过 PodSpec 的 HostAliases 字段来添加这些自定义的条目。
18-
19-
建议通过使用 HostAliases 来进行修改,因为该文件由 Kubelet 管理,并且可以在 Pod 创建/重启过程中被重写。
20-
29+
建议通过使用 HostAliases 来进行修改,因为该文件由 Kubelet 管理,并且
30+
可以在 Pod 创建/重启过程中被重写。
2131

2232
<!-- body -->
2333

2434
<!--
2535
## Default Hosts File Content
2636
27-
Let's start an Nginx Pod which is assigned a Pod IP:
37+
Start an Nginx Pod which is assigned a Pod IP:
2838
-->
2939
## 默认 hosts 文件内容
3040

31-
让我们从一个 Nginx Pod 开始,给该 Pod 分配一个 IP:
41+
让我们从一个 Nginx Pod 开始, Pod 被分配一个 IP:
3242

3343
```shell
3444
kubectl run nginx --image nginx --generator=run-pod/v1
3545
```
3646

37-
```shell
47+
```
3848
pod/nginx created
3949
```
4050

4151
<!--
4252
Examine a Pod IP:
4353
-->
44-
检查Pod IP:
54+
检查 Pod IP:
4555

4656
```shell
4757
kubectl get pods --output=wide
4858
```
4959

50-
```shell
60+
```
5161
NAME READY STATUS RESTARTS AGE IP NODE
5262
nginx 1/1 Running 0 13s 10.200.0.4 worker0
5363
```
5464

5565
<!--
5666
The hosts file content would look like this:
5767
-->
58-
5968
主机文件的内容如下所示:
6069

6170
```shell
6271
kubectl exec nginx -- cat /etc/hosts
6372
```
6473

65-
```none
74+
```
6675
# Kubernetes-managed hosts file.
6776
127.0.0.1 localhost
6877
::1 localhost ip6-localhost ip6-loopback
@@ -77,63 +86,63 @@ fe00::2 ip6-allrouters
7786
By default, the `hosts` file only includes IPv4 and IPv6 boilerplates like
7887
`localhost` and its own hostname.
7988
-->
80-
默认,hosts 文件只包含 ipv4ipv6 的样板内容,像 `localhost` 和主机名称。
89+
默认情况下,hosts 文件只包含 IPv4IPv6 的样板内容,像 `localhost` 和主机名称。
8190

8291
<!--
8392
## Adding Additional Entries with HostAliases
8493
8594
In addition to the default boilerplate, we can add additional entries to the
86-
`hosts` file to resolve `foo.local`, `bar.local` to `127.0.0.1` and `foo.remote`,
87-
`bar.remote` to `10.1.2.3`, we can by adding HostAliases to the Pod under
95+
`hosts` file.
96+
For example: to resolve `foo.local`, `bar.local` to `127.0.0.1` and `foo.remote`,
97+
`bar.remote` to `10.1.2.3`, we can configure HostAliases for a Pod under
8898
`.spec.hostAliases`:
8999
-->
100+
## 通过 HostAliases 增加额外条目
90101

91-
## 通过 HostAliases 增加额外的条目
92-
93-
除了默认的样板内容,我们可以向 hosts 文件添加额外的条目,`foo.local``bar.local` 解析为`127.0.0.1`
94-
`foo.remote``bar.remote` 解析为 `10.1.2.3`,我们可以在 `.spec.hostAliases` 下为 Pod 添加 HostAliases。
102+
除了默认的样板内容,我们可以向 hosts 文件添加额外的条目。
103+
例如,要将 `foo.local``bar.local` 解析为 `127.0.0.1`
104+
`foo.remote``bar.remote` 解析为 `10.1.2.3`,我们可以在
105+
`.spec.hostAliases` 下为 Pod 配置 HostAliases。
95106

96107
{{< codenew file="service/networking/hostaliases-pod.yaml" >}}
97108

98109
<!--
99-
This Pod can be started with the following commands:
110+
You can start a Pod with that configuration by running:
100111
-->
101-
102-
可以使用以下命令启动此Pod:
112+
你可以使用以下命令用此配置启动 Pod:
103113

104114
```shell
105115
kubectl apply -f hostaliases-pod.yaml
106116
```
107117

108-
```shell
118+
```
109119
pod/hostaliases-pod created
110120
```
111121

112122
<!--
113-
Examine a Pod IP and status:
123+
Examine a Pod's details to see its IPv4 address and its status:
114124
-->
115-
检查Pod IP 和状态
125+
检查 Pod 详情,查看其 IPv4 地址和状态
116126

117127
```shell
118128
kubectl get pod --output=wide
119129
```
120130

121-
```shell
122-
NAME READY STATUS RESTARTS AGE IP NODE
123-
hostaliases-pod 0/1 Completed 0 6s 10.200.0.5 worker0
131+
```
132+
NAME READY STATUS RESTARTS AGE IP NODE
133+
hostaliases-pod 0/1 Completed 0 6s 10.200.0.5 worker0
124134
```
125135

126136
<!--
127-
The `hosts` file content would look like this:
137+
The `hosts` file content looks like this:
128138
-->
129-
130139
hosts 文件的内容看起来类似如下这样:
131140

132141
```shell
133142
kubectl logs hostaliases-pod
134143
```
135144

136-
```none
145+
```
137146
# Kubernetes-managed hosts file.
138147
127.0.0.1 localhost
139148
::1 localhost ip6-localhost ip6-loopback
@@ -151,30 +160,31 @@ fe00::2 ip6-allrouters
151160
<!--
152161
With the additional entries specified at the bottom.
153162
-->
154-
155163
在最下面额外添加了一些条目。
156164

157165
<!--
158-
With the additional entries specified at the bottom.
159-
160166
## Why Does Kubelet Manage the Hosts File?
161167
162168
Kubelet [manages](https://github.com/kubernetes/kubernetes/issues/14633) the
163169
`hosts` file for each container of the Pod to prevent Docker from
164170
[modifying](https://github.com/moby/moby/issues/17190) the file after the
165171
containers have already been started.
166-
167-
Because of the managed-nature of the file, any user-written content will be
168-
overwritten whenever the `hosts` file is remounted by Kubelet in the event of
169-
a container restart or a Pod reschedule. Thus, it is not suggested to modify
170-
the contents of the file.
171172
-->
173+
## 为什么 kubelet 管理 hosts 文件?
172174

173-
## 为什么 Kubelet 管理 hosts文件?
175+
kubelet [管理](https://github.com/kubernetes/kubernetes/issues/14633) Pod
176+
中每个容器的 hosts 文件,避免 Docker 在容器已经启动之后去
177+
[修改](https://github.com/moby/moby/issues/17190) 该文件。
174178

175-
kubelet [管理](https://github.com/kubernetes/kubernetes/issues/14633) Pod 中每个容器的 hosts 文件,避免 Docker 在容器已经启动之后去 [修改](https://github.com/moby/moby/issues/17190) 该文件。
176-
177-
因为该文件是托管性质的文件,无论容器重启或 Pod 重新调度,用户修改该 hosts 文件的任何内容,都会在 Kubelet 重新安装后被覆盖。因此,不建议修改该文件的内容。
179+
{{< caution >}}
180+
<!--
181+
Avoid making manual changes to the hosts file inside a container.
178182
183+
If you make manual changes to the hosts file,
184+
those changes are lost when the container exits.
185+
-->
186+
请避免手工更改容器内的 hosts 文件内容。
179187

188+
如果你对 hosts 文件做了手工修改,这些修改都会在容器退出时丢失。
189+
{{< /caution >}}
180190

content/zh/docs/concepts/services-networking/connect-applications-service.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,8 @@ about the [service proxy](/docs/concepts/services-networking/service/#virtual-ip
205205
206206
Kubernetes supports 2 primary modes of finding a Service - environment variables
207207
and DNS. The former works out of the box while the latter requires the
208-
[CoreDNS cluster addon](http://releases.k8s.io/{{< param "githubbranch" >}}/cluster/addons/dns/coredns).
208+
[CoreDNS cluster addon](https://releases.k8s.io/{{< param "githubbranch" >}}/cluster/addons/dns/coredns).
209209
-->
210-
211210
## 访问 Service
212211

213212
Kubernetes支持两种查找服务的主要模式: 环境变量和DNS。 前者开箱即用,而后者则需要[CoreDNS集群插件]

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

Lines changed: 80 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ considered implementation details and are subject to change without warning.
4242
For more up-to-date specification, see
4343
[Kubernetes DNS-Based Service Discovery](https://github.com/kubernetes/dns/blob/master/docs/specification.md).
4444
-->
45-
46-
## 怎样获取 DNS 名字?
45+
## 哪些对象会有 DNS 名字? {#what-things-get-dns-names}
4746

4847
在集群中定义的每个 Service(包括 DNS 服务器自身)都会被指派一个 DNS 名称。
4948
默认,一个客户端 Pod 的 DNS 搜索列表将包含该 Pod 自己的名字空间和集群默认域。
@@ -74,7 +73,6 @@ Services, this resolves to the set of IPs of the pods selected by the Service.
7473
Clients are expected to consume the set or else use standard round-robin
7574
selection from the set.
7675
-->
77-
7876
### 服务 {#services}
7977

8078
#### A/AAAA 记录
@@ -117,17 +115,35 @@ Kubernetes 会为命名端口创建 SRV 记录,这些端口是普通服务或
117115
<!--
118116
### A/AAAA records
119117
120-
Any pods created by a Deployment or DaemonSet have the following
121-
DNS resolution available:
118+
In general a pod has the following DNS resolution:
119+
120+
`pod-ip-address.my-namespace.pod.cluster-domain.example`.
121+
122+
For example, if a pod in the `default` namespace has the IP address 172.17.0.3,
123+
and the domain name for your cluster is `cluster.local`, then the Pod has a DNS name:
122124
123-
`pod-ip-address.deployment-name.my-namespace.svc.cluster-domain.example.`
125+
`172-17-0-3.default.pod.cluster.local`.
126+
127+
Any pods created by a Deployment or DaemonSet exposed by a Service have the
128+
following DNS resolution available:
129+
130+
`pod-ip-address.deployment-name.my-namespace.svc.cluster-domain.example`.
124131
-->
125132
### A/AAAA 记录
126133

127-
经由 Deployment 或者 DaemonSet 所创建的所有 Pods 都会有如下 DNS
128-
解析项与之对应:
134+
一般而言,Pod 会对应如下 DNS 名字解析:
135+
136+
`pod-ip-address.my-namespace.pod.cluster-domain.example`
129137

130-
`pod-ip-address.deployment-name.my-namespace.svc.cluster-domain.example.`
138+
例如,对于一个位于 `default` 名字空间,IP 地址为 172.17.0.3 的 Pod,
139+
如果集群的域名为 `cluster.local`,则 Pod 会对应 DNS 名称:
140+
141+
`172-17-0-3.default.pod.cluster.local`.
142+
143+
Deployment 或通过 Service 暴露出来的 DaemonSet 所创建的 Pod 会有如下 DNS
144+
解析名称可用:
145+
146+
`pod-ip-address.deployment-name.my-namespace.svc.cluster-domain.example`.
131147

132148
<!--
133149
### Pod's hostname and subdomain fields
@@ -146,7 +162,6 @@ domain name (FQDN) "`foo.bar.my-namespace.svc.cluster-domain.example`".
146162
147163
Example:
148164
-->
149-
150165
### Pod 的 hostname 和 subdomain 字段
151166

152167
当前,创建 Pod 时其主机名取自 Pod 的 `metadata.name` 值。
@@ -254,6 +269,51 @@ record unless `publishNotReadyAddresses=True` is set on the Service.
254269
才会有与之对应的记录。
255270
{{< /note >}}
256271

272+
<!--
273+
### Pod's setHostnameAsFQDN field {#pod-sethostnameasfqdn-field}
274+
-->
275+
### Pod 的 setHostnameAsFQDN 字段 {#pod-sethostnameasfqdn-field}
276+
277+
{{< feature-state for_k8s_version="v1.19" state="alpha" >}}
278+
279+
<!--
280+
**Prerequisites**: The `SetHostnameAsFQDN` [feature gate](/docs/reference/command-line-tools-reference/feature-gates/)
281+
The `SetHostnameAsFQDN` [feature gate](/docs/reference/command-line-tools-reference/feature-gates/)
282+
must be enabled for the
283+
{{< glossary_tooltip text="API Server" term_id="kube-apiserver" >}}
284+
285+
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.
286+
-->
287+
**前置条件**:`SetHostnameAsFQDN`
288+
[特性门控](/zh/docs/reference/command-line-tools-reference/feature-gates/)
289+
必须在 {{< glossary_tooltip text="API 服务器" term_id="kube-apiserver" >}}
290+
上启用。
291+
292+
当你在 Pod 规约中设置了 `setHostnameAsFQDN: true` 时,kubelet 会将 Pod
293+
的全限定域名(FQDN)作为该 Pod 的主机名记录到 Pod 所在名字空间。
294+
在这种情况下,`hostname` 和 `hostname --fqdn` 都会返回 Pod 的全限定域名。
295+
296+
{{< note >}}
297+
<!--
298+
In Linux, the hostname field of the kernel (the `nodename` field of `struct utsname`) is limited to 64 characters.
299+
300+
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.
301+
-->
302+
在 Linux 中,内核的主机名字段(`struct utsname` 的 `nodename` 字段)限定
303+
最多 64 个字符。
304+
305+
如果 Pod 启用这一特性,而其 FQDN 超出 64 字符,Pod 的启动会失败。
306+
Pod 会一直出于 `Pending` 状态(通过 `kubectl` 所看到的 `ContainerCreating`),
307+
并产生错误事件,例如
308+
"Failed to construct FQDN from pod hostname and cluster domain, FQDN
309+
`long-FQDN` is too long (64 characters is the max, 70 characters requested)."
310+
(无法基于 Pod 主机名和集群域名构造 FQDN,FQDN `long-FQDN` 过长,至多 64
311+
字符,请求字符数为 70)。
312+
对于这种场景而言,改善用户体验的一种方式是创建一个
313+
[准入 Webhook 控制器](/zh/docs/reference/access-authn-authz/extensible-admission-controllers/#admission-webhooks),
314+
在用户创建顶层对象(如 Deployment)的时候控制 FQDN 的长度。
315+
{{< /note >}}
316+
257317
<!--
258318
### Pod's DNS Policy
259319

@@ -278,10 +338,15 @@ following pod-specific DNS policies. These policies are specified in the
278338
`dnsConfig` field in the Pod Spec.
279339
See [Pod's DNS config](#pod-s-dns-config) subsection below.
280340
-->
341+
### Pod 的 DNS 策略 {#pod-s-dns-policy}
342+
343+
DNS 策略可以逐个 Pod 来设定。目前 Kubernetes 支持以下特定 Pod 的 DNS 策略。
344+
这些策略可以在 Pod 规约中的 `dnsPolicy` 字段设置:
281345

282-
- "`Default`": Pod 从运行所在的节点继承名称解析配置。
283-
参考[相关讨论](/zh/docs/tasks/administer-cluster/dns-custom-nameservers/#inheriting-dns-from-the-node) 获取更多信息。
284-
- "`ClusterFirst`": 与配置的集群域后缀不匹配的任何 DNS 查询(例如 “www.kubernetes.io”)
346+
- "`Default`": Pod 从运行所在的节点继承名称解析配置。参考
347+
[相关讨论](/zh/docs/tasks/administer-cluster/dns-custom-nameservers/#inheriting-dns-from-the-node)
348+
获取更多信息。
349+
- "`ClusterFirst`": 与配置的集群域后缀不匹配的任何 DNS 查询(例如 "www.kubernetes.io")
285350
都将转发到从节点继承的上游名称服务器。集群管理员可能配置了额外的存根域和上游 DNS 服务器。
286351
参阅[相关讨论](/zh/docs/tasks/administer-cluster/dns-custom-nameservers/#impacts-on-pods)
287352
了解在这些场景中如何处理 DNS 查询的信息。
@@ -293,10 +358,10 @@ following pod-specific DNS policies. These policies are specified in the
293358

294359
<!--
295360
"Default" is not the default DNS policy. If `dnsPolicy` is not
296-
explicitly specified, then ClusterFirst is used.
361+
explicitly specified, then "ClusterFirst" is used.
297362
-->
298363
{{< note >}}
299-
"`Default`" 不是默认的 DNS 策略。如果未明确指定 `dnsPolicy`,则使用 "`ClusterFirst`"。
364+
"Default" 不是默认的 DNS 策略。如果未明确指定 `dnsPolicy`,则使用 "ClusterFirst"。
300365
{{< /note >}}
301366

302367
<!--

0 commit comments

Comments
 (0)