# Pods — Kubernetes

Source: https://www.skillbyai.com/en/kubernetes/w-pod

> The smallest deployable unit.

## One or more tightly coupled containers

A **Pod** wraps one or more containers that share a network address, can share volumes, and are always scheduled together on the same node. Most pods run one main container, sometimes with **sidecars** (log shippers, proxies) or **init containers** that run first. Pods are **ephemeral**: when one dies or its node fails it is not resurrected; a controller creates a new pod with a new IP. You rarely create pods directly; use a Deployment, StatefulSet, DaemonSet or Job to manage them.

## Pods, Deployments, rollouts and jobs

Controllers manage pods for long-running services and run-to-completion tasks.

![Four ideas: pods, Deployments, rolling updates, Jobs.](assets/figures/kubernetes/section-2-map.svg) — Figure 2.1 — Pods, Deployments, rollouts and Jobs.

## A pod with an init container and a sidecar

Not applied to a live cluster in this course; check field names against the API reference for your version.

```yaml
apiVersion: v1
kind: Pod
metadata:
  name: web-debug
  labels: {app: web}
spec:
  initContainers:
  - name: wait-for-db
    image: busybox:1.36
    command: ["sh", "-c", "until nc -z db 5432; do sleep 2; done"]
  containers:
  - name: web
    image: ghcr.io/example/web:1.4.0
    ports: [{containerPort: 8080}]
  - name: log-shipper
    image: fluent/fluent-bit:3.0
```

## Never rely on pod IPs

Pods come and go with new addresses; reach them through Services.

**Quiz:** What happens to a pod when its node dies?

- [ ] It moves with the same IP
- [x] It is gone; a controller creates a replacement pod with a new IP
- [ ] It is paused until the node returns
- [ ] The cluster stops

*Answer:* It is gone; a controller creates a replacement pod with a new IP. Pods are ephemeral.
