Set a different default value for terminationMessagePolicy

1/10/2022

I would like to set the value of terminationMessagePolicy to FallbackToLogsOnError by default for all my pods.

Is there any way to do that?

I am running Kubernetes 1.21.

-- ITChap
kubernetes

2 Answers

1/10/2022

terminationMessagePolicy is a field in container spec, currently beside set it in your spec there is no cluster level setting that could change the default value ("File").

-- gohm'c
Source: StackOverflow

1/11/2022

Community wiki answer to summarise the topic.

The answer provided by the gohm'c is good. It is not possible to change this value from the cluster level. You can find more information about it in the official documentation:

Moreover, users can set the terminationMessagePolicy field of a Container for further customization. This field defaults to "File" which means the termination messages are retrieved only from the termination message file. By setting the terminationMessagePolicy to "FallbackToLogsOnError", you can tell Kubernetes 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 2048 bytes or 80 lines, whichever is smaller.

See also this page about Container v1 core API for 1.21 version. You can find there information about terminationMessagePolicy:

Indicate how the termination message should be populated. File will use the contents of terminationMessagePath to populate the container status message on both success and failure. FallbackToLogsOnError will 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 2048 bytes or 80 lines, whichever is smaller. Defaults to File. Cannot be updated.

This can be done only from the Container level.

-- Mikołaj Głodziak
Source: StackOverflow