PART 4: CAPACITY PLANNING & COST MODELING
21. Bin-Packing vs Spreading
Spreading (Default)
The default scheduler spreads workloads (LeastAllocated).
| Pros | Cons |
| Resilient to node failure | Lower utilization |
| Even distribution | More nodes needed |
| Simpler reasoning | Higher cost |
Bin-Packing
Bin-packing packs workloads (MostAllocated).
yaml
apiVersion: kubescheduler.config.k8s.io/v1
kind: KubeSchedulerConfiguration
profiles:
- schedulerName: default-scheduler
pluginConfig:
- name: NodeResourcesFit
args:
scoringStrategy:
type: MostAllocated
resources:
- name: cpu
weight: 1
- name: memory
weight: 1
| Pros | Cons |
| Higher utilization | Less resilient |
| Lower cost | Risk of cascading failure |
| Fewer nodes | Noisy neighbors |
When to Use Which
| Scenario | Strategy |
| Production APIs | Spreading |
| Batch jobs | Bin-packing |
| Cost-sensitive | Bin-packing |
| Resilience-critical | Spreading |
| Mixed | Different profiles |
The Cost Impact
text
Spreading: 100 nodes at 40% utilization
Bin-packing: 60 nodes at 70% utilization
Cost savings: 40% fewer nodes
Risk: One node failure affects 70% of workloads
22. Cost-Aware Scheduling
Spot Instance Scheduling
Use Spot instances for fault-tolerant workloads:
yaml
spec:
affinity:
nodeAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
preference:
matchExpressions:
- key: node.kubernetes.io/lifecycle
operator: In
values:
- spot
tolerations:
- key: "kubernetes.io/lifecycle"
operator: "Equal"
value: "spot"
effect: "NoSchedule"
Karpenter
Karpenter is AWS's modern node autoscaler that:
- Provisions nodes just-in-time
- Chooses instance types based on Pod requirements
- Uses Spot when possible
- Can bin-pack efficiently
Covered in depth in Stage 10 (Autoscaling).
Cost Visibility via Scheduling Metrics
| Metric | Meaning |
kube_pod_container_resource_requests | Pod requests |
kube_node_status_allocatable | Node capacity |
kube_pod_status_phase{phase="Pending"} | Pending Pods |
scheduler_schedule_attempts_total | Scheduling attempts |
23. SLA & Availability Design
Availability Math
text
99.9% = 8.76 hours downtime/year
99.99% = 52.56 minutes downtime/year
99.999% = 5.26 minutes downtime/year
Scheduling SLA Design
| Target | Architecture |
| 99.9% | Basic affinity, PDBs |
| 99.99% | Topology spread across 3 AZs, anti-affinity, PDBs |
| 99.999% | Multi-region, gang scheduling, chaos-tested |
1:1 copy of the class Google Doc, code in code blocks.