Or, maybe, not exactly inconsistency but now it's a bit misleading...
In the Kubernetes Container Lifecycle there is a suggestion to use preStop handler like this: command: ["sh", "-c", "sleep 10"]
Problem is that by default Spring Boot paketo images from now on use paketobuildpacks/builder-jammy-java-tiny image, which does not have any shell.
So, either a new recipe should be suggested or a word of warning should say that for default spring boot images that won't work anymore.
As a suggestion - maybe include "sleep" command into the image, so something like this would work?
lifecycle:
preStop:
exec:
command:
- sleep
- 60
Comment From: philwebb
We also have #20995 open
Comment From: andrej-urvantsev
Then this ticket can be considered mostly as a documentation update and maybe worth to review #20995 in the light that situation has changed now - by default(using paketo buildpacks) there is no option to execute shell commands in container anymore.
Comment From: andrej-urvantsev
@philwebb maybe https://github.com/spring-projects/spring-boot/issues/20995 is not needed anymore - https://github.com/spring-projects/spring-boot/issues/20995#issuecomment-2593761197
Since 1.32 is GA and sleep option is enabled there, then right thing to do would be just to update the documentation.
Comment From: mhalbritter
The sleep option in the Kubernetes preStop hook is behind a feature gate: https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#hook-handler-implementations
Sleep - Pauses the container for a specified duration. This is a beta-level feature default enabled by the PodLifecycleSleepAction feature gate.
Comment From: andrej-urvantsev
@mhalbritter from the release notes 1.32: PodLifecycleSleepAction is graduated to GA
Unfortunately, don't have 1.32 yet to verify, but looks like it's GA now.
Comment From: mhalbritter
Huh, yeah, looks like it. Then the doc is outdated.
Comment From: mhalbritter
Just tested it with Kubernetes 1.32.0 and
lifecycle:
preStop:
sleep:
seconds: 10
works.
We'll update the documentation.
Comment From: billkoch
For folks that aren't able to upgrade to Kubernetes 1.32, I humbly offer upmc-enterprises-graceful-shutdown-spring-boot-starter (an open source library I maintain) which adds an Actuator endpoint (/actuator/preStopHook/{some-delay-in-ms}) that can be used in the preStop configuration.