When deleting a pod or deploying a new version of a pod kubernetes should theoretically send a SIGTERM
to the process running and then wait gracePeriodSeconds
(30 by default) seconds before it sends a SIGKILL
.
I have encountered the problem that this first SIGTERM
never seems to be sent. The default settings in my cluster were never changed (kill is sent as expected after 30 seconds), so my assumption is that there might be something wrong, permissions or similar, with my Dockerfile (see below).
I've excluded there being an error in the graceful shutdown logic catching the SIGTERM
in the executable by kubectl exec
-ing into the pod and using kill -15
on the process which works as expected.
The Dockerfile looks as follows:
FROM debian:bullseye-slim AS app
ARG USERNAME=app
ARG USER_UID=1000
ARG USER_GID=$USER_UID
RUN apt update && apt install -y libssl-dev zstd ca-certificates pkg-config
RUN groupadd --gid $USER_GID $USERNAME \
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME
WORKDIR /home/$USERNAME
ARG RELEASE_DIR
ARG SERVICE
USER $USERNAME
COPY $RELEASE_DIR .
EXPOSE 8080
ENV CMD=./${SERVICE}
CMD ${CMD}
Is there something blatantly wrong here? Or does kubernetes require some additional config to actually send the termination signal as expected?