[zh] Tidy up and fix links in tasks section (1/10)

This commit is contained in:
Qiming Teng
2020-08-09 19:17:48 +08:00
parent 664464806c
commit 15845b3223
9 changed files with 635 additions and 1103 deletions
@@ -17,46 +17,43 @@ your pods. But there are a number of ways to get even more information about you
前面我们介绍了如何使用 `kubectl get pods` 来查询 pod 的简单信息。
除此之外,还有一系列的方法来获取应用的更详细信息。
<!-- body -->
<!--
## Using `kubectl describe pod` to fetch details about pods
-->
## 使用 `kubectl describe pod` 命令获取 pod 详情
## 使用 `kubectl describe pod` 命令获取 Pod 详情
<!--
For this example we'll use a Deployment to create two pods, similar to the earlier example.
-->
与之前的例子类似,我们使用一个 Deployment 来创建两个 pod。
与之前的例子类似,我们使用一个 Deployment 来创建两个 Pod。
{{< codenew file="application/nginx-with-request.yaml" >}}
<!--
Create deployment by running following command:
-->
使用如下命令创建 deployment
使用如下命令创建 Deployment
```shell
kubectl apply -f https://k8s.io/examples/application/nginx-with-request.yaml
```
```none
```
deployment.apps/nginx-deployment created
```
<!--
Check pod status by following command:
-->
使用如下命令查看 pod 状态:
使用如下命令查看 Pod 状态:
```shell
kubectl get pods
```
```none
```
NAME READY STATUS RESTARTS AGE
nginx-deployment-1006230814-6winp 1/1 Running 0 11s
nginx-deployment-1006230814-fmgu3 1/1 Running 0 11s
@@ -65,13 +62,13 @@ nginx-deployment-1006230814-fmgu3 1/1 Running 0 11s
<!--
We can retrieve a lot more information about each of these pods using `kubectl describe pod`. For example:
-->
我们可以使用 `kubectl describe pod` 命令来查询每个 pod 的更多信息,比如:
我们可以使用 `kubectl describe pod` 命令来查询每个 Pod 的更多信息,比如:
```shell
kubectl describe pod nginx-deployment-1006230814-6winp
```
```none
```
Name: nginx-deployment-1006230814-6winp
Namespace: default
Node: kubernetes-node-wul5/10.240.0.9
@@ -130,34 +127,37 @@ Events:
Here you can see configuration information about the container(s) and Pod (labels, resource requirements, etc.),
as well as status information about the container(s) and Pod (state, readiness, restart count, events, etc.).
-->
这里可以看到容器和 pod 的 label、资源需求等配置信息,还可以看到状态、就绪态、重启次数、事件等状态信息。
这里可以看到容器和 Pod 的标签、资源需求等配置信息,还可以看到状态、就绪态、
重启次数、事件等状态信息。
<!--
The container state is one of Waiting, Running, or Terminated.
Depending on the state, additional information will be provided -- here you can see that for a container in Running state, the system tells you when the container started.
-->
容器状态包括 Waiting、Running 和 Terminated。
根据状态的不同,将提供额外的信息——在这里可以看到,对于处于运行状态的容器,系统会告诉您容器的启动时间。
容器状态 Waiting、Running 和 Terminated 之一
根据状态的不同,还有对应的额外的信息 —— 在这里可以看到,
对于处于运行状态的容器,系统会告诉你容器的启动时间。
<!--
Ready tells you whether the container passed its last readiness probe.
(In this case, the container does not have a readiness probe configured; the container is assumed to be ready if no readiness probe is configured.)
-->
Ready 指示是否通过了最后一个就绪探测。
(在本例中,容器没有配置就绪探测;如果没有配置就绪探测,则假定容器已经就绪。)
Ready 指示是否通过了最后一个就绪探测。
(在本例中,容器没有配置就绪探测;如果没有配置就绪探测,则假定容器已经就绪。)
<!--
Restart Count tells you how many times the container has been restarted;
this information can be useful for detecting crash loops in containers that are configured with a restart policy of 'always.'
-->
Restart Count 告诉容器已重启的次数;
这些信息对于定位配置了“always”重启策略的容器持续崩溃问题非常有用。
Restart Count 告诉容器已重启的次数;
这些信息对于定位配置了 “Always” 重启策略的容器持续崩溃问题非常有用。
<!--
Currently the only Condition associated with a Pod is the binary Ready condition,
which indicates that the pod is able to service requests and should be added to the load balancing pools of all matching services.
-->
目前,唯一与 Pod 有关的状态是就绪状态,这表明 Pod 能够为请求提供服务,并且应该添加到相应服务的负载平衡池中。
目前,唯一与 Pod 有关的状态是 Ready 状况,该状况表明 Pod 能够为请求提供服务,
并且应该添加到相应服务的负载均衡池中。
<!--
Lastly, you see a log of recent events related to your Pod.
@@ -166,19 +166,15 @@ The system compresses multiple identical events by indicating the first and last
"SubobjectPath" tells you which object (e.g. container within the pod) is being referred to,
and "Reason" and "Message" tell you what happened.
-->
最后,您将看到与 Pod 相关的近期事件。
系统通过指示第一次和最后一次看到以及看到的次数来压缩多个相同的事件。
“From”表示记录事件的组件,
“SubobjectPath”告诉引用了哪个对象(例如pod中的容器)
“Reason”“Message”告诉发生了什么。
最后,你还可以看到与 Pod 相关的近期事件。
系统通过指示第一次和最后一次看到事件以及看到该事件的次数来压缩多个相同的事件。
“From” 标明记录事件的组件,
“SubobjectPath” 告诉引用了哪个对象例如 Pod 中的容器
“Reason”“Message” 告诉发生了什么。
<!--
## Example: debugging Pending Pods
-->
## 例子: 调试 Pending Pods
<!--
A common scenario that you can detect using events is when you've created a Pod that won't fit on any node.
For example, the Pod might request more resources than are free on any node,
or it might specify a label selector that doesn't match any nodes.
@@ -187,19 +183,20 @@ on a four-node cluster where each (virtual) machine has 1 CPU.
In that case one of the Pods will not be able to schedule.
(Note that because of the cluster addon pods such as fluentd, skydns, etc., that run on each node, if we requested 1000 millicores then none of the Pods would be able to schedule.)
-->
一个常见的场景是,当你创建了一个 Pod,但是他没有被调度到任何一个 node,可以使用 event 来调试。
比如说,这个 Pod 需求的资源比较多,没有任何一个 node 能够满足,或者它指定了一个标签,没有 node 被匹配到。
假如,我们创建之前的 Deployment 时指定副本数是5(不再是2),并且需求 600 millicore(不再是 500),
对于一个4个节点的集群并且每个节点只有1个CPU
这个情况下,至少有一个 Pod 不能被调度。
(需要注意的是,其他集群组件,比如 fluentd、skydns等等会在每个 node 上运行,
如果我们需求 1000 millicore,那么将不会有 Pod 会被调度。)
## 例子: 调试 Pending 状态的 Pod
可以使用事件来调试的一个常见的场景是,你创建 Pod 无法被调度到任何节点。
比如,Pod 请求的资源比较多,没有任何一个节点能够满足,或者它指定了一个标签,没有节点可匹配
假定我们创建之前的 Deployment 时指定副本数是 5(不再是 2),并且请求 600 毫核(不再是 500),
对于一个 4 个节点的集群,若每个节点只有 1 个 CPU,这时至少有一个 Pod 不能被调度。
(需要注意的是,其他集群插件 Pod,比如 fluentd、skydns 等等会在每个节点上运行,
如果我们需求 1000 毫核,将不会有 Pod 会被调度。)
```shell
kubectl get pods
```
```none
```
NAME READY STATUS RESTARTS AGE
nginx-deployment-1006230814-6winp 1/1 Running 0 7m
nginx-deployment-1006230814-fmgu3 1/1 Running 0 7m
@@ -211,13 +208,14 @@ nginx-deployment-1370807587-fz9sd 0/1 Pending 0 1m
<!--
To find out why the nginx-deployment-1370807587-fz9sd pod is not running, we can use `kubectl describe pod` on the pending Pod and look at its events:
-->
为了查找 Pod nginx-deployment-1370807587-fz9sd 没有运行的原因,我们可以使用 `kubectl describe pod` 命令查询处理 pending 状态的 Pod
为了查找 Pod nginx-deployment-1370807587-fz9sd 没有运行的原因,我们可以使用
`kubectl describe pod` 命令描述 Pod,查看其事件:
```shell
kubectl describe pod nginx-deployment-1370807587-fz9sd
```
```none
```
Name: nginx-deployment-1370807587-fz9sd
Namespace: default
Node: /
@@ -256,13 +254,13 @@ Here you can see the event generated by the scheduler saying that the Pod failed
The message tells us that there were not enough resources for the Pod on any of the nodes.
-->
这里你可以看到由调度器记录的事件,它表明了 Pod 不能被调度的原因是 `FailedScheduling`(也可能是其他值)。
这个信息表明没有任何 node 拥有足够多的资源。
其 message 部分表明没有任何节点拥有足够多的资源。
<!--
To correct this situation, you can use `kubectl scale` to update your Deployment to specify four or fewer replicas.
(Or you could just leave the one Pod pending, which is harmless.)
-->
要纠正这种情况,可以使用kubectl scale”更新部署,以指定个或更少的副本。
要纠正这种情况,可以使用 `kubectl scale` 更新 Deployment,以指定 4 个或更少的副本。
(或者你可以让 Pod 继续保持这个状态,这是无害的。)
<!--
@@ -270,7 +268,8 @@ Events such as the ones you saw at the end of `kubectl describe pod` are persist
provide high-level information on what is happening in the cluster.
To list all events you can use
-->
与您在“kubectl describe pod结尾处看到的一样,这些事件都保存在 etcd 中,并提供关于集群中正在发生的事情的高级信息。
你在 `kubectl describe pod` 结尾处看到的事件都保存在 etcd 中,
并提供关于集群中正在发生的事情的高级信息。
如果需要列出所有事件,可使用命令:
```shell
@@ -282,9 +281,9 @@ but you have to remember that events are namespaced.
This means that if you're interested in events for some namespaced object
(e.g. what happened with Pods in namespace `my-namespace`) you need to explicitly provide a namespace to the command:
-->
但是,需要注意的是,事件是按照 namespace 分组的。
如果你对些些 namespace 下的对象感兴趣(比如查看 namespace `my-namespace` 下的 Pod 事件,
你需要显式在命令行中指定 namespace
但是,需要注意的是,事件是区分名字空间的。
如果你对某些名字空间域的对象(比如 `my-namespace` 名字下的 Pod的事件感兴趣,
你需要显式在命令行中指定名字空间
```shell
kubectl get events --namespace=my-namespace
@@ -293,7 +292,7 @@ kubectl get events --namespace=my-namespace
<!--
To see events from all namespaces, you can use the `--all-namespaces` argument.
-->
查看所有 namespace 的事件,可使用 `--all-namespaces` 参数
查看所有 namespace 的事件,可使用 `--all-namespaces` 参数
<!--
In addition to `kubectl describe pod`, another way to get extra information about a pod (beyond what is provided by `kubectl get pod`) is
@@ -302,9 +301,11 @@ This will give you, in YAML format, even more information than `kubectl describe
Here you will see things like annotations (which are key-value metadata without the label restrictions, that is used internally by Kubernetes system components),
restart policy, ports, and volumes.
-->
除了 `kubectl describe pod` 以外,另一种获取 Pod 额外信息(超越 `kubectl get pod`)的方法是给 `kubectl get pod` 增加 `-o yaml` 输出格式参数。
这将以YAML格式为您提供比“kubectl describe pod”更多的信息——实际上是系统拥有的关于pod的所有信息
在这里,您将看到注释(没有标签限制的键值元数据,由Kubernetes系统组件在内部使用)、重启策略、端口和卷
除了 `kubectl describe pod` 以外,另一种获取 Pod 额外信息(除了 `kubectl get pod`)的方法
是给 `kubectl get pod` 增加 `-o yaml` 输出格式参数
该命令将以 YAML 格式为你提供比 `kubectl describe pod` 更多的信息 —— 实际上是系统拥有的关于 Pod 的所有信息
在这里,你将看到注解(没有标签限制的键值元数据,由 Kubernetes 系统组件在内部使用)、
重启策略、端口和卷等。
```shell
kubectl get pod nginx-deployment-1006230814-6winp -o yaml
@@ -382,10 +383,7 @@ status:
<!--
## Example: debugging a down/unreachable node
-->
## 例子: 调试 down/unreachable node
<!--
Sometimes when debugging it can be useful to look at the status of a node
-- for example, because you've noticed strange behavior of a Pod that's running on the node,
or to find out why a Pod won't schedule onto the node.
@@ -397,17 +395,19 @@ Notice the events that show the node is NotReady, and
also notice that the pods are no longer running
(they are evicted after five minutes of NotReady status).
-->
有时候,在调试时,查看节点的状态是很有用的——例如,因为您已经注意到节点上运行的 Pod 的奇怪行为,
## 示例:调试宕机或无法联系的节点
有时候,在调试时,查看节点的状态是很有用的 —— 例如,因为你已经注意到节点上运行的 Pod 的奇怪行为,
或者想了解为什么 Pod 不会调度到节点上。
与Pods一样,可以使用 `kubectl describe node``kubectl get node -o yaml` 来查询节点的详细信息。
例如,如果某个节点关闭(与网络断开连接,或者 kubelet 挂掉无法重新启动等等),您将看到以下情况。
请注意显示节点未就绪的事件,也请注意 pod 不再运行(它们在5分钟未就绪状态后被驱逐)。
Pod 一样,可以使用 `kubectl describe node``kubectl get node -o yaml` 来查询节点的详细信息。
例如,如果某个节点宕机(与网络断开连接,或者 kubelet 挂掉无法重新启动等等),你将看到以下情况。
请注意显示节点未就绪的事件,也请注意 Pod 不再运行(它们在5分钟未就绪状态后被驱逐)。
```shell
kubectl get nodes
```
```none
```
NAME STATUS ROLES AGE VERSION
kubernetes-node-861h NotReady <none> 1h v1.13.0
kubernetes-node-bols Ready <none> 1h v1.13.0
@@ -518,11 +518,8 @@ status:
systemUUID: ABE5F6B4-D44B-108B-C46A-24CCE16C8B6E
```
## {{% heading "whatsnext" %}}
<!--
Learn about additional debugging tools, including:
-->
@@ -536,11 +533,10 @@ Learn about additional debugging tools, including:
* [Connecting to containers via port forwarding](/docs/tasks/access-application-cluster/port-forward-access-application-cluster/)
* [Inspect Kubernetes node with crictl](/docs/tasks/debug-application-cluster/crictl/)
-->
* [日志](/docs/concepts/cluster-administration/logging/)
* [监控](/docs/tasks/debug-application-cluster/resource-usage-monitoring/)
* [使用 `exec` 进入容器](/docs/tasks/debug-application-cluster/get-shell-running-container/)
* [使用代理连接容器](/docs/tasks/extend-kubernetes/http-proxy-access-api/)
* [使用端口转发连接容器](/docs/tasks/access-application-cluster/port-forward-access-application-cluster/)
* [使用 crictl 检查节点](/docs/tasks/debug-application-cluster/crictl/)
* [日志](/zh/docs/concepts/cluster-administration/logging/)
* [监控](/zh/docs/tasks/debug-application-cluster/resource-usage-monitoring/)
* [使用 `exec` 进入容器](/zh/docs/tasks/debug-application-cluster/get-shell-running-container/)
* [使用代理连接容器](/zh/docs/tasks/extend-kubernetes/http-proxy-access-api/)
* [使用端口转发连接容器](/zh/docs/tasks/access-application-cluster/port-forward-access-application-cluster/)
* [使用 crictl 检查节点](/zh/docs/tasks/debug-application-cluster/crictl/)