Skip to content

Commit 4b07eb7

Browse files
authored
Merge pull request #32188 from tengqm/zh-fix-nodelocaldns
[zh] Resync node local DNS page
2 parents 4ea7240 + c0a6047 commit 4b07eb7

File tree

1 file changed

+141
-52
lines changed

1 file changed

+141
-52
lines changed

content/zh/docs/tasks/administer-cluster/nodelocaldns.md

Lines changed: 141 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
---
2-
reviewers:
3-
- bowei
4-
- zihongz
52
title: 在 Kubernetes 集群中使用 NodeLocal DNSCache
63
content_type: task
74
---
85
<!--
9-
---
106
reviewers:
117
- bowei
128
- zihongz
139
title: Using NodeLocal DNSCache in Kubernetes clusters
1410
content_type: task
15-
---
1611
-->
1712

1813
<!-- overview -->
@@ -22,14 +17,10 @@ This page provides an overview of NodeLocal DNSCache feature in Kubernetes.
2217
-->
2318
本页概述了 Kubernetes 中的 NodeLocal DNSCache 功能。
2419

25-
26-
2720
## {{% heading "prerequisites" %}}
2821

29-
3022
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
3123

32-
3324
<!-- steps -->
3425

3526
<!--
@@ -40,11 +31,11 @@ This page provides an overview of NodeLocal DNSCache feature in Kubernetes.
4031
<!--
4132
NodeLocal DNSCache improves Cluster DNS performance by running a dns caching agent on cluster nodes as a DaemonSet. In today's architecture, Pods in ClusterFirst DNS mode reach out to a kube-dns serviceIP for DNS queries. This is translated to a kube-dns/CoreDNS endpoint via iptables rules added by kube-proxy. With this new architecture, Pods will reach out to the dns caching agent running on the same node, thereby avoiding iptables DNAT rules and connection tracking. The local caching agent will query kube-dns service for cache misses of cluster hostnames(cluster.local suffix by default).
4233
-->
43-
NodeLocal DNSCache 通过在集群节点上作为 DaemonSet 运行 dns 缓存代理来提高集群 DNS 性能。
44-
在当今的体系结构中,处于 ClusterFirst DNS 模式的 Pod 可以连接到 kube-dns serviceIP 进行 DNS 查询。
34+
NodeLocal DNSCache 通过在集群节点上作为 DaemonSet 运行 DNS 缓存代理来提高集群 DNS 性能。
35+
在当今的体系结构中,运行在 ClusterFirst DNS 模式下的 Pod 可以连接到 kube-dns `serviceIP` 进行 DNS 查询。
4536
通过 kube-proxy 添加的 iptables 规则将其转换为 kube-dns/CoreDNS 端点。
46-
借助这种新架构,Pods 将可以访问在同一节点上运行的 dns 缓存代理,从而避免了 iptables DNAT 规则和连接跟踪。
47-
本地缓存代理将查询 kube-dns 服务以获取集群主机名的缓存缺失(默认为 cluster.local 后缀)。
37+
借助这种新架构,Pods 将可以访问在同一节点上运行的 DNS 缓存代理,从而避免 iptables DNAT 规则和连接跟踪。
38+
本地缓存代理将查询 kube-dns 服务以获取集群主机名的缓存缺失(默认为 "`cluster.local`" 后缀)。
4839

4940
<!--
5041
## Motivation
@@ -55,29 +46,36 @@ NodeLocal DNSCache 通过在集群节点上作为 DaemonSet 运行 dns 缓存代
5546
* With the current DNS architecture, it is possible that Pods with the highest DNS QPS have to reach out to a different node, if there is no local kube-dns/CoreDNS instance.
5647
Having a local cache will help improve the latency in such scenarios.
5748
-->
58-
* 使用当前的 DNS 体系结构,如果没有本地 kube-dns/CoreDNS 实例,则具有最高 DNS QPS 的 Pod 可能必须延伸到另一个节点。
59-
在这种脚本下,拥有本地缓存将有助于改善延迟。
49+
* 使用当前的 DNS 体系结构,如果没有本地 kube-dns/CoreDNS 实例,则具有最高 DNS QPS
50+
的 Pod 可能必须延伸到另一个节点。
51+
在这种场景下,拥有本地缓存将有助于改善延迟。
6052

