Merge pull request #36980 from ydFu/determine-reason-pod-failure

Update Determine the Reason for Pod Failure
pull/37103/head
Kubernetes Prow Robot 2022-09-30 05:40:30 -07:00 committed by GitHub
commit 76de58969a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 34 additions and 40 deletions

View File

@ -1,12 +1,12 @@
--- ---
title: Determine the Reason for Pod Failure title: Determine the Reason for Pod Failure
content_type: task content_type: task
weight: 30
--- ---
<!-- overview --> <!-- overview -->
This page shows how to write and read a Container This page shows how to write and read a Container termination message.
termination message.
Termination messages provide a way for containers to write Termination messages provide a way for containers to write
information about fatal events to a location where it can information about fatal events to a location where it can
@ -16,31 +16,25 @@ put in a termination message should also be written to
the general the general
[Kubernetes logs](/docs/concepts/cluster-administration/logging/). [Kubernetes logs](/docs/concepts/cluster-administration/logging/).
## {{% heading "prerequisites" %}} ## {{% heading "prerequisites" %}}
{{< include "task-tutorial-prereqs.md" >}}
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
<!-- steps --> <!-- steps -->
## Writing and reading a termination message ## Writing and reading a termination message
In this exercise, you create a Pod that runs one container. In this exercise, you create a Pod that runs one container.
The configuration file specifies a command that runs when The manifest for that Pod specifies a command that runs when the container starts:
the container starts.
{{< codenew file="debug/termination.yaml" >}} {{< codenew file="debug/termination.yaml" >}}
1. Create a Pod based on the YAML configuration file: 1. Create a Pod based on the YAML configuration file:
kubectl apply -f https://k8s.io/examples/debug/termination.yaml ```shell
kubectl apply -f https://k8s.io/examples/debug/termination.yaml
```
In the YAML file, in the `command` and `args` fields, you can see that the In the YAML file, in the `command` and `args` fields, you can see that the
container sleeps for 10 seconds and then writes "Sleep expired" to container sleeps for 10 seconds and then writes "Sleep expired" to
the `/dev/termination-log` file. After the container writes the `/dev/termination-log` file. After the container writes
@ -48,34 +42,42 @@ the container starts.
1. Display information about the Pod: 1. Display information about the Pod:
kubectl get pod termination-demo ```shell
kubectl get pod termination-demo
```
Repeat the preceding command until the Pod is no longer running. Repeat the preceding command until the Pod is no longer running.
1. Display detailed information about the Pod: 1. Display detailed information about the Pod:
kubectl get pod termination-demo --output=yaml ```shell
kubectl get pod termination-demo --output=yaml
```
The output includes the "Sleep expired" message: The output includes the "Sleep expired" message:
apiVersion: v1 ```yaml
kind: Pod apiVersion: v1
... kind: Pod
lastState: ...
terminated: lastState:
containerID: ... terminated:
exitCode: 0 containerID: ...
finishedAt: ... exitCode: 0
message: | finishedAt: ...
Sleep expired message: |
... Sleep expired
...
```
1. Use a Go template to filter the output so that it includes 1. Use a Go template to filter the output so that it includes only the termination message:
only the termination message:
kubectl get pod termination-demo -o go-template="{{range .status.containerStatuses}}{{.lastState.terminated.message}}{{end}}" ```shell
kubectl get pod termination-demo -o go-template="{{range .status.containerStatuses}}{{.lastState.terminated.message}}{{end}}"
```
If you are running a multi-container pod, you can use a Go template to include the container's name. By doing so, you can discover which of the containers is failing: If you are running a multi-container Pod, you can use a Go template to include the container's name.
By doing so, you can discover which of the containers is failing:
```shell ```shell
kubectl get pod multi-container-pod -o go-template='{{range .status.containerStatuses}}{{printf "%s:\n%s\n\n" .name .lastState.terminated.message}}{{end}}' kubectl get pod multi-container-pod -o go-template='{{range .status.containerStatuses}}{{printf "%s:\n%s\n\n" .name .lastState.terminated.message}}{{end}}'
@ -96,7 +98,7 @@ The total message length across all containers is limited to 12KiB, divided equa
For example, if there are 12 containers (`initContainers` or `containers`), each has 1024 bytes of available termination message space. For example, if there are 12 containers (`initContainers` or `containers`), each has 1024 bytes of available termination message space.
The default termination message path is `/dev/termination-log`. The default termination message path is `/dev/termination-log`.
You cannot set the termination message path after a Pod is launched You cannot set the termination message path after a Pod is launched.
In the following example, the container writes termination messages to In the following example, the container writes termination messages to
`/tmp/my-log` for Kubernetes to retrieve: `/tmp/my-log` for Kubernetes to retrieve:
@ -121,17 +123,9 @@ to use the last chunk of container log output if the termination message file
is empty and the container exited with an error. The log output is limited to is empty and the container exited with an error. The log output is limited to
2048 bytes or 80 lines, whichever is smaller. 2048 bytes or 80 lines, whichever is smaller.
## {{% heading "whatsnext" %}} ## {{% heading "whatsnext" %}}
* See the `terminationMessagePath` field in * See the `terminationMessagePath` field in
[Container](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#container-v1-core). [Container](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#container-v1-core).
* Learn about [retrieving logs](/docs/concepts/cluster-administration/logging/). * Learn about [retrieving logs](/docs/concepts/cluster-administration/logging/).
* Learn about [Go templates](https://golang.org/pkg/text/template/). * Learn about [Go templates](https://golang.org/pkg/text/template/).