From af7bca629d01aac9ce443419d94cbae99cc960fb Mon Sep 17 00:00:00 2001 From: John Coffey Date: Fri, 20 Nov 2026 15:53:29 -0700 Subject: [PATCH] Server pods keep serving while they leave the Services The server closes its listeners as soon as it gets SIGTERM, and Kubernetes takes a stopping pod out of the Services' endpoints at the same time, not before. A request routed to the pod in between finds the port closed: the lab's GitOps upgrade saw a webmail request fail with "could not reach the mail server" that way, once in four runs. server.shutdownDelaySeconds (5 by default) is a preStop sleep, the kubelet's own (stable since Kubernetes 1.34; the chart needs 1.35), so the image needs no sleep binary. 0 turns it off; it has to be less than terminationGracePeriodSeconds, which it counts toward. --- CHANGELOG.md | 3 +++ charts/inbuxa/VALUES.md | 5 ++++ .../inbuxa/templates/server/deployment.yaml | 10 +++++++ charts/inbuxa/tests/server_test.yaml | 26 +++++++++++++++++++ charts/inbuxa/values.schema.json | 5 ++++ charts/inbuxa/values.yaml | 6 +++++ 6 files changed, 55 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index abb3608..c59116d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -132,3 +132,6 @@ runs, pinned by digest. policies, then the upgrade check (nothing to do on a new store), then the seed, which Argo runs on every sync and which does nothing on a seeded store. +- `server.shutdownDelaySeconds` (5 by default): a stopping server pod keeps + serving that long, with a `preStop` sleep, while Kubernetes takes it out + of the Services, so a request routed to it in that moment isn't refused. diff --git a/charts/inbuxa/VALUES.md b/charts/inbuxa/VALUES.md index c97f6a2..fde71e7 100644 --- a/charts/inbuxa/VALUES.md +++ b/charts/inbuxa/VALUES.md @@ -385,6 +385,11 @@ Used for every group that sets no resources of its own Allowed: at least 0.\ Time for SMTP sessions in progress to finish when a pod stops +- **`server.shutdownDelaySeconds`** (integer)\ + Default: `5`.\ + Allowed: at least 0; at most 60.\ + Seconds a stopping pod keeps serving before the server is told to stop, while Kubernetes takes it out of the Services. Without it, a request routed in that moment finds the port closed. 0 turns it off; it counts toward terminationGracePeriodSeconds. + ### `server.topologySpread` Pods of a group are spread across nodes (never two on one node while another node has room) and, where the cluster has zones, across zones. diff --git a/charts/inbuxa/templates/server/deployment.yaml b/charts/inbuxa/templates/server/deployment.yaml index 74ccac6..7bcd854 100644 --- a/charts/inbuxa/templates/server/deployment.yaml +++ b/charts/inbuxa/templates/server/deployment.yaml @@ -285,6 +285,16 @@ spec: periodSeconds: 10 timeoutSeconds: 5 failureThreshold: 6 + {{- if gt (int $server.shutdownDelaySeconds) 0 }} + {{- if ge (int $server.shutdownDelaySeconds) (int $server.terminationGracePeriodSeconds) }} + {{- fail "server.shutdownDelaySeconds must be less than server.terminationGracePeriodSeconds" }} + {{- end }} + lifecycle: + # Keeps serving while the pod leaves the Services' endpoints + preStop: + sleep: + seconds: {{ int $server.shutdownDelaySeconds }} + {{- end }} readinessProbe: # Ready while the data store answers httpGet: diff --git a/charts/inbuxa/tests/server_test.yaml b/charts/inbuxa/tests/server_test.yaml index f6bb027..4b617e2 100644 --- a/charts/inbuxa/tests/server_test.yaml +++ b/charts/inbuxa/tests/server_test.yaml @@ -339,3 +339,29 @@ tests: - notExists: path: spec.template.spec.initContainers + + - it: keeps serving for a moment while a stopping pod leaves the Services + template: server/deployment.yaml + documentIndex: 0 + asserts: + - equal: + path: spec.template.spec.containers[0].lifecycle.preStop.sleep.seconds + value: 5 + + - it: leaves the delay out at 0 + set: + server.shutdownDelaySeconds: 0 + template: server/deployment.yaml + documentIndex: 0 + asserts: + - notExists: + path: spec.template.spec.containers[0].lifecycle + + - it: refuses a delay as long as the grace period + set: + server.shutdownDelaySeconds: 30 + server.terminationGracePeriodSeconds: 30 + template: server/deployment.yaml + asserts: + - failedTemplate: + errorPattern: shutdownDelaySeconds must be less than diff --git a/charts/inbuxa/values.schema.json b/charts/inbuxa/values.schema.json index 7839e71..82bff4c 100644 --- a/charts/inbuxa/values.schema.json +++ b/charts/inbuxa/values.schema.json @@ -535,6 +535,11 @@ "type": "integer", "minimum": 0 }, + "shutdownDelaySeconds": { + "type": "integer", + "minimum": 0, + "maximum": 60 + }, "topologySpread": { "type": "object", "additionalProperties": false, diff --git a/charts/inbuxa/values.yaml b/charts/inbuxa/values.yaml index 2bdf3e7..8bb037b 100644 --- a/charts/inbuxa/values.yaml +++ b/charts/inbuxa/values.yaml @@ -227,6 +227,12 @@ server: # Time for SMTP sessions in progress to finish when a pod stops terminationGracePeriodSeconds: 120 + # Seconds a stopping pod keeps serving before the server is told to stop, + # while Kubernetes takes it out of the Services. Without it, a request + # routed in that moment finds the port closed. 0 turns it off; it counts + # toward terminationGracePeriodSeconds. + shutdownDelaySeconds: 5 + # Pods of a group are spread across nodes (never two on one node while # another node has room) and, where the cluster has zones, across zones. topologySpread: -- 2.54.0