You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/zh/docs/concepts/services-networking/add-entries-to-pod-etc-hosts-with-host-aliases.md
+54-44Lines changed: 54 additions & 44 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,67 +2,76 @@
2
2
title: 使用 HostAliases 向 Pod /etc/hosts 文件添加条目
3
3
content_type: concept
4
4
weight: 60
5
+
min-kubernetes-server-version: 1.7
5
6
---
6
7
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
+
-->
8
17
9
18
<!-- overview -->
10
19
11
20
<!--
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.
13
22
14
23
Modification not using HostAliases is not suggested because the file is managed by Kubelet and can be overwritten on during Pod creation/restart.
15
24
-->
25
+
当 DNS 配置以及其它选项不合理的时候,通过向 Pod 的 /etc/hosts 文件中添加条目,
26
+
可以在 Pod 级别覆盖对主机名的解析。你可以通过 PodSpec 的 HostAliases
27
+
字段来添加这些自定义条目。
16
28
17
-
当 DNS 配置以及其它选项不合理的时候,通过向 Pod 的 /etc/hosts 文件中添加条目,可以在 Pod 级别覆盖对主机名的解析。在 1.7 版本,用户可以通过 PodSpec 的 HostAliases 字段来添加这些自定义的条目。
18
-
19
-
建议通过使用 HostAliases 来进行修改,因为该文件由 Kubelet 管理,并且可以在 Pod 创建/重启过程中被重写。
20
-
29
+
建议通过使用 HostAliases 来进行修改,因为该文件由 Kubelet 管理,并且
30
+
可以在 Pod 创建/重启过程中被重写。
21
31
22
32
<!-- body -->
23
33
24
34
<!--
25
35
## Default Hosts File Content
26
36
27
-
Let's start an Nginx Pod which is assigned a Pod IP:
37
+
Start an Nginx Pod which is assigned a Pod IP:
28
38
-->
29
39
## 默认 hosts 文件内容
30
40
31
-
让我们从一个 Nginx Pod 开始,给该 Pod 分配一个 IP:
41
+
让我们从一个 Nginx Pod 开始,该 Pod 被分配一个 IP:
32
42
33
43
```shell
34
44
kubectl run nginx --image nginx --generator=run-pod/v1
35
45
```
36
46
37
-
```shell
47
+
```
38
48
pod/nginx created
39
49
```
40
50
41
51
<!--
42
52
Examine a Pod IP:
43
53
-->
44
-
检查Pod IP:
54
+
检查 Pod IP:
45
55
46
56
```shell
47
57
kubectl get pods --output=wide
48
58
```
49
59
50
-
```shell
60
+
```
51
61
NAME READY STATUS RESTARTS AGE IP NODE
52
62
nginx 1/1 Running 0 13s 10.200.0.4 worker0
53
63
```
54
64
55
65
<!--
56
66
The hosts file content would look like this:
57
67
-->
58
-
59
68
主机文件的内容如下所示:
60
69
61
70
```shell
62
71
kubectl exec nginx -- cat /etc/hosts
63
72
```
64
73
65
-
```none
74
+
```
66
75
# Kubernetes-managed hosts file.
67
76
127.0.0.1 localhost
68
77
::1 localhost ip6-localhost ip6-loopback
@@ -77,63 +86,63 @@ fe00::2 ip6-allrouters
77
86
By default, the `hosts` file only includes IPv4 and IPv6 boilerplates like
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.
当你在 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
0 commit comments