Pod template for specifying tolerations when running Spark on Kubernetes
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
Spark on Kubernetes often needs scheduling control so driver and executor pods land on the right nodes. Taints and tolerations are the standard way to isolate workloads such as batch jobs, GPU tasks, or cost-optimized pools. This guide shows how to apply tolerations through Spark pod templates and verify that scheduler behavior is correct.
Core Topic Sections
Why tolerations matter for Spark workloads
In many clusters, nodes are segmented by taints:
- Dedicated analytics nodes.
- Spot or preemptible node pools.
- GPU nodes.
Without matching tolerations, Spark pods can stay pending or run on unintended nodes. Tolerations are necessary but not always sufficient, since affinity and resource requests also influence placement.
Spark pod template basics
Spark supports custom pod specs through template files. You can provide separate templates for:
- Driver pod.
- Executor pods.
Templates let you inject Kubernetes-level fields not directly exposed by Spark flags.
Driver template example:
Executor template example:
Submit Spark job with template references
Use Spark submit configuration keys to point at templates.
Ensure template paths are accessible in submission environment.
Combine tolerations with node selection
Tolerations only allow scheduling onto tainted nodes. They do not force it. To prefer specific pools, combine with node selectors or affinity.
This produces predictable placement and reduces noisy-neighbor effects.
Handle preemptible node pools deliberately
If you use preemptible nodes for executors, keep driver on stable nodes in many workloads.
Practical pattern:
- Driver template without preemptible toleration.
- Executor template with preemptible toleration.
- Spark dynamic allocation enabled with retry strategy.
This balances cost and reliability.
Validate scheduling behavior after deployment
Check pod placement and events, not only Spark logs.
Look for scheduler event messages about taints, tolerations, and node fit failures.
Troubleshooting common pending states
If pods stay pending:
- Toleration key, value, or effect mismatch.
- Missing resources on tolerated nodes.
- Affinity conflicts with available nodes.
- Template not applied due to wrong path or key.
Start with kubectl describe pod scheduler events, they usually identify the exact mismatch.
Governance and maintainability
Keep templates in version control and review them like code. For multi-team clusters, standardize toleration keys and values to avoid conflicting conventions.
A shared convention document for taints and tolerations prevents random scheduling drift across Spark jobs.
Common Pitfalls
- Adding tolerations and assuming Spark pods will prefer those nodes automatically.
- Applying only driver tolerations and forgetting executor template configuration.
- Using wrong effect string or mismatched key and value against node taints.
- Relying on templates without verifying they are actually loaded by submission config.
- Ignoring scheduler event logs and debugging only Spark application logs.
Summary
- Pod templates are the practical way to add tolerations to Spark driver and executors.
- Tolerations allow scheduling on tainted nodes but do not guarantee node preference.
- Combine tolerations with selectors or affinity for deterministic placement.
- Validate behavior through Kubernetes scheduling events and pod placement checks.
- Treat template configuration as versioned infrastructure policy, not one-off flags.
Related reading
- Pods-resources.sh Permission denied in iOS Project
- Pods stuck in PodInitializing state indefinitely
- Pods stuck in Terminating status
- PostgreSQL bitnami Helm Chart does not update the user password
- Possible reasons for timeout when trying to access EC2 instance
- Possible to get multiple object from Amazon S3 in single request?
- Poor performance with Spark streaming, Kafka and multiple topics
- Process parquet file row-wise

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.