Drain API pods before Kubernetes shutdown
This commit is contained in:
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user