Skip to content

Commit fc45c35

Browse files
authored
Merge pull request #34595 from tengqm/zh-resync-debug-service
[zh-cn] Resync debug-service page
2 parents 8899c1f + 2e6e12b commit fc45c35

File tree

1 file changed

+70
-59
lines changed

1 file changed

+70
-59
lines changed

content/zh-cn/docs/tasks/debug/debug-application/debug-service.md

Lines changed: 70 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
content_type: concept
2+
content_type: task
33
title: 调试 Service
44
weight: 20
55
---
@@ -8,24 +8,26 @@ weight: 20
88
reviewers:
99
- thockin
1010
- bowei
11-
content_type: concept
11+
content_type: task
1212
title: Debug Services
1313
weight: 20
1414
-->
1515

1616
<!-- overview -->
17+
1718
<!--
1819
An issue that comes up rather frequently for new installations of Kubernetes is
1920
that a Service is not working properly. You've run your Pods through a
2021
Deployment (or other workload controller) and created a Service, but you
2122
get no response when you try to access it. This document will hopefully help
2223
you to figure out what's going wrong.
2324
-->
24-
对于新安装的 Kubernetes,经常出现的问题是 Service 无法正常运行。 你已经通过
25-
Deployment(或其他工作负载控制器)运行了 Pod,并创建 Service ,但是
26-
当你尝试访问它时,没有任何响应。此文档有望对你有所帮助并找出问题所在。
25+
对于新安装的 Kubernetes,经常出现的问题是 Service 无法正常运行。你已经通过
26+
Deployment(或其他工作负载控制器)运行了 Pod,并创建 Service ,
27+
但是当你尝试访问它时,没有任何响应。此文档有望对你有所帮助并找出问题所在。
2728

2829
<!-- body -->
30+
2931
<!--
3032
## Running commands in a Pod
3133
@@ -217,11 +219,13 @@ What would happen if you tried to access a non-existent Service? If
217219
you have another Pod that consumes this Service by name you would get
218220
something like:
219221
-->
220-
## Service 是否存在?
222+
## Service 是否存在? {#does-the-service-exist}
221223
222-
细心的读者会注意到我们实际上尚未创建 Service -这是有意而为之。 这一步有时会被遗忘,这是首先要检查的步骤。
224+
细心的读者会注意到我们实际上尚未创建 Service —— 这是有意而为之。
225+
这一步有时会被遗忘,这是首先要检查的步骤。
223226
224-
那么,如果我尝试访问不存在的 Service 会怎样? 假设你有另一个 Pod 通过名称匹配到 Service ,你将得到类似结果:
227+
那么,如果我尝试访问不存在的 Service 会怎样?
228+
假设你有另一个 Pod 通过名称匹配到 Service,你将得到类似结果:
225229
226230
```shell
227231
wget -O- hostnames
@@ -250,7 +254,7 @@ Error from server (NotFound): services "hostnames" not found
250254
Let's create the Service. As before, this is for the walk-through - you can
251255
use your own Service's details here.
252256
-->
253-
让我们创建 Service。 和以前一样,在这次实践中 - 你可以在此处使用自己的 Service 的内容。
257+
让我们创建 Service。 和以前一样,在这次实践中 —— 你可以在此处使用自己的 Service 的内容。
254258

255259
```shell
256260
kubectl expose deployment hostnames --port=80 --target-port=9376
@@ -281,7 +285,7 @@ As before, this is the same as if you had started the `Service` with YAML:
281285
-->
282286
现在你知道了 Service 确实存在。
283287

284-
同前,此步骤效果与通过 YAML 方式启动 'Service' 一样:
288+
同前,此步骤效果与通过 YAML 方式启动 `Service` 一样:
285289