6153
<!--
6254
* Skipping iptables DNAT and connection tracking will help reduce [conntrack races](https://github.com/kubernetes/kubernetes/issues/56903) and avoid UDP DNS entries filling up conntrack table.
6355
-->
64-
* 跳过 iptables DNAT 和连接跟踪将有助于减少 [conntrack 竞争](https://github.com/kubernetes/kubernetes/issues/56903)并避免 UDP DNS 条目填满 conntrack 表。
56+
* 跳过 iptables DNAT 和连接跟踪将有助于减少
57+
[conntrack 竞争](https://github.com/kubernetes/kubernetes/issues/56903)
58+
并避免 UDP DNS 条目填满 conntrack 表。
6559

6660
<!--
6761
* Connections from local caching agent to kube-dns servie can be upgraded to TCP. TCP conntrack entries will be removed on connection close in contrast with UDP entries that have to timeout ([default](https://www.kernel.org/doc/Documentation/networking/nf_conntrack-sysctl.txt) `nf_conntrack_udp_timeout` is 30 seconds)
6862
-->
69-
* 从本地缓存代理到 kube-dns 服务的连接可以升级到 TCP 。
70-
TCP conntrack 条目将在连接关闭时被删除,相反 UDP 条目必须超时([默认](https://www.kernel.org/doc/Documentation/networking/nf_conntrack-sysctl.txt) `nf_conntrack_udp_timeout` 是 30 秒)
63+
* 从本地缓存代理到 kube-dns 服务的连接可以升级为 TCP 。
64+
TCP conntrack 条目将在连接关闭时被删除,相反 UDP 条目必须超时
65+
[默认](https://www.kernel.org/doc/Documentation/networking/nf_conntrack-sysctl.txt)
66+
`nf_conntrack_udp_timeout` 是 30 秒)。
7167

7268
<!--
7369
* Upgrading DNS queries from UDP to TCP would reduce tail latency attributed to dropped UDP packets and DNS timeouts usually up to 30s (3 retries + 10s timeout). Since the nodelocal cache listens for UDP DNS queries, applications don't need to be changed.
7470
-->
75-
* 将 DNS 查询从 UDP 升级到 TCP 将减少归因于丢弃的 UDP 数据包和 DNS 超时的尾部等待时间,通常长达 30 秒(3 次重试+ 10 秒超时)。
71+
* 将 DNS 查询从 UDP 升级到 TCP 将减少由于被丢弃的 UDP 包和 DNS 超时而带来的尾部等待时间;
72+
这类延时通常长达 30 秒(3 次重试 + 10 秒超时)。
73+
由于 nodelocal 缓存监听 UDP DNS 查询,应用不需要变更。
7674

7775
<!--
7876
* Metrics & visibility into dns requests at a node level.
7977
-->
80-
* 在节点级别对 dns 请求的度量和可见性。
78+
* 在节点级别对 DNS 请求的度量和可见性。
8179

8280
<!--
8381
* Negative caching can be re-enabled, thereby reducing number of queries to kube-dns service.
@@ -92,13 +90,12 @@ TCP conntrack 条目将在连接关闭时被删除,相反 UDP 条目必须超
9290
<!--
9391
This is the path followed by DNS Queries after NodeLocal DNSCache is enabled:
9492
-->
95-
启用 NodeLocal DNSCache 之后,这是 DNS 查询所遵循的路径:
96-
93+
启用 NodeLocal DNSCache 之后,DNS 查询所遵循的路径如下:
9794

9895
<!--
99-
{{< figure src="/images/docs/nodelocaldns.svg" alt="NodeLocal DNSCache flow" title="Nodelocal DNSCache flow" caption="This image shows how NodeLocal DNSCache handles DNS queries." >}}
96+
{{< figure src="/images/docs/nodelocaldns.svg" alt="NodeLocal DNSCache flow" title="Nodelocal DNSCache flow" caption="This image shows how NodeLocal DNSCache handles DNS queries." class="diagram-medium" >}}
10097
-->
101-
{{< figure src="/images/docs/nodelocaldns.svg" alt="NodeLocal DNSCache 流" title="Nodelocal DNSCache 流" caption="此图显示了 NodeLocal DNSCache 如何处理 DNS 查询。" >}}
98+
{{< figure src="/images/docs/nodelocaldns.svg" alt="NodeLocal DNSCache 流" title="Nodelocal DNSCache 流" caption="此图显示了 NodeLocal DNSCache 如何处理 DNS 查询。" class="diagram-medium" >}}
10299

103100
<!--
104101
## Configuration
@@ -110,8 +107,8 @@ This is the path followed by DNS Queries after NodeLocal DNSCache is enabled:
110107
-->
111108
{{< note >}}
112109
NodeLocal DNSCache 的本地侦听 IP 地址可以是任何地址,只要该地址不和你的集群里现有的 IP 地址发生冲突。
113-
推荐使用本地范围内的地址,例如,IPv4 链路本地区段 169.254.0.0/16 内的地址,
114-
或者 IPv6 唯一本地地址区段 fd00::/8 内的地址。
110+
推荐使用本地范围内的地址,例如,IPv4 链路本地区段 '169.254.0.0/16' 内的地址,
111+
或者 IPv6 唯一本地地址区段 'fd00::/8' 内的地址。
115112
{{< /note >}}
116113

117114
<!--
@@ -129,7 +126,8 @@ This feature can be enabled using the following steps:
129126
If you are using the sample manifest from the previous point, this will require to modify [the configuration line L70](https://github.com/kubernetes/kubernetes/blob/b2ecd1b3a3192fbbe2b9e348e095326f51dc43dd/cluster/addons/dns/nodelocaldns/nodelocaldns.yaml#L70) like this `health [__PILLAR__LOCAL__DNS__]:8080`
130127
-->
131128
* 如果使用 IPv6,在使用 IP:Port 格式的时候需要把 CoreDNS 配置文件里的所有 IPv6 地址用方括号包起来。
132-
如果你使用上述的示例清单,需要把 [配置行 L70](https://github.com/kubernetes/kubernetes/blob/b2ecd1b3a3192fbbe2b9e348e095326f51dc43dd/cluster/addons/dns/nodelocaldns/nodelocaldns.yaml#L70)
129+
如果你使用上述的示例清单,需要把
130+
[配置行 L70](https://github.com/kubernetes/kubernetes/blob/b2ecd1b3a3192fbbe2b9e348e095326f51dc43dd/cluster/addons/dns/nodelocaldns/nodelocaldns.yaml#L70)
133131
修改为 `health [__PILLAR__LOCAL__DNS__]:8080`
134132
<!--
135133
* Substitute the variables in the manifest with the right values:
@@ -143,13 +141,15 @@ If you are using the sample manifest from the previous point, this will require
143141
`<cluster-domain>` is "cluster.local" by default. `<node-local-address>` is the local listen IP address chosen for NodeLocal DNSCache.
144142
-->
145143
* 把清单里的变量更改为正确的值:
146-
* kubedns=`kubectl get svc kube-dns -n kube-system -o jsonpath={.spec.clusterIP}`
147144

148-
* domain=`<cluster-domain>`
145+
```
146+
kubedns=`kubectl get svc kube-dns -n kube-system -o jsonpath={.spec.clusterIP}`
147+
domain=<cluster-domain>
148+
localdns=<node-local-address>
149+
```
149150

150-
* localdns=`<node-local-address>`
151-
152-
`<cluster-domain>` 的默认值是 "cluster.local"。 `<node-local-address>` 是 NodeLocal DNSCache 选择的本地侦听 IP 地址。
151+
`<cluster-domain>` 的默认值是 "`cluster.local`"。`<node-local-address>`
152+
NodeLocal DNSCache 选择的本地侦听 IP 地址。
153153

154154
<!--
155155
* If kube-proxy is running in IPTABLES mode:
@@ -161,16 +161,16 @@ If you are using the sample manifest from the previous point, this will require
161161
`__PILLAR__CLUSTER__DNS__` and `__PILLAR__UPSTREAM__SERVERS__` will be populated by the node-local-dns pods.
162162
In this mode, node-local-dns pods listen on both the kube-dns service IP as well as `<node-local-address>`, so pods can lookup DNS records using either IP address.
163163
-->
164-
* 如果 kube-proxy 运行在 IPTABLES 模式:
164+
* 如果 kube-proxy 运行在 IPTABLES 模式:
165165

166-
``` bash
167-
sed -i "s/__PILLAR__LOCAL__DNS__/$localdns/g; s/__PILLAR__DNS__DOMAIN__/$domain/g; s/__PILLAR__DNS__SERVER__/$kubedns/g" nodelocaldns.yaml
168-
```
166+
``` bash
167+
sed -i "s/__PILLAR__LOCAL__DNS__/$localdns/g; s/__PILLAR__DNS__DOMAIN__/$domain/g; s/__PILLAR__DNS__SERVER__/$kubedns/g" nodelocaldns.yaml
168+
```
169169

170-
node-local-dns Pods 会设置 `__PILLAR__CLUSTER__DNS__``__PILLAR__UPSTREAM__SERVERS__`
171-
在此模式下, node-local-dns Pods 会同时侦听 kube-dns 服务的 IP 地址和 `<node-local-address>` 的地址,
172-
以便 Pods 可以使用其中任何一个 IP 地址来查询 DNS 记录。
173-
<!--
170+
node-local-dns Pods 会设置 `__PILLAR__CLUSTER__DNS__``__PILLAR__UPSTREAM__SERVERS__`
171+
在此模式下, node-local-dns Pods 会同时侦听 kube-dns 服务的 IP 地址和
172+
`<node-local-address>` 的地址,以便 Pods 可以使用其中任何一个 IP 地址来查询 DNS 记录。
173+
<!--
174174
* If kube-proxy is running in IPVS mode:
175175

176176
``` bash
@@ -179,32 +179,121 @@ If you are using the sample manifest from the previous point, this will require
179179
In this mode, node-local-dns pods listen only on `<node-local-address>`. The node-local-dns interface cannot bind the kube-dns cluster IP since the interface used for IPVS loadbalancing already uses this address.
180180
`__PILLAR__UPSTREAM__SERVERS__` will be populated by the node-local-dns pods.
181181
-->
182-
* 如果 kube-proxy 运行在 IPVS 模式:
182+
* 如果 kube-proxy 运行在 IPVS 模式:
183183

184-
``` bash
185-
sed -i "s/__PILLAR__LOCAL__DNS__/$localdns/g; s/__PILLAR__DNS__DOMAIN__/$domain/g; s/__PILLAR__DNS__SERVER__//g; s/__PILLAR__CLUSTER__DNS__/$kubedns/g" nodelocaldns.yaml
186-
```
184+
``` bash
185+
sed -i "s/__PILLAR__LOCAL__DNS__/$localdns/g; s/__PILLAR__DNS__DOMAIN__/$domain/g; s/__PILLAR__DNS__SERVER__//g; s/__PILLAR__CLUSTER__DNS__/$kubedns/g" nodelocaldns.yaml
186+
```
187187

188-
在此模式下,node-local-dns Pods 只会侦听 `<node-local-address>` 的地址。
189-
node-local-dns 接口不能绑定 kube-dns 的集群 IP 地址,因为 IPVS 负载均衡
190-
使用的接口已经占用了该地址。
191-
node-local-dns Pods 会设置 `__PILLAR__UPSTREAM__SERVERS__`
188+
在此模式下,node-local-dns Pods 只会侦听 `<node-local-address>` 的地址。
189+
node-local-dns 接口不能绑定 kube-dns 的集群 IP 地址,因为 IPVS 负载均衡
190+
使用的接口已经占用了该地址。
191+
node-local-dns Pods 会设置 `__PILLAR__UPSTREAM__SERVERS__`
192192

193193
<!--
194194
* Run `kubectl create -f nodelocaldns.yaml`
195195
* If using kube-proxy in IPVS mode, `--cluster-dns` flag to kubelet needs to be modified to use `<node-local-address>` that NodeLocal DNSCache is listening on.
196196
Otherwise, there is no need to modify the value of the `--cluster-dns` flag, since NodeLocal DNSCache listens on both the kube-dns service IP as well as `<node-local-address>`.
197197
-->
198198
* 运行 `kubectl create -f nodelocaldns.yaml`
199-
* 如果 kube-proxy 运行在 IPVS 模式,需要修改 kubelet 的 `--cluster-dns` 参数为 NodeLocal DNSCache 正在侦听的 `<node-local-address>` 地址。
200-
否则,不需要修改 `--cluster-dns` 参数,因为 NodeLocal DNSCache 会同时侦听 kube-dns 服务的 IP 地址和 `<node-local-address>` 的地址。
199+
* 如果 kube-proxy 运行在 IPVS 模式,需要修改 kubelet 的 `--cluster-dns` 参数
200+
NodeLocal DNSCache 正在侦听的 `<node-local-address>` 地址。
201+
否则,不需要修改 `--cluster-dns` 参数,因为 NodeLocal DNSCache 会同时侦听
202+
kube-dns 服务的 IP 地址和 `<node-local-address>` 的地址。
201203

202204
<!--
203205
Once enabled, node-local-dns Pods will run in the kube-system namespace on each of the cluster nodes. This Pod runs [CoreDNS](https://github.com/coredns/coredns) in cache mode, so all CoreDNS metrics exposed by the different plugins will be available on a per-node basis.
204206

205207
You can disable this feature by removing the DaemonSet, using `kubectl delete -f <manifest>` . You should also revert any changes you made to the kubelet configuration.
206208
-->
207209
启用后,node-local-dns Pods 将在每个集群节点上的 kube-system 名字空间中运行。
208-
此 Pod 在缓存模式下运行 [CoreDNS](https://github.com/coredns/coredns) ,因此每个节点都可以使用不同插件公开的所有 CoreDNS 指标。
210+
此 Pod 在缓存模式下运行 [CoreDNS](https://github.com/coredns/coredns) ,
211+
因此每个节点都可以使用不同插件公开的所有 CoreDNS 指标。
212+
213+
如果要禁用该功能,你可以使用 `kubectl delete -f <manifest>` 来删除 DaemonSet。
214+
你还应该回滚你对 kubelet 配置所做的所有改动。
215+
216+
<!--
217+
## StubDomains and Upstream server Configuration
218+
-->
219+
## StubDomains 和上游服务器配置
220+
221+
<!--
222+
StubDomains and upstream servers specified in the `kube-dns` ConfigMap in the `kube-system` namespace
223+
are automatically picked up by `node-local-dns` pods. The ConfigMap contents need to follow the format
224+
shown in [the example](/docs/tasks/administer-cluster/dns-custom-nameservers/#example-1).
225+
The `node-local-dns` ConfigMap can also be modified directly with the stubDomain configuration
226+
in the Corefile format. Some cloud providers might not allow modifying `node-local-dns` ConfigMap directly.
227+
In those cases, the `kube-dns` ConfigMap can be updated.
228+
-->
229+
`node-local-dns` Pod 能够自动读取 `kube-system` 名字空间中 `kube-dns` ConfigMap
230+
中保存的 StubDomains 和上游服务器信息。ConfigMap 中的内容需要遵从
231+
[此示例](/zh/docs/tasks/administer-cluster/dns-custom-nameservers/#example-1)
232+
中所给的格式。
233+
`node-local-dns` ConfigMap 也可被直接修改,使用 Corefile 格式设置 stubDomain 配置。
234+
某些云厂商可能不允许直接修改 `node-local-dns` ConfigMap 的内容。
235+
在这种情况下,可以更新 `kube-dns` ConfigMap。
236+
237+
<!--
238+
## Setting memory limits
239+
-->
240+
## 设置内存限制
241+
242+
<!--
243+
node-local-dns pods use memory for storing cache entries and processing queries. Since they do not watch Kubernetes objects, the cluster size or the number of Services/Endpoints do not directly affect memory usage. Memory usage is influenced by the DNS query pattern.
244+
From [CoreDNS docs](https://github.com/coredns/deployment/blob/master/kubernetes/Scaling_CoreDNS.md),
245+
> The default cache size is 10000 entries, which uses about 30 MB when completely filled.
246+
-->
247+
`node-local-dns` Pod 使用内存来保存缓存项并处理查询。
248+
由于它们并不监视 Kubernetes 对象变化,集群规模或者 Service/Endpoints
249+
的数量都不会直接影响内存用量。内存用量会受到 DNS 查询模式的影响。
250+
根据 [CoreDNS 文档](https://github.com/coredns/deployment/blob/master/kubernetes/Scaling_CoreDNS.md),
251+
252+
> The default cache size is 10000 entries, which uses about 30 MB when completely filled.
253+
> (默认的缓存大小是 10000 个表项,当完全填充时会使用约 30 MB 内存)
254+
255+
<!--
256+
This would be the memory usage for each server block (if the cache gets completely filled).
257+
Memory usage can be reduced by specifying smaller cache sizes.
258+
259+
The number of concurrent queries is linked to the memory demand, because each extra
260+
goroutine used for handling a query requires an amount of memory. You can set an upper limit
261+
using the `max_concurrent` option in the forward plugin.
262+
-->
263+
这一数值是(缓存完全被填充时)每个服务器块的内存用量。
264+
通过设置小一点的缓存大小可以降低内存用量。
265+
266+
并发查询的数量会影响内存需求,因为用来处理查询请求而创建的 Go 协程都需要一定量的内存。
267+
你可以在 forward 插件中使用 `max_concurrent` 选项设置并发查询数量上限。
268+
269+
<!--
270+
If a node-local-dns pod attempts to use more memory than is available (because of total system
271+
resources, or because of a configured
272+
[resource limit](/docs/concepts/configuration/manage-resources-containers/)), the operating system
273+
may shut down that pod's container.
274+
If this happens, the container that is terminated (“OOMKilled”) does not clean up the custom
275+
packet filtering rules that it previously added during startup.
276+
The node-local-dns container should get restarted (since managed as part of a DaemonSet), but this
277+
will lead to a brief DNS downtime each time that the container fails: the packet filtering rules direct
278+
DNS queries to a local Pod that is unhealthy.
279+
-->
280+
如果一个 `node-local-dns` Pod 尝试使用的内存超出可提供的内存量
281+
(因为系统资源总量的,或者所配置的[资源约束](/zh/docs/concepts/configuration/manage-resources-containers/))的原因,
282+
操作系统可能会关闭这一 Pod 的容器。
283+
发生这种情况时,被终止的("OOMKilled")容器不会清理其启动期间所添加的定制包过滤规则。
284+
该 `node-local-dns` 容器应该会被重启(因其作为 DaemonSet 的一部分被管理),
285+
但因上述原因可能每次容器失败时都会导致 DNS 有一小段时间不可用:
286+
the packet filtering rules direct DNS queries to a local Pod that is unhealthy
287+
(包过滤器规则将 DNS 查询转发到本地某个不健康的 Pod)。
288+
289+
<!--
290+
You can determine a suitable memory limit by running node-local-dns pods without a limit and
291+
measuring the peak usage. You can also set up and use a
292+
[VerticalPodAutoscaler](https://github.com/kubernetes/autoscaler/tree/master/vertical-pod-autoscaler)
293+
in _recommender mode_, and then check its recommendations.
294+
-->
295+
通过不带限制地运行 `node-local-dns` Pod 并度量其内存用量峰值,你可以为其确定一个合适的内存限制值。
296+
你也可以安装并使用一个运行在 “Recommender Mode(建议者模式)” 的
297+
[VerticalPodAutoscaler](https://github.com/kubernetes/autoscaler/tree/master/vertical-pod-autoscaler),
298+
并查看该组件输出的建议信息。
209299
210-
如果要禁用该功能,你可以使用 `kubectl delete -f <manifest>` 来删除 DaemonSet。你还应该恢复你对 kubelet 配置所做的所有改动。

0 commit comments

Comments
 (0)