Kubernetes interview questions
Most Kubernetes questions come back to a handful of objects and how they find each other: Pods, Deployments, Services and the labels that connect them. Knowing why a deleted Pod reappears, or why a Service answers every request with connection refused, matters more than knowing every field.
Here are those objects, the difference between kubectl apply and create, ConfigMaps against Secrets, two manifests with a line missing, and what happens, in order, after you apply a Deployment.
All 15 are the free Foundation level of the Kubernetes topic in GapfyreSWE. Try each one before you open its answer.
-
What is a Pod in Kubernetes?
- A virtual machine managed by the Kubernetes control plane
- A group of nodes that run the same workload
- A Kubernetes configuration file written in YAML
- The smallest deployable unit — containers sharing a network
Show the answer
D. The smallest deployable unit — containers sharing a network
A Pod is the smallest deployable unit in Kubernetes. It wraps one or more containers that share the same network namespace (IP address and ports) and storage volumes. Containers in a Pod are co-located and co-scheduled on the same node.
-
What does a Kubernetes Service do?
- It provides a stable network endpoint and load balances traffic to matching Pods
- It stores configuration values that Pods can read as environment variables
- It defines the desired number of Pod replicas to maintain
- It pulls container images from a registry and caches them on each node
Show the answer
A. It provides a stable network endpoint and load balances traffic to matching Pods
A Service provides a stable network endpoint (IP and DNS name) to access a set of Pods. Because Pod IPs change as Pods are created and destroyed, a Service uses label selectors to route traffic to healthy Pods, acting as a load balancer within the cluster.
-
What is the difference between a ConfigMap and a Secret in Kubernetes?
- ConfigMaps store non-sensitive configuration; Secrets store sensitive data
- Secrets are automatically rotated by Kubernetes; ConfigMaps are not
- ConfigMaps are for environment variables only; Secrets are for files only
- They are identical — Secret is just a ConfigMap with a different name
Show the answer
A. ConfigMaps store non-sensitive configuration; Secrets store sensitive data
Both decouple configuration from container images. ConfigMaps store non-sensitive key-value data (e.g. feature flags, config files). Secrets store sensitive data (passwords, tokens, keys) and are base64-encoded at rest and can be encrypted. Both can be mounted as volumes or injected as environment variables.
-
What is a Kubernetes Namespace used for?
- It sets the container registry URL used when pulling images
- It partitions cluster resources into isolated environments
- A namespace defines the DNS domain for all Services in the cluster
- It groups nodes into pools with different hardware profiles
Show the answer
B. It partitions cluster resources into isolated environments
Namespaces provide a mechanism to divide a single cluster into multiple virtual clusters. They scope resource names (so two teams can have a Service called "api"), allow resource quotas per team or environment, and enable RBAC policies to be applied at the namespace level.
-
What does
kubectl apply -f deployment.yamldo thatkubectl create -f deployment.yamldoes not?- apply works only on Deployments and create works on any resource kind in the cluster
- apply schedules the change for the next maintenance window, where create takes effect at once
- apply validates the file without changing the cluster, where create actually submits it
- apply reconciles the resource towards the file, creating or updating it; create fails if it exists
Show the answer
D. apply reconciles the resource towards the file, creating or updating it; create fails if it exists
apply is declarative: the file states the desired end state, and Kubernetes works out the difference against what is running and reconciles towards it — so running the same apply against an existing resource updates it in place, and running it twice changes nothing the second time. create is imperative: it asks for the resource to be made, and fails if one of that name already exists. That difference is why apply is what belongs in a pipeline; it is the same command whether the resource exists yet or not.
-
A Pod is deleted by hand and reappears moments later. What has happened?
- The node cached the Pod definition and restarted it when the process exited
- The deletion was rejected because Pods can only be removed by scaling to zero
- The scheduler replayed the original creation event, which is retained for rollback
- A controller saw fewer Pods than the desired count and created a replacement
Show the answer
D. A controller saw fewer Pods than the desired count and created a replacement
A controller reconciled it. Kubernetes works on desired state: the Deployment says how many replicas should exist, and its ReplicaSet controller compares that against what is actually running, in a loop, and acts on the difference. Deleting a Pod it owns makes the counts disagree, so it creates a replacement. That is why deleting a managed Pod is a way to restart it rather than to remove it — removing it means changing the desired state, by scaling or deleting the Deployment.
-
A Pod is stuck and not serving traffic. What do
kubectl describe podandkubectl logseach tell you?- describe gives resource usage over time; logs gives the current values of the readiness probes
- describe gives the YAML as applied; logs gives the audit trail of who changed the resource
- describe gives Kubernetes’ view and its events; logs gives the container’s own stdout and stderr
- describe gives the container’s output; logs gives the control plane’s scheduling decisions
Show the answer
C. describe gives Kubernetes’ view and its events; logs gives the container’s own stdout and stderr
describe shows Kubernetes’ view of the Pod — its state, its containers, its restart count, and the recent events attached to it, which is where scheduling failures, image pull errors and failed probes appear. logs shows the application’s own stdout and stderr from inside a container, which is where a crash or a stack trace appears. They answer different questions: describe says whether Kubernetes managed to run the thing, logs says what the thing did once it ran, and
logs --previousreaches the container that already died. -
How do a node, a Pod and a container relate to each other?
- A Pod runs on several nodes at once for redundancy, with one container placed on each
- A container holds Pods, which are the isolated processes a single image can start
- A node runs containers, and a Pod is a label grouping containers across several nodes
- A node runs Pods, and a Pod holds one or more containers that share a network namespace
Show the answer
D. A node runs Pods, and a Pod holds one or more containers that share a network namespace
A node is a machine in the cluster, virtual or physical. A Pod is the smallest thing Kubernetes schedules onto a node, and it holds one or more containers that share a network namespace and can share volumes. A container is the running image inside it. So containers in one Pod are always on the same node and reach each other on localhost, while separate Pods may land anywhere and reach each other through Services. Most Pods hold exactly one container; the rest usually add a sidecar container.
-
What does a Deployment give you that creating Pods directly does not?
- A stable network identity per Pod, which is what lets other services address them individually
- Persistent storage that survives a Pod being rescheduled onto a different node
- Scheduling priority, so its Pods are placed before any Pod created directly
- A maintained replica count, automatic replacement, and rolling updates with rollback
Show the answer
D. A maintained replica count, automatic replacement, and rolling updates with rollback
Everything that keeps them running and lets them change: it maintains a replica count, replaces Pods that die or whose node goes away, and rolls out a new version incrementally with the ability to pause or roll back. A bare Pod is a single scheduled thing — when it dies, nothing brings it back, and changing its image means deleting and recreating it by hand. That is why almost nothing in production is a bare Pod: the Deployment is the object you actually manage.
-
Every Kubernetes manifest has
apiVersion,kind,metadataandspec. What is each for?- The API type, the scheduling constraints, the observed state, and the rollout history
- The schema URL, the controller name, the owner reference, and the container definition
- The cluster version, the resource category, the audit trail, and the runtime configuration
- The API type, the object’s identity and labels, and the desired state you are asking for
Show the answer
D. The API type, the object’s identity and labels, and the desired state you are asking for
apiVersion and kind together say which API type this is, so the server knows how to validate and handle it. metadata carries the name, namespace and labels — the identity and the handles other objects select on. spec is the desired state, the part you author. Most objects also have a status the server writes back with the observed state, which is the other half of the reconciliation loop: you write spec, the controller works toward it, and status reports where it got to.
-
What actually connects a Service to the Pods it sends traffic to?
- A list of Pod names in the Service spec, which the controller keeps up to date as Pods change
- The Deployment that owns both, which registers its Pods with the Service as it creates them
- Shared membership of a namespace, so every Pod in it is reachable through that namespace’s Service
- A label selector — any Pod carrying the labels is included, with no Pod named anywhere
Show the answer
D. A label selector — any Pod carrying the labels is included, with no Pod named anywhere
A label selector. The Service names a set of labels, and any Pod carrying them is included — there is no list of Pods anywhere and no reference by name. That indirection is what makes the whole model work: Pods come and go with different names and IPs, and the Service keeps matching whatever currently carries the labels. It is also why a typo in a label leaves a Service with no endpoints and no error: nothing matched, which is a valid state.
-
Why is a Kubernetes manifest usually kept in version control rather than applied ad hoc from a terminal?
- Applying from a terminal is not idempotent, so a repeated apply would create duplicate objects
- The manifest is the desired state, so the repository becomes a reviewable, revertible record of it
- The API server rejects manifests that do not carry a commit hash in their annotations
- Version control is where the cluster reads from, since the API server polls the repository
Show the answer
B. The manifest is the desired state, so the repository becomes a reviewable, revertible record of it
Because the manifest is the desired state, so the repository becomes the record of what the cluster is supposed to be — reviewable, diffable, and revertible. Applying changes by hand leaves the cluster holding state nobody wrote down, so the next person cannot tell what was intended from what drifted, and rebuilding it means reconstructing decisions from live objects. That is the whole premise of GitOps, and it works precisely because apply is declarative and idempotent.
-
Which line completes this Service, so it sends traffic to Pods labelled app: api?
apiVersion: v1 kind: Service metadata: name: api spec: selector: ___ ports: - port: 80 targetPort: 8080app.kubernetes.io/name: api-deploymentkind: Deploymentapp: apiname: api
Show the answer
C.
app: apiA Service finds its backends by matching labels on Pods, and by nothing else — it never names a Deployment, and the Pod's own name is not a label. This is what makes a Service indifferent to how the Pods came to exist, and it is also the failure mode: a selector that matches nothing produces a Service with no endpoints, which answers every request with a connection refused rather than an error saying why. The two ports are the other half — port is what the Service listens on, targetPort is the container port it forwards to.
-
Which line completes this Pod spec, so every key in the api-config ConfigMap arrives as an environment variable?
containers: - name: api image: api:1.4 ___ - configMapRef: name: api-configenv:volumeMounts:envFrom:envValueFrom:
Show the answer
C.
envFrom:envFrom imports every key of a ConfigMap or Secret at once, using the keys as the variable names. env is the other half of the pair and names variables one at a time, each with its own valueFrom.configMapKeyRef — more typing, but it can rename a key and take one value from a source holding many. volumeMounts would surface the same ConfigMap as files in a directory, which is what you want for a config file and not for an environment variable. Neither form re-reads the ConfigMap after the Pod starts: a change needs a restart.
-
Put these in the order they happen after kubectl apply -f deployment.yaml.
- The kubelet on that node pulls the image and starts it
- The API server validates the object and writes it to etcd
- The scheduler assigns each Pod to a node
- The Deployment controller sees it and creates a ReplicaSet
- The ReplicaSet controller creates the Pod objects
Show the answer
- The API server validates the object and writes it to etcd
- The Deployment controller sees it and creates a ReplicaSet
- The ReplicaSet controller creates the Pod objects
- The scheduler assigns each Pod to a node
- The kubelet on that node pulls the image and starts it
Nothing in this chain is a call to the next step: each controller watches the API server, notices that what exists differs from what is declared, and writes one object closer to it. That is why kubectl apply returns immediately having only written to etcd, and why a Pod stuck Pending is a scheduler answer rather than a kubectl one. It is also why the failure is always readable somewhere: whichever controller could not do its part records that on the object it was working on.
Practise the rest in the app
GapfyreSWE has 29 more Kubernetes questions at Intermediate and Advanced level, and over 4,700 across 80+ topics. It works offline and asks for no account.