Kubernetes Container Orchestration Pod Management 4 — Questions and Answers
Question 1: What is the difference between `kubectl delete pod <name>` and `kubectl delete pod <name> --force --grace-period=0`?
- There is no difference; both remove the Pod immediately
- The second command bypasses the graceful termination period and forcefully removes the Pod (Correct answer)
- The second command only removes the Pod from etcd but leaves the container running
- The first command removes only the Pod spec; the second removes all associated resources
Correct answer: The second command bypasses the graceful termination period and forcefully removes the Pod
--force --grace-period=0 skips the SIGTERM grace period and immediately removes the Pod from the API server, useful for stuck Terminating Pods.
Question 2: Which field in a Pod spec allows you to share the host network namespace with the Pod's containers?
- spec.networkPolicy: host
- spec.hostNetwork: true (Correct answer)
- spec.shareNetwork: true
- spec.networkMode: host
Correct answer: spec.hostNetwork: true
Setting spec.hostNetwork: true makes the Pod use the node's network namespace, giving containers direct access to the host network interfaces.
Question 3: What is a Pod Disruption Budget (PDB) used for?
- Limiting the CPU cost of running Pods
- Ensuring a minimum number of Pods remain available during voluntary disruptions (Correct answer)
- Controlling how many Pods can be scheduled per node
- Setting maximum retry counts during Pod failures
Correct answer: Ensuring a minimum number of Pods remain available during voluntary disruptions
A PDB specifies minAvailable or maxUnavailable to protect application availability during planned disruptions like node drains or cluster upgrades.
Question 4: Which probe type checks if a container is ready to accept traffic?
- Liveness probe
- Readiness probe (Correct answer)
- Startup probe
- Health probe
Correct answer: Readiness probe
The readiness probe determines if a container is ready to receive traffic; a failing readiness probe removes the Pod from Service endpoints without restarting it.
Question 5: A Pod has `restartPolicy: OnFailure`. Under which condition will Kubernetes NOT restart a container?
- When the container exits with a non-zero exit code
- When the container exits with exit code 0 (success) (Correct answer)
- When the node runs out of memory
- When the liveness probe fails
Correct answer: When the container exits with exit code 0 (success)
OnFailure only restarts containers that exit with a non-zero exit code; a successful exit (code 0) is treated as completion and not restarted.
Question 6: What is the purpose of `spec.activeDeadlineSeconds` in a Pod?
- Sets the maximum time a Pod can wait in Pending state
- Sets the total duration after which a running Pod is killed, useful for Jobs (Correct answer)
- Defines the liveness probe timeout
- Controls how long a Pod waits for its init containers
Correct answer: Sets the total duration after which a running Pod is killed, useful for Jobs
activeDeadlineSeconds sets an absolute deadline for a Pod's execution; once exceeded, the Pod is terminated, commonly used with Jobs to prevent infinite loops.
Question 7: How can you inject environment variables from a ConfigMap into a Pod?
- Using spec.volumes referencing the ConfigMap
- Using spec.containers[].envFrom with a configMapRef (Correct answer)
- Using spec.configMap.inject: true
- Using spec.containers[].command referencing $CONFIG_MAP
Correct answer: Using spec.containers[].envFrom with a configMapRef
envFrom with configMapRef imports all key-value pairs from a ConfigMap as environment variables into the container.
What is the difference between `kubectl delete pod ` and `kubectl delete pod --force --grace-period=0`?