## Workloads & Scheduling
Kubernetes Pods are the smallest deployable units, encapsulating one or more containers, storage resources, a unique network IP, and options that govern how the containers run. Multi-container Pods often use patterns like sidecar containers for logging or monitoring, and init containers for setup tasks that must complete before the main application containers start.
Deployments are the primary way to manage stateless applications. They define the desired state for a set of Pods and their underlying ReplicaSets. Deployments handle rolling updates and rollbacks, allowing zero-downtime updates and easy reversion to previous versions. ReplicaSets ensure a specified number of identical Pods are running at all times. DaemonSets ensure that all (or some) nodes run a copy of a specific Pod, useful for cluster-level services like logging agents or monitoring daemons.
For tasks that run to completion, Kubernetes provides Jobs. A Job creates one or more Pods and ensures that a specified number of them successfully terminate. CronJobs automate Jobs on a recurring schedule, similar to cron in Linux, enabling scheduled tasks like backups or report generation.
Kubernetes' scheduler places Pods on nodes based on various constraints. Resource Requests define the minimum CPU and memory a Pod needs, ensuring it gets scheduled on a node with sufficient capacity. Resource Limits define the maximum CPU and memory a Pod can consume, preventing resource exhaustion on a node.
Advanced scheduling includes Node Selectors for simple node assignment based on labels. Node Affinity provides more flexible rules (e.g., "prefer this node," "must run on this node"). Taints on nodes repel Pods unless those Pods have a matching Toleration. This is crucial for dedicating nodes or handling special hardware. Pod Disruption Budgets (PDBs) ensure that a minimum number of Pods for a given application remain running during voluntary disruptions (e.g., node maintenance), enhancing application availability. Liveness Probes detect if a container is running correctly and restart it if it fails. Readiness Probes determine if a container is ready to serve traffic, removing it from service endpoints if not. Startup Probes delay liveness and readiness checks until the application has started, preventing premature restarts for slow-starting apps.