286290
```yaml
287291
apiVersion: v1
@@ -314,7 +318,6 @@ traffic to `hostnames-*` Pods, these need to be reviewed.
314318

315319
Please refer to [Network Policies](/docs/concepts/services-networking/network-policies/) for more details.
316320
-->
317-
318321
## 是否存在影响目标 Pod 的网络策略入站规则?
319322

320323
如果你部署了任何可能影响到 `hostnames-*` Pod 的传入流量的网络策略入站规则,
@@ -330,7 +333,7 @@ name.
330333

331334
From a Pod in the same Namespace:
332335
-->
333-
## Service 是否可通过 DNS 名字访问?
336+
## Service 是否可通过 DNS 名字访问? {#does-the-service-work-by-dns-name}
334337

335338
通常客户端通过 DNS 名称来匹配到 Service。
336339

@@ -392,16 +395,16 @@ own cluster.
392395

393396
You can also try this from a `Node` in the cluster:
394397

395-
{{< note >}}
396-
10.0.0.10 is the cluster's DNS Service IP, yours might be different.
397-
{{< /note >}}
398398
-->
399399
注意这里的后缀:"default.svc.cluster.local"。"default" 是我们正在操作的命名空间。
400400
"svc" 表示这是一个 Service。"cluster.local" 是你的集群域,在你自己的集群中可能会有所不同。
401401

402402
你也可以在集群中的节点上尝试此操作:
403403

404404
{{< note >}}
405+
<!--
406+
10.0.0.10 is the cluster's DNS Service IP, yours might be different.
407+
-->
405408
10.0.0.10 是集群的 DNS 服务 IP,你的可能有所不同。
406409
{{< /note >}}
407410

@@ -443,7 +446,11 @@ options ndots:5
443446
<!--
444447
The `nameserver` line must indicate your cluster's DNS `Service`. This is
445448
passed into `kubelet` with the `--cluster-dns` flag.
449+
-->
450+
`nameserver` 行必须指示你的集群的 DNS Service,
451+
它是通过 `--cluster-dns` 标志传递到 kubelet 的。
446452
453+
<!--
447454
The `search` line must include an appropriate suffix for you to find the
448455
Service name. In this case it is looking for Services in the local
449456
Namespace ("default.svc.cluster.local"), Services in all Namespaces
@@ -454,22 +461,20 @@ to 6 total). The cluster suffix is passed into `kubelet` with the
454461
assumed to be "cluster.local". Your own clusters might be configured
455462
differently, in which case you should change that in all of the previous
456463
commands.
457-
458-
The `options` line must set `ndots` high enough that your DNS client library
459-
considers search paths at all. Kubernetes sets this to 5 by default, which is
460-
high enough to cover all of the DNS names it generates.
461464
-->
462-
`nameserver` 行必须指示你的集群的 DNS Service,
463-
它是通过 `--cluster-dns` 标志传递到 kubelet 的。
464-
465465
`search` 行必须包含一个适当的后缀,以便查找 Service 名称。
466-
在本例中,它查找本地命名空间(`default.svc.cluster.local`)中的服务和
467-
所有命名空间(`svc.cluster.local`)中的服务,最后在集群(`cluster.local`)中查找
468-
服务的名称。根据你自己的安装情况,可能会有额外的记录(最多 6 条)。
466+
在本例中,它查找本地命名空间(`default.svc.cluster.local`)中的服务和所有命名空间
467+
(`svc.cluster.local`)中的服务,最后在集群(`cluster.local`)中查找服务的名称。
468+
根据你自己的安装情况,可能会有额外的记录(最多 6 条)。
469469
集群后缀是通过 `--cluster-domain` 标志传递给 `kubelet` 的。
470470
本文中,我们假定后缀是 “cluster.local”。
471471
你的集群配置可能不同,这种情况下,你应该在上面的所有命令中更改它。
472472
473+
<!--
474+
The `options` line must set `ndots` high enough that your DNS client library
475+
considers search paths at all. Kubernetes sets this to 5 by default, which is
476+
high enough to cover all of the DNS names it generates.
477+
-->
473478
`options` 行必须设置足够高的 `ndots`,以便 DNS 客户端库考虑搜索路径。
474479
在默认情况下,Kubernetes 将这个值设置为 5,这个值足够高,足以覆盖它生成的所有 DNS 名称。
475480
@@ -512,7 +517,7 @@ Assuming you have confirmed that DNS works, the next thing to test is whether yo
512517
Service works by its IP address. From a Pod in your cluster, access the
513518
Service's IP (from `kubectl get` above).
514519
-->
515-
### Service 能够通过 IP 访问么?
520+
### Service 能够通过 IP 访问么? {#does-the-service-work-by-ip}
516521

517522
假设你已经确认 DNS 工作正常,那么接下来要测试的是你的 Service 能否通过它的 IP 正常访问。
518523
从集群中的一个 Pod,尝试访问 Service 的 IP(从上面的 `kubectl get` 命令获取)。
@@ -538,7 +543,8 @@ hostnames-632524106-tlaok
538543
If your Service is working, you should get correct responses. If not, there
539544
are a number of things that could be going wrong. Read on.
540545
-->
541-
如果 Service 状态是正常的,你应该得到正确的响应。如果没有,有很多可能出错的地方,请继续阅读。
546+
如果 Service 状态是正常的,你应该得到正确的响应。
547+
如果没有,有很多可能出错的地方,请继续阅读。
542548

543549
<!--
544550
## Is the Service defined correctly?
@@ -547,7 +553,7 @@ It might sound silly, but you should really double and triple check that your
547553
`Service` is correct and matches your `Pod`'s port. Read back your `Service`
548554
and verify it:
549555
-->
550-
## Service 的配置是否正确?
556+
## Service 的配置是否正确? {#is-the-service-defined-correctly}
551557

552558
这听起来可能很愚蠢,但你应该两次甚至三次检查你的 Service 配置是否正确,并且与你的 Pod 匹配。
553559
查看你的 Service 配置并验证它:
@@ -614,7 +620,7 @@ actually being selected by the Service.
614620
615621
Earlier you saw that the Pods were running. You can re-check that:
616622
-->
617-
## Service 有 Endpoints 吗?
623+
## Service 有 Endpoints 吗? {#does-the-service-have-any-endpoints}
618624

619625
如果你已经走到了这一步,你已经确认你的 Service 被正确定义,并能通过 DNS 解析。
620626
现在,让我们检查一下,你运行的 Pod 确实是被 Service 选中的。
@@ -624,38 +630,43 @@ Earlier you saw that the Pods were running. You can re-check that:
624630
```shell
625631
kubectl get pods -l app=hostnames
626632
```
633+
627634
```none
628635
NAME READY STATUS RESTARTS AGE
629636
hostnames-632524106-bbpiw 1/1 Running 0 1h
630637
hostnames-632524106-ly40y 1/1 Running 0 1h
631638
hostnames-632524106-tlaok 1/1 Running 0 1h
632639
```
640+
633641
<!--
634642
The `-l app=hostnames` argument is a label selector configured on the Service.
635643
636644
The "AGE" column says that these Pods are about an hour old, which implies that
637645
they are running fine and not crashing.
646+
-->
647+
`-l app=hostnames` 参数是在 Service 上配置的标签选择器。
638648

649+
“AGE” 列表明这些 Pod 已经启动一个小时了,这意味着它们运行良好,而未崩溃。
650+
651+
<!--
639652
The "RESTARTS" column says that these pods are not crashing frequently or being
640653
restarted. Frequent restarts could lead to intermittent connectivity issues.
641654
If the restart count is high, read more about how to [debug pods](/docs/tasks/debug/debug-application/debug-pods).
642655
643656
Inside the Kubernetes system is a control loop which evaluates the selector of
644657
every Service and saves the results into a corresponding Endpoints object.
645658
-->
646-
`-l app=hostnames` 参数是在 Service 上配置的标签选择器。
647-
648-
"AGE" 列表明这些 Pod 已经启动一个小时了,这意味着它们运行良好,而未崩溃。
649-
650659
"RESTARTS" 列表明 Pod 没有经常崩溃或重启。经常性崩溃可能导致间歇性连接问题。
651660
如果重启次数过大,通过[调试 Pod](/zh-cn/docs/tasks/debug/debug-application/debug-pods)
652661
了解相关技术。
653662

654-
在 Kubernetes 系统中有一个控制回路,它评估每个 Service 的选择算符,并将结果保存到 Endpoints 对象中。
663+
在 Kubernetes 系统中有一个控制回路,它评估每个 Service 的选择算符,并将结果保存到
664+
Endpoints 对象中。
655665

656666
```shell
657667
kubectl get endpoints hostnames
658668
```
669+
659670
```
660671
NAME ENDPOINTS
661672
hostnames 10.244.0.5:9376,10.244.0.6:9376,10.244.0.7:9376
@@ -685,22 +696,23 @@ At the beginning of this walk-through, you verified the Pods themselves.
685696
Let's check again that the Pods are actually working - you can bypass the
686697
Service mechanism and go straight to the Pods, as listed by the Endpoints
687698
above.
688-
689-
{{< note >}}
690-
These commands use the Pod port (9376), rather than the Service port (80).
691-
{{< /note >}}
692-
693-
From within a Pod:
694699
-->
695-
## Pod 正常工作吗?
700+
## Pod 工作正常吗? {#are-the-pods-working}
696701

