Skip to main content

Chapter 3.1 - Introduction to Pods

Learning Objectives

By the end of this chapter, you will be able to:

  • Understand what a Pod is
  • Explain why Pods exist
  • Distinguish Pods from containers
  • Understand multi-container Pod use cases

What is a Pod?

A Pod is the smallest deployable unit in Kubernetes. It is a group of one or more containers that share:

  • The same IP address
  • The same network namespace
  • The same volumes (storage)
  • The same IPC namespace

Why Pods?

Abstraction Above Containers

Kubernetes does not manage containers directly, but Pods:

Advantages:

  • Container group management
  • Resource sharing
  • Network consistency

Single-Container Pods

Most Pods contain a single container:

apiVersion: v1
kind: Pod
metadata:
name: nginx-pod
spec:
containers:
- name: nginx
image: nginx:1.20

Multi-Container Pods

A Pod can contain multiple containers that work together:

Use Case: Sidecar Pattern

apiVersion: v1
kind: Pod
metadata:
name: app-with-logger
spec:
containers:
- name: app
image: my-app:1.0
- name: logger
image: fluentd:latest

Sidecar examples:

  • Logging (Fluentd, Logstash)
  • Monitoring (Prometheus exporter)
  • Proxy (Envoy, nginx)
  • File synchronization

Inter-Container Communication Within a Pod

Containers in a Pod communicate via localhost:

Example:

# From container 1
curl http://localhost:8080 # Communicates with container 2

Shared Volumes

Containers in a Pod share volumes:

apiVersion: v1
kind: Pod
metadata:
name: shared-volume-pod
spec:
containers:
- name: writer
image: busybox
volumeMounts:
- name: shared-data
mountPath: /data
- name: reader
image: busybox
volumeMounts:
- name: shared-data
mountPath: /data
volumes:
- name: shared-data
emptyDir: {}

Summary

In this chapter, you learned:

Pod: Smallest deployable unit, group of containers
Shared resources: IP, network, volumes, IPC
Single-container Pods: Most common case
Multi-container Pods: For sidecars and collaborative containers
Communication: Via localhost between containers in the same Pod


Next Steps

Now that you understand Pods:

Chapter 3.2: YAML Declaration for Pods
Lab 3.1: Creating and Managing Pods


Chapter created: December 2024