Learn Workloads & Scheduling (CKA) with Interactive Flashcards

Master key concepts in Workloads & Scheduling through our interactive flashcard system. Click on each card to reveal detailed explanations and enhance your understanding.

Understand application deployments and how to perform rolling update and rollbacks

In the context of the CKA exam, a Deployment is the standard resource for managing stateless applications. It acts as a wrapper around ReplicaSets, ensuring the desired number of Pods are running and managing their lifecycle. The two critical lifecycle operations are Rolling Updates and Rollbacks.

**Rolling Updates** are the default deployment strategy. When you update the Pod template (for example, changing the container image from v1 to v2), Kubernetes does not terminate all existing Pods simultaneously. Instead, it spins up a new ReplicaSet and incrementally scales it up while scaling down the old ReplicaSet. This ensures zero downtime. The speed and safety of this transition are controlled by the `maxSurge` (how many extra pods can exist) and `maxUnavailable` (how many pods can be down) parameters in the YAML manifest.

To perform a rolling update imperatively, execute:
`kubectl set image deployment/myapp container-name=image:v2`
Monitor the progress with:
`kubectl rollout status deployment/myapp`

**Rollbacks** allow you to revert changes if an update fails or introduces bugs. Kubernetes maintains a history of Deployment revisions.
To view the revision history:
`kubectl rollout history deployment/myapp`
To undo the deployment and revert to the previous revision:
`kubectl rollout undo deployment/myapp`
To revert to a specific revision number:
`kubectl rollout undo deployment/myapp --to-revision=2`

For the exam, you must be proficient with the `kubectl rollout` command suite, including how to pause and resume rollouts (`kubectl rollout pause/resume`) to stack multiple changes before triggering the update.

Use ConfigMaps and Secrets to configure applications

In the context of the CKA exam and Workloads & Scheduling, decoupling configuration from container images is a core best practice. ConfigMaps and Secrets are the Kubernetes primitives used to inject this configuration data into Pods, allowing the same container image to be portable across different environments (Dev, QA, Prod).

ConfigMaps are designed for non-sensitive data, such as config files (e.g., nginx.conf), command-line arguments, or standard environment variables. You can inject ConfigMap data into containers in three primary ways: as individual environment variables using `valueFrom`, as a set of environment variables using `envFrom`, or as files mounted to a specific path via a Volume. This flexibility allows applications to read configuration at startup or watch for file changes.

Secrets handle sensitive data like passwords, OAuth tokens, and SSH keys. While usage syntax mimics ConfigMaps, Secrets are base64-encoded and can be encrypted at rest within etcd. Like ConfigMaps, they can be exposed via environment variables or volumes. Security best practices suggest using Volume mounts for Secrets, as this stores data in an in-memory tmpfs rather than writing to disk, minimizing leakage risks.

For the CKA, you must master the imperative creation of these objects (e.g., `kubectl create configmap --from-literal`) and their integration into Pod manifests. A crucial distinction for scheduling is the update behavior: updates to ConfigMaps/Secrets mounted as Volumes are reflected automatically in the Pod (eventually), whereas Environment Variables are injected only at startup, requiring a Pod restart to apply changes.

Configure workload autoscaling

In the context of the Certified Kubernetes Administrator (CKA) exam, configuring workload autoscaling primarily revolves on the Horizontal Pod Autoscaler (HPA). The HPA automatically scales the number of Pods in a Deployment, ReplicaSet, or StatefulSet based on observed CPU utilization or memory usage.

For autoscaling to function, the **Metrics Server** must be installed in the cluster. This component aggregates resource usage data; without it, the HPA cannot retrieve current metrics and will display targets as `<unknown>`.

Configuring HPA involves three essential requirements:

1. **Pod Specifications:** Containers within your Pods must have resource **requests** and **limits** defined. The HPA uses the request value to calculate utilization percentages.
2. **HPA Resource:** You must create an HPA object that targets a specific workload. This defines the minimum and maximum number of replicas and the target metric (e.g., maintain 50% CPU utilization).
3. **Control Loop:** The HPA controller periodically queries the Metrics Server. It calculates the desired replica count using the ratio of current usage to the target usage. If the load exceeds the target, it scales out (adds pods); if the load drops, it scales in (removes pods).

You can configure this imperatively using: `kubectl autoscale deployment <name> --cpu-percent=50 --min=1 --max=10`. Alternatively, using a YAML manifest (typically `apiVersion: autoscaling/v2`) allows for granular control, such as defining stabilization windows to prevent 'thrashing' (rapid fluctuation of replica counts). Mastery of HPA troubleshooting—specifically ensuring metrics are available and resource requests are set—is critical for the CKA.

Understand the primitives used to create robust, self-healing, application deployments

In Kubernetes, achieving robust, self-healing applications relies on higher-level abstractions that manage the lifecycle of Pods. Since individual Pods are ephemeral and do not self-recover after failure, Kubernetes uses Controllers to maintain the desired system state.

The foundational primitive is the **ReplicaSet**, which guarantees that a specific number of identical Pod replicas are running at any given time. If a Pod crashes or a Node fails, the ReplicaSet detects the discrepancy and spins up new Pods to match the defined replica count.

For most stateless applications, you will use **Deployments**. A Deployment is a wrapper around ReplicaSets that provides declarative updates. It facilitates **Rolling Updates** (gradually replacing old Pods with new ones to ensure zero downtime) and **Rollbacks** (reverting to a previous version if an update fails). This abstraction makes application lifecycle management seamless.

For specialized workloads, Kubernetes offers **StatefulSets** (providing stable network IDs and persistent storage for databases) and **DaemonSets** (ensuring a Pod runs on every Node for logging or monitoring agents).

True self-healing is further enhanced by **Probes** configured within the Pod spec:
1. **Liveness Probes**: Restart containers that are running but in a broken state (e.g., deadlocks).
2. **Readiness Probes**: Ensure traffic is only sent to Pods that are fully ready to process requests, removing unready Pods from Service load balancers.
3. **Startup Probes**: Allow slow-starting applications time to initialize before Liveness checks begin.

For the CKA, understanding how Deployments orchestrate ReplicaSets and how Probes dictate container health is essential for designing architectures that survive infrastructure failures.

Configure Pod admission and scheduling (limits, node affinity, etc.)

In the context of the CKA exam, configuring pod admission and scheduling is essential for ensuring application stability and efficient cluster resource utilization.

First, **Resource Requests and Limits** manage compute allocation. A 'Request' is the minimum amount of CPU and Memory guaranteed to a container, used by the scheduler to filter suitable nodes. A 'Limit' is the hard ceiling; exceeding memory limits results in OOMKills, while CPU overage leads to throttling. Failing to set these can lead to 'Noisy Neighbor' issues.

For controlling placement, **Node Affinity** allows you to constrain pods to nodes with specific labels. It supports flexible operators (In, NotIn, Exists) and two modes: 'hard' (`requiredDuringScheduling...`), which mandates conditions, and 'soft' (`preferred...`), which prioritizes nodes but allows scheduling elsewhere if conditions aren't met.

**Taints and Tolerations** work inversely. Taints are applied to nodes to repel pods, while Tolerations are applied to pods to allow them onto tainted nodes. This pattern is critical for dedicating nodes to specific workloads (e.g., GPU instances) or preventing scheduling during maintenance.

**Pod Affinity/Anti-Affinity** rules schedule pods based on the labels of *other pods* running on the node. Use affinity to co-locate chatty services for performance, and anti-affinity to spread replicas across different nodes or zones for high availability.

Finally, **LimitRanges** and **ResourceQuotas** are admission controls applied at the namespace level. LimitRanges define default request/limit values for pods that don't specify them, while ResourceQuotas cap the total aggregate resource consumption of a namespace, preventing tenant resource exhaustion.