697702
至此,你知道你的 Service 已存在,并且已匹配到你的Pod。在本实验的开始,你已经检查了 Pod 本身。
698-
让我们再次检查 Pod 是否确实在工作 - 你可以绕过 Service 机制并直接转到 Pod,如上面的 Endpoint 所示。
703+
让我们再次检查 Pod 是否确实在工作 - 你可以绕过 Service 机制并直接转到 Pod,
704+
如上面的 Endpoints 所示。
699705

700706
{{< note >}}
707+
<!--
708+
These commands use the Pod port (9376), rather than the Service port (80).
709+
-->
701710
这些命令使用的是 Pod 端口(9376),而不是 Service 端口(80)。
702711
{{< /note >}}
703712

713+
<!--
714+
From within a Pod:
715+
-->
704716
在 Pod 中运行:
705717

706718
```shell
@@ -741,7 +753,7 @@ small set of mechanisms for providing the Service abstraction. If your
741753
cluster does not use kube-proxy, the following sections will not apply, and you
742754
will have to investigate whatever implementation of Services you are using.
743755
-->
744-
## kube-proxy 正常工作吗?
756+
## kube-proxy 正常工作吗? {#is-the-kube-proxy-working}
745757

746758
如果你到达这里,则说明你的 Service 正在运行,拥有 Endpoints,Pod 真正在提供服务。
747759
此时,整个 Service 代理机制是可疑的。让我们一步一步地确认它没问题。
@@ -751,18 +763,19 @@ Service 的默认实现(在大多数集群上应用的)是 kube-proxy。
751763
如果你的集群不使用 kube-proxy,则以下各节将不适用,你将必须检查你正在使用的 Service 的实现方式。
752764

753765
<!--
754-
## Is the kube-proxy working?
766+
## Is kube-proxy working?
755767
756768
Confirm that `kube-proxy` is running on your Nodes. Running directly on a
757769
Node, you should get something like the below:
758770
-->
759-
### kube-proxy 正常运行吗?
771+
### kube-proxy 正常运行吗? {#is-kube-proxy working}
760772

761-
确认 `kube-proxy` 正在节点上运行。 在节点上直接运行,你将会得到类似以下的输出:
773+
确认 `kube-proxy` 正在节点上运行。在节点上直接运行,你将会得到类似以下的输出:
762774

763775
```shell
764776
ps auxw | grep kube-proxy
765777
```
778+
766779
```none
767780
root 4194 0.4 0.1 101864 17696 ? Sl Jul04 25:43 /usr/local/bin/kube-proxy --master=https://kubernetes-master --kubeconfig=/var/lib/kube-proxy/kubeconfig --v=2
768781
```
@@ -826,7 +839,7 @@ Kube-proxy 可以以若干模式之一运行。在上述日志中,`Using iptab
826839
827840
In "iptables" mode, you should see something like the following on a Node:
828841
-->
829-
#### Iptables 模式
842+
#### Iptables 模式 {#iptables-mode}
830843

