KCNA · Domain 1: Kubernetes Fundamentals · 44% of the exam
Task 1.4: Containerization
Containers versus virtual machines, images, layers, tags and digests, OCI images and runtimes, the Container Runtime Interface and the runtimes behind it, image pull policies and private registries, and multi-container Pod patterns.
Try each one before opening the answer. Every option is explained, with the CNCF documentation page that proves it.
Question 1 · choose 1
A team compares running its service in virtual machines with running it in containers. Why can one host usually run many more containers than virtual machines of the same service?
AContainer images are compiled to machine code and need no libraries
BContainers run without isolation from one another, which saves the memory a VM would use
CContainers share the host kernel; each VM boots its own guest operating system
DThe hypervisor merges identical virtual machines into one at runtime
Show the answer and why
AContainer images are compiled to machine code and need no libraries
Incorrect
Images still package the libraries and files the application needs; they are not compiled binaries.
BContainers run without isolation from one another, which saves the memory a VM would use
Incorrect
Containers are isolated with kernel features; they just do not need a separate kernel for it.
CContainers share the host kernel; each VM boots its own guest operating system
Correct
A container is an isolated process with the files it needs; there is no guest kernel to boot or keep in memory.
DThe hypervisor merges identical virtual machines into one at runtime
Incorrect
Hypervisors do not merge guest systems; each VM keeps its own operating system.
The density difference comes from the kernel: every VM brings its own operating system, while containers are processes that share one kernel.
A team wants every node to run exactly the same image content for a release, even if someone later pushes a different image under the tag v2.1. How should the Pod spec refer to the image?
ABy the tag v2.1, with imagePullPolicy set to Always in the Pod spec
BBy the tag latest so the nodes agree on one name
CBy the tag v2.1 with imagePullPolicy set to Never
DBy its digest, such as registry.example.com/app@sha256:<hash>
Show the answer and why
ABy the tag v2.1, with imagePullPolicy set to Always in the Pod spec
Incorrect
Always pulls whatever v2.1 points to at start time, so a re-pushed tag would change the content.
BBy the tag latest so the nodes agree on one name
Incorrect
latest is just another movable tag and changes with every push.
CBy the tag v2.1 with imagePullPolicy set to Never
Incorrect
Never uses whatever copy each node already has, which can differ from node to node.
DBy its digest, such as registry.example.com/app@sha256:<hash>
Correct
A digest is a hash of the image content and is immutable, while a tag can be moved to another image.
Tags are names that can be re-pointed; digests identify content. Pin a digest when the bytes must not change.
Pods fail to start because their image is in a private registry that requires credentials. The credentials are already stored in a Secret of type kubernetes.io/dockerconfigjson. What should the Pod spec add?
AimagePullPolicy set to Always
BAn imagePullSecrets entry that names the Secret
CenvFrom referencing the Secret
DA ConfigMap volume that contains the registry address
Show the answer and why
AimagePullPolicy set to Always
Incorrect
The pull policy decides when to pull, not how to authenticate; the pull would still be refused.
BAn imagePullSecrets entry that names the Secret
Correct
The kubelet uses the Secrets listed in imagePullSecrets to authenticate to the registry when it pulls the image.
CenvFrom referencing the Secret
Incorrect
envFrom gives the values to the running container, but the image has to be pulled before any container runs.
DA ConfigMap volume that contains the registry address
Incorrect
The registry is already part of the image name, and a ConfigMap carries no credentials.
Registry credentials reach the kubelet through imagePullSecrets, which reference Secrets in the same namespace as the Pod.
An operations team plans to switch its nodes from one container runtime to another without rebuilding any Kubernetes component. Which interface makes this possible?
AThe Container Runtime Interface (CRI)
BThe Container Network Interface (CNI)
CThe Container Storage Interface (CSI)
DThe OCI Image Specification
Show the answer and why
AThe Container Runtime Interface (CRI)
Correct
CRI is the plugin interface, a gRPC protocol, through which the kubelet uses any compliant runtime without recompiling.
BThe Container Network Interface (CNI)
Incorrect
CNI is how network plugins give Pods their networking. It does not run containers.
CThe Container Storage Interface (CSI)
Incorrect
CSI connects storage drivers to the cluster for volumes, not runtimes.
DThe OCI Image Specification
Incorrect
The image specification defines the format of an image, such as its manifest and digest; it is not the channel between the kubelet and a runtime.
The kubelet talks to its container runtime over CRI, so any runtime that implements CRI can be plugged in.
A Node.js Dockerfile copies the whole source tree and then runs npm ci. Every small code change makes the build reinstall all dependencies, which takes minutes. What change fixes this?
ABuild with the --no-cache option so stale layers are not reused
BSwitch to a smaller base image so each rebuild has fewer layers to download
CAdd node_modules to .dockerignore so the build context stays small
DCopy only the package files, run npm ci, then copy the rest of the source
Show the answer and why
ABuild with the --no-cache option so stale layers are not reused
Incorrect
That disables the cache entirely, so every build reinstalls dependencies.
BSwitch to a smaller base image so each rebuild has fewer layers to download
Incorrect
A smaller base image saves size, but the install layer still follows the source copy and is rebuilt every time.
CAdd node_modules to .dockerignore so the build context stays small
Incorrect
Excluding node_modules keeps the build context small, but the install layer still comes after the source copy and is rebuilt on every change.
DCopy only the package files, run npm ci, then copy the rest of the source
Correct
When a layer's input changes, it and every later layer are rebuilt. Installing dependencies before the source copy keeps that layer cached until the lock file changes.
Docker reuses cached layers until an instruction's inputs change, then rebuilds from there. Order instructions from least to most frequently changing.
Which two Linux kernel features does a container runtime rely on to give a container its own isolated view of the system and to cap the resources it can use? (Choose TWO.)
ALinux namespaces
BHypervisor guest kernels
Ciptables port rules
DHost swap space
EControl groups (cgroups)
Show the answer and why
ALinux namespaces
Correct
Namespaces give a container its own view of processes, network, mounts and more, isolating it from the host and other containers.
BHypervisor guest kernels
Incorrect
That is how virtual machines isolate workloads; containers share the host kernel.
Ciptables port rules
Incorrect
iptables rules route traffic to containers, but they do not isolate processes or cap resources.
DHost swap space
Incorrect
Swap extends memory; it neither isolates nor limits a container.
EControl groups (cgroups)
Correct
cgroups account for and limit CPU, memory and other resources per container.
A container is an ordinary process placed in its own namespaces and constrained by cgroups. No guest kernel is involved.
A team containerizes a web app and its database. Both could go into one Pod or into separate Pods. Following the guidance on Pods with several containers, what should it do?
AOne Pod, because they talk to each other
BSeparate Pods, because Kubernetes runs one container per Pod
CSeparate Pods, because the two scale and fail independently
DOne Pod, with the database as an init container that starts first
Show the answer and why
AOne Pod, because they talk to each other
Incorrect
Communication alone does not require one Pod; Services connect separate Pods.
BSeparate Pods, because Kubernetes runs one container per Pod
Incorrect
A Pod can run several tightly coupled containers that share resources, so that is not the reason; the two tiers belong apart because they scale and fail independently.
CSeparate Pods, because the two scale and fail independently
Correct
Several containers belong in one Pod only when they are tightly coupled and must share resources; one container per Pod is the common case.
DOne Pod, with the database as an init container that starts first
Incorrect
Regular init containers run to completion before the app containers start, so a database that has to keep serving cannot be one, and the two tiers would still be scaled and replaced together.
Group containers in one Pod only when they form a single unit, such as an app and its helper. Independent tiers belong in their own Pods.
A developer runs a database with plain Docker. Each time the container is removed and recreated, the data is gone. What keeps the data across container replacements?
AA larger container writable layer
BA Docker volume mounted at the database's data directory
CThe --restart always option
DCommitting the container to a new image after each change
Show the answer and why
AA larger container writable layer
Incorrect
The writable layer belongs to one container and goes away with it.
BA Docker volume mounted at the database's data directory
Correct
Volumes persist data beyond the lifecycle of an individual container.
CThe --restart always option
Incorrect
A restart policy restarts containers; a removed container still loses its data.
DCommitting the container to a new image after each change
Incorrect
Images are for software, not live database files, and commits miss data written later.
Containers are ephemeral; volumes give data a lifecycle of its own.
In one Pod, an application container writes reports to a directory, and a helper container must read the same files. How do the two containers share them?
ACopy the files over localhost with an HTTP server
BWrite the files into a ConfigMap from the application
CUse the container image's file system, which is shared
DMount one shared volume, such as an emptyDir, in both
Show the answer and why
ACopy the files over localhost with an HTTP server
Incorrect
That is possible but needless; shared volumes are built for this.
BWrite the files into a ConfigMap from the application
Incorrect
ConfigMaps hold configuration through the API, not files produced at runtime.
CUse the container image's file system, which is shared
Incorrect
Each container has its own file system from its own image.
DMount one shared volume, such as an emptyDir, in both
Correct
Containers in a Pod can share volumes, so both see the same files.
Pods give their containers shared storage through volumes, alongside the shared network.