diff --git a/content/zh/docs/concepts/services-networking/dns-pod-service.md b/content/zh/docs/concepts/services-networking/dns-pod-service.md index 2b9dfeb36f..4e6cb0f067 100644 --- a/content/zh/docs/concepts/services-networking/dns-pod-service.md +++ b/content/zh/docs/concepts/services-networking/dns-pod-service.md @@ -37,27 +37,27 @@ Kubernetes DNS 在集群上调度 DNS Pod 和服务,并配置 kubelet 以告 集群中定义的每个 Service (包括 DNS 服务器自身)都被赋予一个 DNS 名称。 默认情况下,客户端 Pod 的 DNS 搜索列表会包含 Pod 自身的名字空间和集群 的默认域。 ### Service 的名字空间 @@ -73,11 +73,11 @@ Pod 查询 `data` 时没有返回结果,因为使用的是 Pod 的名字空间 Pod 查询 `data.prod` 时则会返回预期的结果,因为查询中指定了名字空间。 DNS 查询可以使用 Pod 中的 `/etc/resolv.conf` 展开。kubelet 会为每个 Pod 生成此文件。例如,对 `data` 的查询可能被展开为 `data.test.svc.cluster.local`。 @@ -91,7 +91,7 @@ options ndots:5 ``` 概括起来,名字空间 `test` 中的 Pod 可以成功地解析 `data.prod` 或者 @@ -127,12 +127,14 @@ For more up-to-date specification, see ### A/AAAA records -"Normal" (not headless) Services are assigned a DNS A or AAAA record for a name of the -form `my-svc.my-namespace.svc.cluster-domain.example`. This resolves to the cluster IP +"Normal" (not headless) Services are assigned a DNS A or AAAA record, +depending on the IP family of the service, for a name of the form +`my-svc.my-namespace.svc.cluster-domain.example`. This resolves to the cluster IP of the Service. -"Headless" (without a cluster IP) Services are also assigned a DNS A record for -a name of the form `my-svc.my-namespace.svc.cluster-domain.example`. Unlike normal +"Headless" (without a cluster IP) Services are also assigned a DNS A or AAAA record, +depending on the IP family of the service, for a name of the form +`my-svc.my-namespace.svc.cluster-domain.example`. Unlike normal Services, this resolves to the set of IPs of the pods selected by the Service. Clients are expected to consume the set or else use standard round-robin selection from the set. @@ -314,9 +316,9 @@ along with its IP. Endpoints 对象可以为任何端点地址及其 IP 指定 `hostname`。 @@ -341,12 +343,13 @@ record unless `publishNotReadyAddresses=True` is set on the Service. {{< feature-state for_k8s_version="v1.22" state="stable" >}} -**前置条件**:`SetHostnameAsFQDN` -[特性门控](/zh/docs/reference/command-line-tools-reference/feature-gates/) -必须在 {{< glossary_tooltip text="API 服务器" term_id="kube-apiserver" >}} -上启用。 +当 Pod 配置为具有全限定域名 (FQDN) 时,其主机名是短主机名。 + 例如,如果你有一个具有完全限定域名 `busybox-1.default-subdomain.my-namespace.svc.cluster-domain.example` 的 Pod, + 则默认情况下,该 Pod 内的 `hostname` 命令返回 `busybox-1`,而 `hostname --fqdn` 命令返回 FQDN。 当你在 Pod 规约中设置了 `setHostnameAsFQDN: true` 时,kubelet 会将 Pod 的全限定域名(FQDN)作为该 Pod 的主机名记录到 Pod 所在名字空间。 @@ -392,10 +395,11 @@ following pod-specific DNS policies. These policies are specified in the for details on how DNS queries are handled in those cases. - "`ClusterFirstWithHostNet`": For Pods running with hostNetwork, you should explicitly set its DNS policy "`ClusterFirstWithHostNet`". + - Note: This is not supported on Windows. See [below](#dns-windows) for details - "`None`": It allows a Pod to ignore DNS settings from the Kubernetes environment. All DNS settings are supposed to be provided using the `dnsConfig` field in the Pod Spec. - See [Pod's DNS config](#pod-s-dns-config) subsection below. + See [Pod's DNS config](#pod-dns-config) subsection below. --> ### Pod 的 DNS 策略 {#pod-s-dns-policy} @@ -411,6 +415,7 @@ DNS 策略可以逐个 Pod 来设定。目前 Kubernetes 支持以下特定 Pod 了解在这些场景中如何处理 DNS 查询的信息。 - "`ClusterFirstWithHostNet`":对于以 hostNetwork 方式运行的 Pod,应显式设置其 DNS 策略 "`ClusterFirstWithHostNet`"。 + - 注意:这在 Windows 上不支持。 有关详细信息,请参见[下文](#dns-windows)。 - "`None`": 此设置允许 Pod 忽略 Kubernetes 环境中的 DNS 设置。Pod 会使用其 `dnsConfig` 字段 所提供的 DNS 设置。 参见 [Pod 的 DNS 配置](#pod-dns-config)节。 @@ -450,7 +455,7 @@ spec: ``` -输出类似于 - +输出类似于: ``` nameserver fd00:79:30::a search default.svc.cluster-domain.example svc.cluster-domain.example cluster-domain.example @@ -565,6 +569,42 @@ a list of search domains of up to 2048 characters. 如果启用 kube-apiserver 和 kubelet 的特性门控 `ExpandedDNSConfig`,Kubernetes 将可以有最多 32 个 搜索域以及一个最多 2048 个字符的搜索域列表。 + +## Windows 节点上的 DNS 解析 {#dns-windows} + + +- 在 Windows 节点上运行的 Pod 不支持 ClusterFirstWithHostNet。 + Windows 将所有带有 `.` 的名字视为 FQDN 并跳过 FQDN 解析。 +- 在 Windows 上,可以使用多个 DNS 解析器。由于这些解析器的行为上略有不同,建议使用 + [`Resolve-DNSName`](https://docs.microsoft.com/powershell/module/dnsclient/resolve-dnsname) + 这个 PowerShell cmdlet 进行名字查询解析。 +- 在 Linux 上,你会有一个 DNS 后缀列表,在全限定域名解析失败之后会使用这里的后缀。 + 在 Windows 上,你只能有 1 个 DNS 后缀,即与 Pod 的命名空间关联的 DNS + 后缀(例如:`mydns.svc.cluster.local`)。 Windows 可以解析能够使用此唯一后缀解析的 + FQDN、服务与网络名字。 + 例如,在 `default` 命名空间中产生的某个 Pod 将具有 DNS 后缀 `default.svc.cluster.local`。 + 在 Windows Pod 中,你可以解析 `kubernetes.default.svc.cluster.local` + 和 `kubernetes`,但无法解析部分限定名称(`kubernetes.default` 或 + `kubernetes.default.svc`)。 + ## {{% heading "whatsnext" %}}