Stage 5, Part 4 of 9, Scheduling Deep Dive

Text

PART 4: CAPACITY PLANNING & COST MODELING

21. Bin-Packing vs Spreading

Spreading (Default)

The default scheduler spreads workloads (LeastAllocated).

ProsCons
Resilient to node failureLower utilization
Even distributionMore nodes needed
Simpler reasoningHigher 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
ProsCons
Higher utilizationLess resilient
Lower costRisk of cascading failure
Fewer nodesNoisy neighbors

When to Use Which

ScenarioStrategy
Production APIsSpreading
Batch jobsBin-packing
Cost-sensitiveBin-packing
Resilience-criticalSpreading
MixedDifferent 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:

Covered in depth in Stage 10 (Autoscaling).

Cost Visibility via Scheduling Metrics

MetricMeaning
kube_pod_container_resource_requestsPod requests
kube_node_status_allocatableNode capacity
kube_pod_status_phase{phase="Pending"}Pending Pods
scheduler_schedule_attempts_totalScheduling 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

TargetArchitecture
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.