Support Boundaries for Kubernetes Service Account Token Renewal in Spark 3.5
0 reputation · 25 Feb 2023, 20:57 UTC
0 reputation · 25 Feb 2023, 20:57 UTC
Apache Spark's Kubernetes scheduler backend supports least-privilege authentication via Kubernetes service account tokens, yet the documented behavior for long-running applications that outlive these credentials remains ambiguous. In Spark 3.5, the default scheduler backend does not automatically refresh service account tokens or OAuth tokens for driver and executor pods; renewal is instead delegated to external sidecars or manual pod restarts. This leaves an unresolved boundary between Spark's internal authentication handling and cluster-level credential management.
For batch or Structured Streaming jobs that exceed the token lifetime, operators must choose between manual intervention, external renewal mechanisms, or restricting job duration. The core design question is whether Spark should integrate automatic token refresh into its Kubernetes scheduler or continue treating credential rotation as an external operational concern.
What is the documented support boundary for automatic service account token renewal in Spark's Kubernetes scheduler backend? Should long-running Spark applications on Kubernetes rely on external sidecars for token refresh, or is native integration expected? How does Spark 3.5 handle expired service account tokens for driver and executor pods without manual restarts?
35775 reputation · 26 Feb 2023, 05:20 UTC
Confirmed facts
Practical steps for long‑running jobs
/var/run/secrets/kubernetes.io/serviceaccount/token) and triggers a pod restart or token rotation when the token changes.spark.kubernetes.authenticate.driver.serviceAccountName setting to specify the account, then rely on cluster‑level mechanisms (e.g., CSI drivers, kube‑token‑refresh) to maintain validity.Note: The behavior described reflects Spark 3.5 as released through mid‑2024; subsequent releases may introduce native token‑refresh capabilities. Operators should verify the specific Spark and Kubernetes versions in their environment.
Use comments to ask for clarification. Post a solution as an answer.
35,775 reputation · 26 Feb 2023, 00:22 UTC
In Spark 3.5 the service‑account token is mounted as a projected volume at pod start. The kubelet will rewrite the file when the token expires, but the KubernetesClient in Spark does not watch the file or re‑initialize the underlying io.fabric8.kubernetes.client.KubernetesClient. As a result, Spark continues to use the cached token in memory and will fail to authenticate once the TTL elapses. The official documentation states that token renewal is an operational concern, not a built‑in feature.
Operators can either: