@@ -3,7 +3,6 @@ title: 调试 Pod
3
3
content_type : task
4
4
weight : 10
5
5
---
6
-
7
6
<!--
8
7
reviewers:
9
8
- mikedanese
@@ -16,23 +15,21 @@ weight: 10
16
15
<!-- overview -->
17
16
18
17
<!--
19
- This guide is to help users debug applications that are deployed into Kubernetes and not behaving correctly.
20
- This is *not* a guide for people who want to debug their cluster. For that you should check out
21
- [this guide](/docs/tasks/debug/debug-cluster).
18
+ This guide is to help users debug applications that are deployed into Kubernetes
19
+ and not behaving correctly. This is *not* a guide for people who want to debug their cluster.
20
+ For that you should check out [this guide](/docs/tasks/debug/debug-cluster).
22
21
-->
23
-
24
22
本指南帮助用户调试那些部署到 Kubernetes 上后没有正常运行的应用。
25
23
本指南 ** 并非** 指导用户如何调试集群。
26
24
如果想调试集群的话,请参阅[ 这里] ( /zh-cn/docs/tasks/debug/debug-cluster ) 。
27
25
28
-
29
26
<!-- body -->
30
27
31
28
<!--
32
29
## Diagnosing the problem
33
30
34
- The first step in troubleshooting is triage. What is the problem? Is it your Pods, your Replication Controller or
35
- your Service?
31
+ The first step in troubleshooting is triage. What is the problem?
32
+ Is it your Pods, your Replication Controller or your Service?
36
33
37
34
* [Debugging Pods](#debugging-pods)
38
35
* [Debugging Replication Controllers](#debugging-replication-controllers)
@@ -49,7 +46,8 @@ your Service?
49
46
<!--
50
47
### Debugging Pods
51
48
52
- The first step in debugging a Pod is taking a look at it. Check the current state of the Pod and recent events with the following command:
49
+ The first step in debugging a Pod is taking a look at it. Check the current
50
+ state of the Pod and recent events with the following command:
53
51
-->
54
52
### 调试 Pod {#debugging-pods}
55
53
@@ -60,7 +58,8 @@ kubectl describe pods ${POD_NAME}
60
58
```
61
59
62
60
<!--
63
- Look at the state of the containers in the pod. Are they all `Running`? Have there been recent restarts?
61
+ Look at the state of the containers in the pod. Are they all `Running`?
62
+ Have there been recent restarts?
64
63
65
64
Continue debugging depending on the state of the pods.
66
65
-->
@@ -71,32 +70,35 @@ Continue debugging depending on the state of the pods.
71
70
<!--
72
71
#### My pod stays pending
73
72
74
- If a Pod is stuck in `Pending` it means that it can not be scheduled onto a node. Generally this is because
75
- there are insufficient resources of one type or another that prevent scheduling. Look at the output of the
76
- `kubectl describe ...` command above. There should be messages from the scheduler about why it can not schedule
77
- your pod. Reasons include:
73
+ If a Pod is stuck in `Pending` it means that it can not be scheduled onto a node.
74
+ Generally this is because there are insufficient resources of one type or another
75
+ that prevent scheduling. Look at the output of the `kubectl describe ...` command above.
76
+ There should be messages from the scheduler about why it can not schedule your pod.
77
+ Reasons include:
78
78
-->
79
79
#### Pod 停滞在 Pending 状态 {#my-pod-stays-pending}
80
80
81
- 如果一个 Pod 停滞在 ` Pending ` 状态,表示 Pod 没有被调度到节点上。通常这是因为
82
- 某种类型的资源不足导致无法调度 。
81
+ 如果一个 Pod 停滞在 ` Pending ` 状态,表示 Pod 没有被调度到节点上。
82
+ 通常这是因为某种类型的资源不足导致无法调度 。
83
83
查看上面的 ` kubectl describe ... ` 命令的输出,其中应该显示了为什么没被调度的原因。
84
84
常见原因如下:
85
85
86
86
<!--
87
- * **You don't have enough resources**: You may have exhausted the supply of CPU or Memory in your cluster, in this case
88
- you need to delete Pods, adjust resource requests, or add new nodes to your cluster. See
89
- [Compute Resources document](/docs/concepts/configuration/manage-resources-containers/) for more information.
90
-
91
- * **You are using `hostPort`**: When you bind a Pod to a `hostPort` there are a limited number of places that pod can be
92
- scheduled. In most cases, `hostPort` is unnecessary, try using a Service object to expose your Pod. If you do require
93
- `hostPort` then you can only schedule as many Pods as there are nodes in your Kubernetes cluster.
87
+ * **You don't have enough resources**: You may have exhausted the supply of CPU
88
+ or Memory in your cluster, in this case you need to delete Pods, adjust resource
89
+ requests, or add new nodes to your cluster. See [Compute Resources document](/docs/concepts/configuration/manage-resources-containers/)
90
+ for more information.
91
+
92
+ * **You are using `hostPort`**: When you bind a Pod to a `hostPort` there are a
93
+ limited number of places that pod can be scheduled. In most cases, `hostPort`
94
+ is unnecessary, try using a Service object to expose your Pod. If you do require
95
+ `hostPort` then you can only schedule as many Pods as there are nodes in your Kubernetes cluster.
94
96
-->
95
- * ** 资源不足** :
97
+ * ** 资源不足** :
96
98
你可能耗尽了集群上所有的 CPU 或内存。此时,你需要删除 Pod、调整资源请求或者为集群添加节点。
97
99
更多信息请参阅[ 计算资源文档] ( /zh-cn/docs/concepts/configuration/manage-resources-containers/ )
98
100
99
- * ** 使用了 ` hostPort ` ** :
101
+ * ** 使用了 ` hostPort ` ** :
100
102
如果绑定 Pod 到 ` hostPort ` ,那么能够运行该 Pod 的节点就有限了。
101
103
多数情况下,` hostPort ` 是非必要的,而应该采用 Service 对象来暴露 Pod。
102
104
如果确实需要使用 ` hostPort ` ,那么集群中节点的个数就是所能创建的 Pod
@@ -105,8 +107,10 @@ scheduled. In most cases, `hostPort` is unnecessary, try using a Service object
105
107
<!--
106
108
#### My pod stays waiting
107
109
108
- If a Pod is stuck in the `Waiting` state, then it has been scheduled to a worker node, but it can't run on that machine.
109
- Again, the information from `kubectl describe ...` should be informative. The most common cause of `Waiting` pods is a failure to pull the image. There are three things to check:
110
+ If a Pod is stuck in the `Waiting` state, then it has been scheduled to a worker node,
111
+ but it can't run on that machine. Again, the information from `kubectl describe ...`
112
+ should be informative. The most common cause of `Waiting` pods is a failure to pull the image.
113
+ There are three things to check:
110
114
111
115
* Make sure that you have the name of the image correct.
112
116
* Have you pushed the image to the registry?
@@ -119,20 +123,21 @@ Again, the information from `kubectl describe ...` should be informative. The m
119
123
同样,` kubectl describe ... ` 命令的输出可能很有用。
120
124
` Waiting ` 状态的最常见原因是拉取镜像失败。要检查的有三个方面:
121
125
122
- * 确保镜像名字拼写正确
123
- * 确保镜像已被推送到镜像仓库
126
+ * 确保镜像名字拼写正确。
127
+ * 确保镜像已被推送到镜像仓库。
124
128
* 尝试手动是否能拉取镜像。例如,如果你在你的 PC 上使用 Docker,请运行 ` docker pull <镜像> ` 。
125
129
126
130
<!--
127
131
#### My pod is crashing or otherwise unhealthy
128
132
129
- Once your pod has been scheduled, the methods described in [Debug Running Pods](
130
- /docs/tasks/debug/debug-application/debug-running-pod/) are available for debugging.
133
+ Once your pod has been scheduled, the methods described in
134
+ [Debug Running Pods](/docs/tasks/debug/debug-application/debug-running-pod/)
135
+ are available for debugging.
131
136
-->
132
137
#### Pod 处于 Crashing 或别的不健康状态 {#my-pod-is-crashing-or-otherwise-unhealthy}
133
138
134
- 一旦 Pod 被调度,就可以采用
135
- [ 调试运行中的 Pod] ( /zh-cn/docs/tasks/debug/debug-application/debug-running-pod/ )
139
+ 一旦 Pod 被调度,
140
+ 就可以采用 [ 调试运行中的 Pod] ( /zh-cn/docs/tasks/debug/debug-application/debug-running-pod/ )
136
141
中的方法来进一步调试。
137
142
138
143
<!--
@@ -160,7 +165,7 @@ If you misspelled `command` as `commnd` then will give an error like this:
160
165
-->
161
166
可以做的第一件事是删除你的 Pod,并尝试带有 ` --validate ` 选项重新创建。
162
167
例如,运行 ` kubectl apply --validate -f mypod.yaml ` 。
163
- 如果 ` command ` 被误拼成 ` commnd ` ,你将会看到下面的错误信息:
168
+ 如果 ` command ` 被误拼成 ` commnd ` ,你将会看到下面的错误信息:
164
169
165
170
``` shell
166
171
I0805 10:43:25.129850 46757 schema.go:126] unknown field: commnd
@@ -175,9 +180,9 @@ The next thing to check is whether the pod on the apiserver
175
180
matches the pod you meant to create (e.g. in a yaml file on your local machine).
176
181
For example, run `kubectl get pods/mypod -o yaml > mypod-on-apiserver.yaml` and then
177
182
manually compare the original pod description, `mypod.yaml` with the one you got
178
- back from apiserver, `mypod-on-apiserver.yaml`. There will typically be some
179
- lines on the "apiserver" version that are not on the original version. This is
180
- expected. However, if there are lines on the original that are not on the apiserver
183
+ back from apiserver, `mypod-on-apiserver.yaml`. There will typically be some
184
+ lines on the "apiserver" version that are not on the original version. This is
185
+ expected. However, if there are lines on the original that are not on the apiserver
181
186
version, then this may indicate a problem with your pod spec.
182
187
-->
183
188
接下来就要检查的是 API 服务器上的 Pod 与你所期望创建的是否匹配
@@ -191,11 +196,12 @@ Pod 规约是有问题的。
191
196
<!--
192
197
### Debugging Replication Controllers
193
198
194
- Replication controllers are fairly straightforward. They can either create Pods or they can't. If they can't
195
- create pods, then please refer to the [instructions above](#debugging-pods) to debug your pods.
199
+ Replication controllers are fairly straightforward. They can either create Pods or they can't.
200
+ If they can't create pods, then please refer to the
201
+ [instructions above](#debugging-pods) to debug your pods.
196
202
197
- You can also use `kubectl describe rc ${CONTROLLER_NAME}` to introspect events related to the replication
198
- controller.
203
+ You can also use `kubectl describe rc ${CONTROLLER_NAME}` to introspect events
204
+ related to the replication controller.
199
205
-->
200
206
### 调试副本控制器 {#debugging-replication-controllers}
201
207
@@ -207,10 +213,11 @@ controller.
207
213
<!--
208
214
### Debugging Services
209
215
210
- Services provide load balancing across a set of pods. There are several common problems that can make Services
216
+ Services provide load balancing across a set of pods. There are several common problems that can make Services
211
217
not work properly. The following instructions should help debug Service problems.
212
218
213
- First, verify that there are endpoints for the service. For every Service object, the apiserver makes an `endpoints` resource available.
219
+ First, verify that there are endpoints for the service. For every Service object,
220
+ the apiserver makes an `endpoints` resource available.
214
221
215
222
You can view this resource with:
216
223
-->
@@ -241,8 +248,8 @@ IP addresses in the Service's endpoints.
241
248
<!--
242
249
#### My service is missing endpoints
243
250
244
- If you are missing endpoints, try listing pods using the labels that Service uses. Imagine that you have
245
- a Service where the labels are:
251
+ If you are missing endpoints, try listing pods using the labels that Service uses.
252
+ Imagine that you have a Service where the labels are:
246
253
-->
247
254
#### 服务缺少 Endpoints {#my-service-is-missing-endpoints}
248
255
@@ -263,7 +270,8 @@ You can use:
263
270
kubectl get pods --selector=name=nginx,type=frontend
264
271
```
265
272
266
- to list pods that match this selector. Verify that the list matches the Pods that you expect to provide your Service.
273
+ to list pods that match this selector. Verify that the list matches the Pods that you expect to provide your Service.
274
+ Verify that the pod's ` containerPort ` matches up with the Service's ` targetPort `
267
275
-->
268
276
你可以使用如下命令列出与选择算符相匹配的 Pod,并验证这些 Pod 是否归属于创建的服务:
269
277
@@ -298,8 +306,7 @@ You may also visit [troubleshooting document](/docs/tasks/debug/) for more infor
298
306
-->
299
307
如果上述方法都不能解决你的问题,
300
308
请按照[ 调试 Service 文档] ( /zh-cn/docs/tasks/debug/debug-application/debug-service/ ) 中的介绍,
301
- 确保你的 ` Service ` 处于 Running 态 ,有 ` Endpoints ` 被创建,` Pod ` 真的在提供服务;
302
- DNS 服务已配置并正常工作,iptables 规则也以安装并且 ` kube-proxy ` 也没有异常行为。
309
+ 确保你的 ` Service ` 处于 Running 状态 ,有 ` Endpoints ` 被创建,` Pod ` 真的在提供服务;
310
+ DNS 服务已配置并正常工作,iptables 规则也已安装并且 ` kube-proxy ` 也没有异常行为。
303
311
304
312
你也可以访问[ 故障排查文档] ( /zh-cn/docs/tasks/debug/ ) 来获取更多信息。
305
-
0 commit comments