Docker and Kubernetes course menu
Advanced Docker and Kubernetes Interview Questions
Advanced Docker and Kubernetes interview questions with answers: namespaces and cgroups, overlay storage, security, PID 1, pods, deployments, services, probes and troubleshooting.
On this page
- Docker internals
- 1. How do containers work under the hood?
- 2. What is overlay2?
- 3. What are containerd and runc?
- 4. Why does PID 1 matter in a container?
- 5. What does BuildKit add?
- 6. What are the risks of mounting the Docker socket?
- 7. How would you harden a container?
- 8. What is rootless Docker?
- 9. How do you make builds reproducible?
- Kubernetes
- 10. What is the difference between a pod and a container?
- 11. What is the difference between a Deployment, a StatefulSet and a DaemonSet?
- 12. How does a rolling update work?
- 13. What is the difference between liveness and readiness probes?
- 14. Explain ClusterIP, NodePort, LoadBalancer and Ingress.
- 15. What is the difference between requests and limits?
- 16. Are Kubernetes Secrets encrypted?
- 17. What does the scheduler do?
- 18. A pod is in CrashLoopBackOff. What do you do?
- 19. A pod is stuck in Pending. Why?
- 20. How does a Service find its pods?
DevOps and senior interviews look at how containers work inside, how to secure them, and how to run them on Kubernetes.
Docker internals#
1. How do containers work under the hood?#
Show solution
A container is a process, isolated with Linux namespaces (PIDs, network, mounts and more), limited with cgroups (CPU and memory), and given a file system by a union file system. There is no separate kernel.
2. What is overlay2?#
Show solution
Docker's default storage driver. It stacks image layers as read-only directories, and adds a writable layer on top. Changing a file copies it up to the writable layer first, which is called copy-on-write.
3. What are containerd and runc?#
Show solution
Docker's daemon uses containerd to manage the container lifecycle and images, and containerd uses runc to create containers according to the OCI standard. Kubernetes talks to containerd directly.
4. Why does PID 1 matter in a container?#
Show solution
The process with PID 1 gets signals such as SIGTERM, and must reap zombie child processes. Many apps do neither well. Use the exec form, handle signals, or add --init.
5. What does BuildKit add?#
Show solution
Parallel builds, better caching, build secrets, SSH forwarding, multi-platform builds through buildx, and remote cache export.
6. What are the risks of mounting the Docker socket?#
Show solution
A container with access to /var/run/docker.sock can start privileged containers and mount the host's file system, which amounts to root on the host.
7. How would you harden a container?#
Show solution
Use a minimal, pinned, scanned image. Run as non-root, with a read-only root file system, --cap-drop=ALL, no-new-privileges, resource and PID limits, and no --privileged. Keep secrets out of the image.
8. What is rootless Docker?#
Show solution
Running the Docker daemon and containers as a normal user, using user namespaces, so that a container escape does not give root on the host.
9. How do you make builds reproducible?#
Show solution
Pin base images by digest, use lock files, avoid fetching floating versions during the build, and build in CI.
Kubernetes#
10. What is the difference between a pod and a container?#
Show solution
A pod is the smallest unit in Kubernetes. It holds one or more containers that share a network address and can share volumes. Sidecars, such as log shippers, run in the same pod.
11. What is the difference between a Deployment, a StatefulSet and a DaemonSet?#
Show solution
A Deployment runs interchangeable pods, for stateless apps. A StatefulSet gives pods stable names and their own storage, for databases. A DaemonSet runs one pod on each node, for agents such as log collectors.
12. How does a rolling update work?#
Show solution
The Deployment creates a new ReplicaSet, and scales it up while scaling the old one down, within maxSurge and maxUnavailable. New pods get traffic once they pass readiness checks. kubectl rollout undo goes back.
13. What is the difference between liveness and readiness probes?#
Show solution
A failing readiness probe removes a pod from Service traffic. A failing liveness probe restarts the container. Startup probes protect slow-starting apps.
14. Explain ClusterIP, NodePort, LoadBalancer and Ingress.#
Show solution
ClusterIP is internal only. NodePort opens a port on each node. LoadBalancer creates a cloud load balancer. Ingress is an HTTP router by host and path, and needs an ingress controller.
15. What is the difference between requests and limits?#
Show solution
Requests are what the scheduler reserves, and limits are the maximum. Exceeding a memory limit kills the container, and exceeding a CPU limit throttles it.
16. Are Kubernetes Secrets encrypted?#
Show solution
By default, they are only base64-encoded in the API. You should enable encryption at rest, restrict access with RBAC, and consider External Secrets or a vault.
17. What does the scheduler do?#
Show solution
It picks a node for each new pod, based on requests, node resources, affinity rules, taints and tolerations.
18. A pod is in CrashLoopBackOff. What do you do?#
Show solution
Use kubectl logs --previous and kubectl describe pod to read the events. Common causes are a bad config, a missing secret, a failing liveness probe, or an out-of-memory kill.
19. A pod is stuck in Pending. Why?#
Show solution
No node fits it. Usually it needs more CPU or memory than is free, a volume cannot be bound, or taints and affinity rules block it. kubectl describe pod shows the reason.
20. How does a Service find its pods?#
Show solution
Through its label selector. Kubernetes keeps EndpointSlices listing the ready pods, and kube-proxy routes traffic to them. DNS maps the Service's name to its stable address.
Finished this lesson?
Related lessons
Recommended Docker and Kubernetes resources
- Docker Deep Dive by Nigel Poulton
A practical guide to how Docker works, for readers who have finished the basics.
Some links are affiliate links. If you buy through them, Laviyx Learn may earn a commission at no extra cost to you. As an Amazon Associate, we earn from qualifying purchases.