In Kubernetes, the terminationMessagePath parameter is used to specify the paths of container termination messages and the terminationMessagePolicy parameter is used to specify the policies for container termination messages. This topic describes how to configure terminationMessagePath and terminationMessagePolicy for a container. This allows you to obtain and analyze termination messages if the container is terminated.
Configuration description
Kubernetes manages container termination messages by using the terminationMessagePath and terminationMessagePolicy parameters.
Parameter | Description |
terminationMessagePath | The path of the container termination message. If a container is terminated, Kubernetes retrieves the termination message from the termination message file whose directory is specified by the terminationMessagePath parameter of the container. Default value: You can specify the terminationMessagePath parameter for a container to fill the content of the specified file into the termination message of the container when the container running process completes or fails. A termination message can be up to 4 KB in size. |
terminationMessagePolicy | The policy for the container termination message. Default: File. Valid values:
|
The total size of the termination messages of all containers in a pod cannot exceed 12 KB. If the total size exceeds 12 KB, the state manager of Kubernetes sets a limit on the sizes of the termination messages. For example, if a pod contains four init containers and eight application containers, the state manager limits the termination message of each container to 1 KB. This indicates that only the first 1 KB of the termination message of each container is truncated.
Configuration example
In the following example, the terminationMessagePath parameter is set to /tmp/termination-log
. The container writes the termination message to the /tmp/termination-log
file. Then, Kubernetes retrieves the message from the specified directory.
apiVersion: v1
kind: Pod
metadata:
name: msg-path-demo
spec:
containers:
- name: msg-path-demo-container
image: registry.cn-shanghai.aliyuncs.com/eci_open/nginx:1.14.2
terminationMessagePath: "/tmp/termination-log"
You can use the terminationMessagePolicy parameter to configure a policy for container termination messages. Example:
apiVersion: v1
kind: Pod
metadata:
name: msg-path-demo
spec:
containers:
- name: msg-path-demo-container
image: registry.cn-shanghai.aliyuncs.com/eci_open/nginx:1.14.2
terminationMessagePath: "/tmp/termination-log"
terminationMessagePolicy: "FallbackToLogsOnError"