Kubernetes Workloads
Pods — The Smallest Deployable Unit
Pod networking, shared volumes, and container relationships.
Interview: Interviewers will check if you understand container sharing inside a Pod. Be ready to explain how containers inside a single Pod share the network namespace (localhost routing), IPC namespace, and storage volumes, but remain isolated via separate PID namespaces.
What is a Pod?
A Pod is the smallest deployable computing unit in Kubernetes. It represents a single instance of a running process in your cluster. Unlike traditional virtual environments where you deploy individual containers, Kubernetes manages Pods, which wrap one or more tightly coupled containers.
Shared Context and Namespace Sharing
Containers inside the same Pod share namespaces, meaning they operate as if they were running on the same physical host:
- Network Sharing: All containers in a Pod share the Pod's network namespace, sharing the same IP address and port space. They communicate with each other using
localhost(e.g. a Node web app can communicate with a database cache container onlocalhost:6379). - Storage Sharing: You can define volumes at the Pod level. These volumes can be mounted into the filesystem of multiple containers within the Pod, allowing them to share files in real-time.
Multi-Container Patterns
Most Pods contain a single container. However, you should run multiple containers in a single Pod if they are tightly coupled and depend on sharing files or network spaces. Common patterns include:
- Sidecar Pattern: A helper container that enhances the primary application. For example, a main container runs a web server while a sidecar container pulls updated static files or collects logs and forwards them to a central logging driver.
- Init Containers: Specialized containers that run and complete before application containers start. They are useful for checking database availability, parsing environment secrets, or running migrations before starting the main application.
Multi-Container Pod Manifest
Here is a YAML manifest representing a Pod with an application container and a sidecar container sharing an in-memory volume: