Every Pod so far held one container. The Pod can hold more, and sometimes it should.
One Pod, shared
namespace tandem
- market-web (web + log-shipper)Website
Containers in the same Pod share:
| Shared | So |
|---|---|
| The IP and the ports | Container A reaches container B on localhost:PORT |
| The lifetime | They are scheduled, started and deleted together |
| Volumes the Pod declares | Both can read and write the same files (next lesson) |
They do not share a filesystem or a process list. Each container is still its own image with its own command.
yaml
spec:
containers:
- name: web
image: stackmonsters/monster-market-web
- name: helper
image: busybox
command: ["sh", "-c", "sleep 3600"]text
learner@shallows:~$ kubectl get pod market-web
NAME READY STATUS RESTARTS AGE
market-web 2/2 Running 0 8s
learner@shallows:~$ kubectl exec market-web -c helper -- wget -qO- http://localhost
<!doctype html>READY counts containers. -c picks one for exec and logs.
When to do it
The question is "does this process belong to that one?". A log shipper that reads the web server's files, a proxy that fronts exactly one app, a tool that renders the app's config: yes. The database behind the API: no. The database scales and restarts on its own schedule and gets its own Pod behind a Service.