Skip to content

Commit f4dc79f

Browse files
authored
Merge pull request #48187 from windsonsea/csfile
[zh] Sync customize-hosts-file-for-pods.md
2 parents e657ca6 + 903eb3f commit f4dc79f

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

content/zh-cn/docs/tasks/network/customize-hosts-file-for-pods.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ content_type: task
44
weight: 60
55
min-kubernetes-server-version: 1.7
66
---
7-
87
<!--
98
reviewers:
109
- rickypai
@@ -20,14 +19,18 @@ min-kubernetes-server-version: 1.7
2019
<!--
2120
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.
2221
23-
Modification not using HostAliases is not suggested because the file is managed by the kubelet and can be overwritten on during Pod creation/restart.
22+
The Kubernetes project recommends modifying DNS configuration using the `hostAliases` field
23+
(part of the `.spec` for a Pod), and not by using an init container or other means to edit `/etc/hosts`
24+
directly.
25+
Change made in other ways may be overwritten by the kubelet during Pod creation or restart.
2426
-->
2527
当 DNS 配置以及其它选项不合理的时候,通过向 Pod 的 `/etc/hosts` 文件中添加条目,
2628
可以在 Pod 级别覆盖对主机名的解析。你可以通过 PodSpec 的 HostAliases
2729
字段来添加这些自定义条目。
2830

29-
建议通过使用 HostAliases 来进行修改,因为该文件由 Kubelet 管理,并且
30-
可以在 Pod 创建/重启过程中被重写。
31+
Kubernetes 项目建议使用 `hostAliases` 字段(Pod `.spec` 的一部分)来修改 DNS 配置,
32+
而不是通过使用 Init 容器或其他方式直接编辑 `/etc/hosts`
33+
以其他方式所做的更改可能会在 Pod 创建或重启过程中被 kubelet 重写。
3134

3235
<!-- steps -->
3336

@@ -36,7 +39,7 @@ Modification not using HostAliases is not suggested because the file is managed
3639
3740
Start an Nginx Pod which is assigned a Pod IP:
3841
-->
39-
## 默认 hosts 文件内容
42+
## 默认 hosts 文件内容 {#default-hosts-file-content}
4043

4144
让我们从一个 Nginx Pod 开始,该 Pod 被分配一个 IP:
4245

@@ -65,7 +68,7 @@ nginx 1/1 Running 0 13s 10.200.0.4 worker0
6568
<!--
6669
The hosts file content would look like this:
6770
-->
68-
主机文件的内容如下所示
71+
hosts 文件的内容如下所示
6972

7073
```shell
7174
kubectl exec nginx -- cat /etc/hosts
@@ -97,7 +100,7 @@ For example: to resolve `foo.local`, `bar.local` to `127.0.0.1` and `foo.remote`
97100
`bar.remote` to `10.1.2.3`, you can configure HostAliases for a Pod under
98101
`.spec.hostAliases`:
99102
-->
100-
## 通过 HostAliases 增加额外条目
103+
## 通过 HostAliases 增加额外条目 {#adding-additional-entries-with-hostaliases}
101104

102105
除了默认的样板内容,你可以向 `hosts` 文件添加额外的条目。
103106
例如,要将 `foo.local``bar.local` 解析为 `127.0.0.1`

0 commit comments

Comments
 (0)