831844
在 "iptables" 模式中, 你应该可以在节点上看到如下输出:
832845

@@ -864,7 +877,7 @@ config (including node-ports and load-balancers).
864877
865878
In "ipvs" mode, you should see something like the following on a Node:
866879
-->
867-
#### IPVS 模式
880+
#### IPVS 模式 {#ipvs-mode}
868881

869882
在 "ipvs" 模式中, 你应该在节点下看到如下输出:
870883

@@ -901,7 +914,7 @@ hostnames(`10.0.1.175:80`) has 3 endpoints(`10.244.0.5:9376`,
901914
902915
In rare cases, you may be using "userspace" mode. From your Node:
903916
-->
904-
#### Userspace 模式
917+
#### Userspace 模式 {#userspace-mode}
905918

906919
在极少数情况下,你可能会用到 "userspace" 模式。在你的节点上运行:
907920

@@ -932,7 +945,7 @@ more time on it here.
932945
Assuming you do see one the above cases, try again to access your Service by
933946
IP from one of your Nodes:
934947
-->
935-
### kube-proxy 是否在运行?
948+
### kube-proxy 是否在执行代理操作? {#is-kube-proxy-proxying}
936949

937950
假设你确实遇到上述情况之一,请重试从节点上通过 IP 访问你的 Service :
938951

@@ -995,9 +1008,9 @@ back to themselves if they try to access their own Service VIP. The
9951008
`promiscuous-bridge`.
9961009
9971010
-->
998-
### 边缘案例: Pod 无法通过 Service IP 连接到它本身 {#a-pod-fails-to-reach-itself-via-the-service-ip}
1011+
### 边缘案例: Pod 无法通过 Service IP 连接到它本身 {#a-pod-fails-to-reach-itself-via-the-service-ip}
9991012

1000-
这听起来似乎不太可能,但是确实可能发生,并且应该可行
1013+
这听起来似乎不太可能,但是确实可能发生,并且应该可以工作
10011014

10021015
如果网络没有为“发夹模式(Hairpin)”流量生成正确配置,
10031016
通常当 `kube-proxy``iptables` 模式运行,并且 Pod 与桥接网络连接时,就会发生这种情况。
@@ -1097,21 +1110,19 @@ Contact us on
10971110
[Forum](https://discuss.kubernetes.io) or
10981111
[GitHub](https://github.com/kubernetes/kubernetes).
10991112
-->
1100-
## 寻求帮助
1113+
## 寻求帮助 {#seek-help}
11011114

11021115
如果你走到这一步,那么就真的是奇怪的事情发生了。你的 Service 正在运行,有 Endpoints 存在,
11031116
你的 Pods 也确实在提供服务。你的 DNS 正常,`iptables` 规则已经安装,`kube-proxy` 看起来也正常。
11041117
然而 Service 还是没有正常工作。这种情况下,请告诉我们,以便我们可以帮助调查!
11051118

1106-
通过
1107-
[Slack](https://slack.k8s.io/) 或者
1108-
[Forum](https://discuss.kubernetes.io) 或者
1109-
[GitHub](https://github.com/kubernetes/kubernetes)
1110-
联系我们。
1119+
通过 [Slack](https://slack.k8s.io/) 或者 [Forum](https://discuss.kubernetes.io) 或者
1120+
[GitHub](https://github.com/kubernetes/kubernetes) 联系我们。
11111121

11121122
## {{% heading "whatsnext" %}}
11131123

11141124
<!--
11151125
Visit [troubleshooting document](/docs/tasks/debug/) for more information.
11161126
-->
1117-
访问[故障排查文档](/zh-cn/docs/tasks/debug/) 获取更多信息。
1127+
访问[故障排查文档](/zh-cn/docs/tasks/debug/)获取更多信息。
1128+

0 commit comments

Comments
 (0)