DaemonSets and StatefulSets

In the context of the Certified Kubernetes Administrator (CKA) exam, DaemonSets and StatefulSets are specialized controllers used for specific workload requirements that standard Deployments cannot handle efficiently.

DaemonSets ensure that a copy of a Pod runs on all (or a selected subset of) nodes in the cluster. Unlike Deployments, which manage a specific count of replicas, DaemonSets focus on node coverage. They are primarily used for system daemons and background processes, such as log collectors (e.g., Fluentd), monitoring agents (e.g., Prometheus Node Exporter), or network proxies (e.g., kube-proxy). When a new node is added to the cluster, the DaemonSet controller automatically schedules a Pod onto it. In the exam, you may need to configure these using `nodeSelector` or Node Affinity to restrict them to specific hardware types.

StatefulSets are designed for stateful applications requiring unique, persistent identities and stable storage. While Deployments treat Pods as interchangeable (stateless), StatefulSets assign a sticky identity to each Pod with a deterministic name (e.g., `web-0`, `web-1`) and ordered deployment. They use `volumeClaimTemplates` to dynamically provision PersistentVolumeClaims (PVCs) for each replica, ensuring that if a Pod is rescheduled, it reattaches to its specific storage volume. This is critical for databases (like PostgreSQL or Cassandra) and distributed systems (like Zookeeper) where data consistency and network identity are paramount. A key CKA detail is that deleting a StatefulSet does not automatically delete the associated PVCs, protecting data from accidental loss.

Jobs and CronJobs

In the context of the Certified Kubernetes Administrator (CKA) exam regarding Workloads & Scheduling, Jobs and CronJobs are controllers designed for finite tasks that run to completion, distinguishing them from long-running processes managed by Deployments or DaemonSets.

A **Job** creates one or more Pods and ensures a specified number of them successfully terminate. Once the process exits with a success code, the task is considered complete. If a Pod fails or is evicted, the Job controller creates a new one to replace it until the completion target is met. Key specifications to master include `.spec.completions` (total successes required), `.spec.parallelism` (how many Pods run simultaneously), and `.spec.backoffLimit` (number of retries before marking the Job as failed). You must strictly configure the Pod's `restartPolicy` to `OnFailure` or `Never`, as the default `Always` is invalid for finite workloads.

A **CronJob** builds upon the Job object by scheduling execution at specific times, acting as the Kubernetes equivalent of the Linux crontab. A CronJob does not run Pods directly; it creates a Job object based on a schedule defined in standard cron syntax (e.g., `*/1 * * * *`). Critical configuration options include `.spec.jobTemplate` (the blueprint for the resulting Job) and the `concurrencyPolicy`. The latter controls behavior if a previous run is still active when the next schedule triggers: `Allow` (concurrent runs), `Forbid` (skip the new run), or `Replace` (cancel the old run to start the new one). You should also be familiar with `successfulJobsHistoryLimit` and `failedJobsHistoryLimit` to manage the cleanup of completed Job objects.

Resource requests and limits

In the context of the CKA exam and Kubernetes Workloads, managing compute resources (CPU and Memory) is vital for efficient scheduling and cluster stability. These controls are defined within the container spec of a Pod manifest under the `resources` field.

**Resource Requests** specify the guaranteed minimum resources a container requires to start. The kube-scheduler uses this value purely for scheduling decisions; it filters out Nodes that do not have enough unallocated capacity to meet the request. If a container requests `500m` CPU and `256Mi` Memory, the scheduler ensures the chosen Node has that specific capacity available. If no Node meets the requirement, the Pod remains in a `Pending` state.

