Kubernetes Pods, Sidecars, and Workload Controllers
Namespaces: logical clusters without built-in firewalls
A Namespace partitions a physical Kubernetes cluster into multiple “logical clusters”, allowing teams to organize resources and apply RBAC permissions separately. Crucially, namespaces provide no pod-to-pod firewalling by default—every pod can ping every other pod across namespaces until an administrator configures a NetworkPolicy (see Kubernetes Multi-Tenancy Quotas and Autoscaling).
Pods: the scheduling atom
A Pod is the smallest deployable execution unit in Kubernetes—analogous to a process in an operating system. It wraps one or more tightly coupled containers and shared disk volumes, and must execute on a single worker node.
- Ephemeral lifecycle: A Pod is bound to its scheduled node; containers can restart in place, or the Pod can die—in which case it cannot be reborn with the same ID or IP address.
- Sidecar containers: Although most Pods run one container, multi-container Pods let helper “sidecar” containers extend the main container (for example, a log saver, monitoring agent, auth proxy, or file-puller sharing a volume with a web server). Because containers inside a Pod share the network stack, the main app reaches its sidecar directly via
localhostwithout external service discovery.
Linux namespaces inside a Pod
A Pod does not share every Linux isolation boundary identically across its containers:
| Linux namespace | Shared by containers in a Pod? | Practical effect |
|---|---|---|
Network (net) | Yes | Same IP address, port space, loopback (localhost), and interfaces |
IPC (ipc) | Yes | Shared SysV IPC and POSIX message queues |
UTS (uts) | Yes | Shared hostname |
PID (pid) | Optional | Shared only if shareProcessNamespace: true is set |
Mount (mnt) | No | Separate root filesystems (files are shared only via explicitly mounted Volumes) |
User (user) | No | Separate user namespaces (rarely enabled in Kubernetes) |
Init containers and privileged pods
- Init Containers: Specialized setup containers that run before application containers (for example, waiting for a companion service, cloning a Git repo into a shared volume, or templating configuration files using tools absent from the main image). Each init container runs to completion sequentially before the next one or the main app starts.
- Privileged Pods: Pods granted elevated host permissions to manage hardware devices (GPUs, NICs, storage), configure kernel modules, mount
/sysor/proc, or run host-level networking/security scanners—commonly deployed via aDaemonSet.
Pets vs. cattle and workload controllers
Traditional infrastructure treats servers as pets (unique names, bespoke manual setup, manual repair when sick). Cloud-native Kubernetes workloads treat pods as cattle (generic identifiers, templated config, automatically destroyed and replaced upon failure). Four workload controllers implement these patterns:
| Controller | How it manages Pods | Typical use case |
|---|---|---|
ReplicaSet (rs) | Uses labelSelector and a PodTemplate to continuously maintain replicas: N healthy pods, spawning replacements on other nodes if one fails | Low-level replica enforcement (normally created indirectly by a Deployment) |
Deployment (deploy) | Wraps ReplicaSets to manage application lifecycle and versions: Rolling Updates, Rollbacks, and Scaling (spawning a new RS and shifting pods gradually) | Stateless microservices and web frontends |
| DaemonSet | Guarantees one copy of a Pod runs on every node (automatically scheduling onto newly joined nodes) | Node networking plugins (CNI), log/metric agents |
| StatefulSet | Manages stateful Pods requiring stable unique network IDs, stable persistent storage, and ordered deployment, scaling, and rolling updates preserved across rescheduling | Databases, consensus stores, distributed queues |
ConfigMap vs. Secret
Both inject external configuration into containers as mounted files or environment variables so container images stay portable:
| Feature | ConfigMap (cm) | Secret |
|---|---|---|
| Purpose | Non-sensitive configuration data | Passwords, TLS certificates, API keys |
| Encoding | Plain text | Base64-encoded |
| Access control | Treated as non-sensitive | Restricted via RBAC |
| Storage & delivery | Stored in etcd as plain text | Stored in etcd (base64 + encrypted in modern versions); mounted/injected and decrypted at runtime |
Common confusion: Base64 is encoding, not encryption. Anyone granted RBAC permission to
getaSecretcan trivially decode the base64 string back to plaintext.
Retrieval
- A web container and a log-shipper sidecar run inside the same Pod. Can the web container send logs to the sidecar on
localhost:9000, and can the sidecar read/var/log/nginxfrom the web container’s root filesystem without a Volume?
Yes tolocalhost:9000, because containers in a Pod share thenetnamespace (same IP, ports, and loopback). No to reading/var/log/nginxdirectly, because each container keeps a privatemntnamespace—an explicit shared Volume must be mounted into both containers. - Why would you choose a
StatefulSetinstead of aDeploymentfor a clustered database, and aDaemonSetfor a node monitoring agent?
StatefulSetpreserves stable network identities, stable persistent volumes, and ordered updates across pod rescheduling, whereasDeploymenttreats pods as interchangeable cattle.DaemonSetguarantees exactly one monitoring Pod runs on every node (including newly added nodes).
Source: Lecture 11 - Kubernetes, PDF pages 12–27 (printed slides 13–31).