All Products
Search
Document Center

Configure container termination messages

Last Updated: Mar 05, 2021

This topic describes how to set the terminationMessagePath and terminationMessagePolicy fields for a container. This allows you to customize the termination message of a container.

Kubernetes can configure the source of a container termination message by using terminationMessagePath. When a container is terminated, Kubernetes retrieves the termination message from the termination message file specified by the terminationMessagePath field of the container. Default value: /dev/termination-log.

You can customize the terminationMessagePath field of a container for Kubernetes to use the content of the specified custom file to fulfill the termination message of the container when the container running process completes or fails. The maximum size of a termination message is 4 KB.

In the following example, the terminationMessagePath field is configured as /tmp/termination-log. The container writes the termination message to the /tmp/termination-log file for Kubernetes to receive.

apiVersion: v1
kind: Pod
metadata:
  name: msg-path-demo
spec:
  containers:
  - name: msg-path-demo-container
    image: debian
    terminationMessagePath: "/tmp/termination-log"

In addition, you can set the terminationMessagePolicy field of the container to further customize the container termination message. Default value: File. This value indicates that termination messages can be retrieved only from the termination message file. You can set the terminationMessagePolicy field to FallbackToLogsOnError. This value indicates the last part of the container log output is used as the termination message if the termination message file is empty when the container exits due to exceptions.

apiVersion: v1
kind: Pod
metadata:
  name: msg-path-demo
spec:
  containers:
  - name: msg-path-demo-container
    image: debian
    terminationMessagePath: "/tmp/termination-log"
    terminationMessagePolicy: "FallbackToLogsOnError"

The total size of 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 termination message sizes. For example, if a pod contains four InitContainers 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 intercepted.