**Resource Limits** specify the hard maximum a container is allowed to consume. This setting prevents a single misbehaving Pod from monopolizing Node resources and starving other processes. The behavior when exceeding limits depends on the resource type:
1. **CPU:** Considered a compressible resource. If a container tries to exceed its CPU limit, the runtime throttles the CPU cycles, resulting in degraded performance, but the container remains running.
2. **Memory:** Considered incompressible. If a container tries to consume more RAM than its limit, the kernel invokes the OOM (Out Of Memory) Killer, terminating the container with an `OOMKilled` error.

Additionally, these settings determine the **Quality of Service (QoS)** class assigned to the Pod (Guaranteed, Burstable, or BestEffort), which dictates the order in which Pods are evicted when a Node is under resource pressure.

Taints and tolerations

In the context of Certified Kubernetes Administrator (CKA) Workloads & Scheduling, Taints and Tolerations function as a filtering mechanism to restrict which pods can be scheduled on specific nodes. Unlike Node Affinity, which attracts pods to nodes, Taints allow a node to repel pods.

A **Taint** is applied to a Node using a key, value, and an effect (e.g., `key=value:NoSchedule`). This marks the node as dedicated or restricted. By default, the Kubernetes scheduler will not place any pod on a tainted node.

A **Toleration** is applied to a Pod's specification. If a pod contains a toleration that matches a node's taint (matching key, value, and effect), the scheduler allows the pod to be placed on that node. It essentially serves as an 'immunity' card against the node's 'repellent'.

There are three taint effects you must know for the CKA:
1. **NoSchedule**: Strict. New pods will not be scheduled on the node unless they tolerate the taint. Existing pods remain running.
2. **PreferNoSchedule**: Soft. The system tries to avoid placing non-tolerant pods on the node, but will do so if no other resources are available.
3. **NoExecute**: Aggressive. New pods are blocked, and any existing pods on the node without the toleration are immediately evicted.

Common use cases include dedicating nodes for specific hardware (like GPUs) to ensure standard workloads do not waste resources, or isolating Control Plane nodes to prevent application interference with critical cluster components.

Node selectors and affinity rules

In the context of the CKA exam and Kubernetes Workloads & Scheduling, controlling Pod placement is achieved primarily through nodeSelector and Affinity rules.

nodeSelector is the simplest constraint mechanism. It relies on strict equality matching of key-value labels attached to nodes. To use it, you apply labels to nodes (e.g., 'disktype=ssd') and define a matching 'nodeSelector' map in the Pod specification. If the labels match, the Pod can be scheduled; otherwise, it remains pending.

Node Affinity provides a much more expressive language for constraints. Unlike the exact matching of nodeSelector, Affinity supports operators such as In, NotIn, Exists, DoesNotExist, Gt, and Lt. Node affinity comes in two flavors:
1. Hard rules ('requiredDuringSchedulingIgnoredDuringExecution'): These act like a filter; the Pod will not be scheduled unless the rule is met.
2. Soft rules ('preferredDuringSchedulingIgnoredDuringExecution'): These act like a weighting system; the scheduler attempts to find a matching node but will fallback to any available node if the preference cannot be satisfied.

Pod Affinity and Anti-Affinity extend this logic by allowing you to constrain a Pod's schedule based on the labels of *other Pods* already running on the node, rather than the node's labels. This is crucial for high availability (spreading Pods across zones using Anti-Affinity) or performance (co-locating chatty microservices using Affinity).

For the exam, remember that 'IgnoredDuringExecution' means changes to labels after a Pod is scheduled do not trigger eviction. You should be comfortable writing the nested YAML syntax under 'spec.affinity' and using 'kubectl label nodes' to set up the environment.

Pod priority and preemption

In the context of the CKA exam and Workloads & Scheduling, Pod Priority and Preemption are mechanisms used to ensure that critical workloads run even when the cluster is under resource pressure.

**Pod Priority** indicates the importance of a Pod relative to others. It is implemented using a non-namespaced API object called `PriorityClass`, which maps a specific name to an integer value. A higher integer represents a higher priority. When a user creates a Pod, they specify the `priorityClassName` in the Pod spec. The Kubernetes scheduler uses this value to order Pods in the scheduling queue; higher-priority Pods are processed before lower-priority ones.

