<p>Does anyone had success implementing preStop hook with distroless/java17:nonroot ? Here is my (default) deployment:</p>
<pre class="lang-java prettyprint-override"><code># [...]
          lifecycle:
            preStop:
              exec:
                command: [&quot;sh&quot;, &quot;-c&quot;, &quot;sleep 10&quot;]

          securityContext:
            readOnlyRootFilesystem: true
            allowPrivilegeEscalation: false
            privileged: false
            runAsUser: 65532
            capabilities:
              drop:
                - ALL

          volumeMounts:
            - name: tmp-volume
              mountPath: /tmp
</code></pre>

Jonathan Chevalier
<p>Solved using actuator endpoint</p>
<pre class="lang-java prettyprint-override"><code>@Slf4j
@Component
@ControllerEndpoint(id = &quot;preStopHook&quot;)
class WebMvcPreStopHookEndpoint {

  @ResponseStatus(OK)
  @GetMapping(&quot;/{delayInMillis}&quot;)
  public ResponseEntity&lt;Void&gt; preStopHook(@PathVariable(&quot;delayInMillis&quot;) final long delayInMillis)
      throws InterruptedException {
    log.info(&quot;[preStopHook] received signal to sleep for {}ms&quot;, delayInMillis);
    Thread.sleep(delayInMillis);
    return null;
  }
}
</code></pre>
