Kubernetes and Cloud Native Associate (KCNA) free question 4 / 10 · Domain 1: Kubernetes Fundamentals
A container has limits for both CPU and memory. What happens when its usage reaches the limits, according to the Kubernetes documentation?
- The container is terminated as soon as it reaches either limit
- CPU use is throttled, and memory use can get the container killed by the kernel when it goes over
- CPU use is terminated at the limit, and memory is throttled so that the container stays under the limit
- The limits are guidelines, and the scheduler may move the Pod to another node when they are exceeded
Show the answer and explanation
Answer: B
Why this is correct
The page on managing resources for containers says that both cpu and memory limits are applied by the kubelet and the container runtime, and are ultimately enforced by the kernel, using cgroups on Linux nodes. Their behavior differs slightly. CPU limits are enforced by CPU throttling: when a container approaches its limit, the kernel restricts its access to the CPU, so a CPU limit is a hard limit and the container cannot use more. Memory limits are enforced with out of memory kills: when a container uses more than its memory limit, the kernel may terminate it. This only happens when the kernel detects memory pressure, so memory limits are enforced reactively, and a container that over-allocates may not be killed immediately.
Why the other options are wrong
"The container is terminated as soon as it reaches either limit" … The limits do not work in the same way for both resources. A CPU limit is enforced by throttling, so a container that reaches it keeps running, only slower.
"CPU use is terminated at the limit, and memory is throttled so that the container stays under the limit" … The two are swapped. The CPU limit is enforced by throttling, and the memory limit is enforced reactively with out of memory kills, so a container is not held to a memory ceiling by throttling.
"The limits are guidelines, and the scheduler may move the Pod to another node when they are exceeded" … The kubelet and the container runtime apply the limits, and the kernel enforces them. The scheduler uses requests to choose a node and does not move running Pods when limits are exceeded.
CPU is throttled, memory is killed
Going over a CPU limit slows the container. Going over a memory limit can get it OOM-killed.