**Preemption** occurs when a high-priority Pod is pending but cannot be scheduled because no node has sufficient available resources. In this scenario, the scheduler attempts to free up space by 'preempting' (evicting) lower-priority Pods running on a suitable node. The lower-priority Pods receive a graceful termination signal, and once they are removed and resources are released, the high-priority Pod is scheduled on that node.

For CKA administrators, it is important to understand that there are system-reserved priority classes (`system-node-critical` and `system-cluster-critical`) which ensure core components (like CoreDNS) are not evicted by user workloads. When configuring your own `PriorityClass`, you can also set a `globalDefault` to false or true to control default behavior for Pods without a specified class. Correctly utilizing these features guarantees that mission-critical applications (e.g., payment processing) take precedence over less critical tasks (e.g., batch reporting) during resource contention.

Horizontal Pod Autoscaler (HPA)

In the context of the CKA exam and Workloads & Scheduling, the Horizontal Pod Autoscaler (HPA) is a control loop that automatically scales the number of Pod replicas in a Deployment, ReplicaSet, or StatefulSet based on observed metric utilization. Its primary purpose is to ensure applications have sufficient resources during peak traffic while reducing waste during low usage.

HPA relies heavily on the **Metrics Server** to aggregate resource data (like CPU and Memory) from the Kubelets. If the Metrics Server is not deployed, the HPA will fail to retrieve data, often displaying `<unknown>` under the targets column.

The scaling logic follows a ratio formula: `desiredReplicas = ceil[currentReplicas * ( currentMetricValue / desiredMetricValue )]`. For example, if the target CPU utilization is set to 50% and the current utilization is 100%, the HPA will attempt to double the number of replicas.

Key takeaways for the CKA exam include:
1. **Prerequisites:** You must have the Metrics Server installed, and your Pod containers **must have resource requests defined** (e.g., `requests: cpu: 100m`). Without requests, HPA cannot calculate percentage-based utilization.
2. **Configuration:** HPAs define `minReplicas` and `maxReplicas` to constrain scaling limits. They also include stabilization windows to prevent 'thrashing' (rapidly scaling up and down due to metric noise).
3. **Commands:** You should know how to create an HPA imperatively using `kubectl autoscale deployment <name> --cpu-percent=50 --min=1 --max=10` and how to inspect its status using `kubectl get hpa` and `kubectl describe hpa`.

Init containers and sidecar patterns

In the context of the Certified Kubernetes Administrator (CKA) exam and Workloads & Scheduling, understanding multi-container Pod capabilities is essential. While a Pod represents a single deployable unit, it often requires helper processes to function correctly. This is achieved through Init Containers and the Sidecar pattern.

**Init Containers**
Defined in the `spec.initContainers` field, these specialized containers run to completion *before* the main application containers start. They execute sequentially; each must succeed before the next begins. If an Init Container fails, the Pod restarts (subject to `restartPolicy`). This pattern is critical for separating setup logic from the main application. Common use cases include waiting for a dependency (like a database) to become available, running migration scripts, or populating a shared volume with configuration data. This allows the main application image to remain lightweight and secure, devoid of unnecessary debugging tools like `curl` or `nc`.

**Sidecar Pattern**
A Sidecar is a secondary container running *alongside* the main application container within the `spec.containers` array. They share the same lifecycle, network namespace (IP address), and storage volumes. The Sidecar extends the functionality of the primary app without altering its code. Classic examples include a logging agent that tails logs from a shared volume and forwards them to a central server, or a proxy (like Envoy in a Service Mesh) that handles network traffic. For the CKA, you must know how to configure these multi-container Pods to ensure they can communicate over `localhost` or read/write to common `emptyDir` volumes.

More Workloads & Scheduling questions
400 questions (total)