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 localhost without external service discovery.

Linux namespaces inside a Pod

A Pod does not share every Linux isolation boundary identically across its containers:

Linux namespaceShared by containers in a Pod?Practical effect
Network (net)YesSame IP address, port space, loopback (localhost), and interfaces
IPC (ipc)YesShared SysV IPC and POSIX message queues
UTS (uts)YesShared hostname
PID (pid)OptionalShared only if shareProcessNamespace: true is set
Mount (mnt)NoSeparate root filesystems (files are shared only via explicitly mounted Volumes)
User (user)NoSeparate 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 /sys or /proc, or run host-level networking/security scanners—commonly deployed via a DaemonSet.

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:

ControllerHow it manages PodsTypical use case
ReplicaSet (rs)Uses labelSelector and a PodTemplate to continuously maintain replicas: N healthy pods, spawning replacements on other nodes if one failsLow-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
DaemonSetGuarantees one copy of a Pod runs on every node (automatically scheduling onto newly joined nodes)Node networking plugins (CNI), log/metric agents
StatefulSetManages stateful Pods requiring stable unique network IDs, stable persistent storage, and ordered deployment, scaling, and rolling updates preserved across reschedulingDatabases, consensus stores, distributed queues

ConfigMap vs. Secret

Both inject external configuration into containers as mounted files or environment variables so container images stay portable:

FeatureConfigMap (cm)Secret
PurposeNon-sensitive configuration dataPasswords, TLS certificates, API keys
EncodingPlain textBase64-encoded
Access controlTreated as non-sensitiveRestricted via RBAC
Storage & deliveryStored in etcd as plain textStored 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 get a Secret can trivially decode the base64 string back to plaintext.

Retrieval

  1. 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/nginx from the web container’s root filesystem without a Volume?
    Yes to localhost:9000, because containers in a Pod share the net namespace (same IP, ports, and loopback). No to reading /var/log/nginx directly, because each container keeps a private mnt namespace—an explicit shared Volume must be mounted into both containers.
  2. Why would you choose a StatefulSet instead of a Deployment for a clustered database, and a DaemonSet for a node monitoring agent?
    StatefulSet preserves stable network identities, stable persistent volumes, and ordered updates across pod rescheduling, whereas Deployment treats pods as interchangeable cattle. DaemonSet guarantees exactly one monitoring Pod runs on every node (including newly added nodes).

Source: Lecture 11 - Kubernetes, PDF pages 12–27 (printed slides 13–31).