Building a MapReduce job system on Kubernetes involves leveraging K8s primitives like Jobs, Pods, PersistentVolumes (PVs), StatefulSets, and custom Custom Resource Definitions (CRDs) with a controller (e.g., via Operator SDK or Kubebuilder). This provides scalability, fault tolerance, and orchestration for large-scale data processing.
The system typically consists of:
Driver Pod: Orchestrates the job, splits input, monitors progress.
Mapper Pods: Process input partitions in parallel (scale via HorizontalPodAutoscaler or Job replicas).
Reducer Pods: Aggregate shuffled mapper outputs.
Shared Storage: For input/output/checkpoints (e.g., PVCs backed by NFS, Ceph, or cloud storage like S3 via CSI drivers).
Focus on partitioning, checkpointing, and retries below. I'll assume a custom implementation using CRDs for flexibility (e.g., a MapReduceJob CR). Tools like Apache Spark on K8s or Argo Workflows handle much of this natively—consider them for production.
1. Partitioning
Partitioning splits input data into chunks for mappers, ensuring even load distribution and parallelism.
Strategy
Static Partitioning: Pre-split input (e.g., files into N chunks based on file size or line count).
Dynamic Partitioning: Driver samples input data and partitions based on runtime metrics (e.g., data skew).
Key-Based Partitioning: For reducers, hash mapper keys to reducer partitions (consistent hashing to minimize shuffle).
#!/bin/bash # Entry script
for attempt in {1..5}; do
if run_mapper; then
touch /shuffle/checkpoint-$PARTITION_ID.done
exit 0
fi
sleep $((2 ** $attempt))
done
exit 1
Full Architecture Diagram (Text)
code
Input (S3/PVC) --> Driver Pod (Partition & Orchestrate)
|
v
Mapper Jobs (100 pods) --> Shuffle PV (Checkpoints: /mapper-{id}/part-{r})
| |
v v (Poll .done files)
Reducer Jobs (20 pods) <-- Hash Partitioning
|
v
Output (S3/PVC)