Drain API pods before Kubernetes shutdown
Dependency Audit / dependency-audit (push) Successful in 1m51s
Deployment Installer / deployment-installer (push) Successful in 6s
Security Audit / security-audit (push) Successful in 11m37s

This commit is contained in:
2026-08-05 21:55:32 +02:00
parent 3b9ae901dd
commit 389df7c3d5
3 changed files with 39 additions and 0 deletions
@@ -168,6 +168,7 @@ def render_kubernetes(
readiness_path="/health/ready",
liveness_path="/health",
probe_host=public_host,
graceful_shutdown_seconds=10,
extra_environment=_role_database_environment(environment, "API"),
),
_service(
@@ -658,6 +659,7 @@ def _deployment(
readiness_path: str | None = None,
liveness_path: str | None = None,
probe_host: str | None = None,
graceful_shutdown_seconds: int = 0,
extra_environment: Mapping[str, str] | None = None,
selector_labels: Mapping[str, str] | None = None,
) -> dict[str, Any]:
@@ -715,6 +717,18 @@ def _deployment(
container_port or 8000,
host=probe_host,
)
if graceful_shutdown_seconds:
container["lifecycle"] = {
"preStop": {
"exec": {
"command": [
"/bin/sh",
"-c",
f"sleep {graceful_shutdown_seconds}",
]
}
}
}
pod_spec: dict[str, Any] = {
"serviceAccountName": service_account,
"automountServiceAccountToken": False,
@@ -734,6 +748,11 @@ def _deployment(
}
],
}
if graceful_shutdown_seconds:
pod_spec["terminationGracePeriodSeconds"] = max(
30,
graceful_shutdown_seconds + 20,
)
container["volumeMounts"] = [{"name": "tmp", "mountPath": "/tmp"}]
if s3_ca_secret_name:
pod_spec["volumes"].append(_s3_ca_volume(s3_ca_secret_name))