Normal containers are flats in one building: they share the walls and the foundation, which is the node's kernel. If one tenant breaks through a wall, they reach the others. gVisor builds a small extra room inside each flat with its own walls, so a tenant who breaks out of their room is still inside the flat, not in the building's basement.
When sharing the node's kernel is too much trust
Every normal container shares the node's Linux kernel: one kernel bug, and a container can reach the host. gVisor puts a user-space kernel between the container and the host (its runtime is called runsc); Kata Containers puts a small VM there. You pick one per pod with a RuntimeClass:
apiVersion: node.k8s.io/v1
kind: RuntimeClass
metadata:
name: gvisor
handler: runsc # the runtime configured in containerd on the node
---
spec:
runtimeClassName: gvisor
No such RuntimeClass: the Pod is rejected ("RuntimeClass \"gvisor\" not found").
The node has no runsc configured in containerd: the pod cannot start ("no runtime for \"runsc\" is configured") - the RuntimeClass's scheduling.nodeSelector sends such pods only to nodes that have it.
Inside the sandbox the kernel is gVisor's: uname -r answers 4.4.0 and dmesg shows "Starting gVisor...". That is how you prove the pod really runs sandboxed.
The cost: system calls are slower, and some workloads (heavy I/O, special syscalls) do not fit. Sandbox the untrusted ones: user-supplied code, build jobs, multi-tenant workloads.
On the exam: domain "Minimize microservice vulnerabilities": create a RuntimeClass and run a pod with it.
Why it helps
A kernel bug is a path from one container to the host and to every other container on it. Sandboxed runtimes such as gVisor or Kata Containers add a boundary for workloads you do not trust: user-submitted code, build jobs, multi-tenant services. RuntimeClass is how a pod asks for that boundary, and proving the pod really runs sandboxed is part of the exam task.
FAQ
What does a RuntimeClass contain?
A name and a handler: the name is what pods put in runtimeClassName, and the handler names the runtime configured in containerd on the node, runsc for gVisor. It can also carry scheduling rules that send its pods only to nodes that have the runtime.
What happens if the RuntimeClass does not exist?
The Pod is rejected at admission with a message that the RuntimeClass was not found. Nothing is scheduled, so the mistake is visible immediately when you apply the manifest. Create the RuntimeClass first, then the pods that name it.
What if the node has no runsc?
The pod cannot start: the node reports that no runtime for runsc is configured. Use the RuntimeClass's scheduling.nodeSelector so pods only go to nodes where the runtime is installed. Without that rule the scheduler may pick a node that cannot run the pod.
How do I prove a pod runs in gVisor?
From inside the container: uname -r answers 4.4.0, gVisor's own kernel version, and dmesg shows gVisor's boot messages such as Starting gVisor. A normal container shows the node's real kernel instead. Always check from inside; a field in YAML proves nothing on its own.
What does gVisor cost?
System calls are slower because gVisor handles them in user space, and some workloads with heavy I/O or unusual system calls do not fit. That is why you sandbox the untrusted workloads, not everything. Measure the slowdown before you move a latency-sensitive service.
In an interview Mid
How would you run untrusted code in a Kubernetes cluster more safely?
In a sandboxed runtime: create a RuntimeClass with handler runsc for gVisor (or a Kata handler), make sure the nodes have that runtime configured in containerd and pin the pods to them with the RuntimeClass's scheduling.nodeSelector, then set runtimeClassName on the pod and prove it from inside - uname -r shows gVisor's 4.4.0 instead of the node kernel.
Also asked: What is the difference between gVisor and Kata Containers? · What happens if the node lacks the runtime? · Which workloads would you not sandbox, and why?