CKA Workloads and Scheduling 1 — Questions and Answers
Question 1: Which Kubernetes object is used to ensure that a specific number of replicas of a Pod are running at any time?
- Deployment
- StatefulSet
- ReplicaSet (Correct answer)
- DaemonSet
Correct answer: ReplicaSet
A ReplicaSet's primary purpose is to maintain a stable set of replica Pods running at any given time. It ensures that a specified number of identical Pods are always available and automatically replaces any Pods that fail or are terminated. While Deployments use ReplicaSets under the hood to manage Pods, the ReplicaSet itself is the object directly responsible for maintaining the desired replica count.
Question 2: How do you prevent a Pod from being scheduled on specific nodes?
- By using node selectors in the Pod specification.
- By tainting the nodes and adding tolerations to the Pod. (Correct answer)
- By defining affinity rules in the Pod specification.
- By scaling down the node pool.
Correct answer: By tainting the nodes and adding tolerations to the Pod.
Taints are applied to nodes to mark them as undesirable for certain Pods, preventing Pods from being scheduled on them unless they explicitly "tolerate" that taint. By tainting a node, you effectively repel Pods without the corresponding toleration. This mechanism is crucial for dedicating nodes to specific workloads or isolating problematic nodes.
Question 3: What happens when you scale a Deployment to zero replicas?
- The Pods remain running but are not restarted if they fail.
- All Pods managed by the Deployment are terminated. (Correct answer)
- The Deployment is deleted.
- The ReplicaSet is deleted.
Correct answer: All Pods managed by the Deployment are terminated.
When a Deployment's replica count is scaled to zero, it instructs the underlying ReplicaSet to terminate all Pods it manages. This action effectively stops the application or service associated with that Deployment from running within the cluster. The Deployment object itself remains, allowing for easy scaling back up later.
Question 4: Which type of workload should you use for a Pod that must run on every node in a Kubernetes cluster?
- Deployment
- StatefulSet
- ReplicaSet
- DaemonSet (Correct answer)
Correct answer: DaemonSet
A DaemonSet ensures that all (or some) nodes in a cluster run a copy of a specific Pod. This is ideal for cluster-level services like logging agents, monitoring agents, or CNI plugins that need to be present on every node. Unlike Deployments, DaemonSets automatically add Pods to new nodes as they join the cluster and remove them when nodes are removed.
Question 5: How can you ensure that a Pod is scheduled on a node with specific hardware requirements (e.g., GPUs)?
- Add a node selector to the Pod specification. (Correct answer)
- Use a ConfigMap to define node hardware.
- Use a toleration and taint.
- Add resource limits to the Pod specification.
Correct answer: Add a node selector to the Pod specification.
Node selectors are a simple way to constrain Pods to nodes with specific labels. By labeling nodes with their hardware capabilities (e.g., `gpu=true`) and then adding a `nodeSelector` to the Pod's specification matching that label, you can ensure the Pod is only scheduled on nodes possessing those required resources. This provides a direct and explicit method for node selection based on attributes.
Which Kubernetes object is used to ensure that a specific number of replicas of a Pod are running at any time?