Foundations: web, servers, containersLesson 7 of 13
Linux Basics for Kubernetes
Every Kubernetes node is a Linux machine, and every container is a Linux process. Follow one app on one host: how it starts, how it is stopped, what its exit code says, why it gets "permission denied", and where its logs go.
Process treebash
Signal—
Exit code—
Access—
RequestResponse / reportAppears in a later step
What you will learn
- PIDs, parents and children, and what PID 1 does
- SIGTERM vs SIGKILL vs SIGHUP, and trap
- Reading exit codes: 0, 1, 126, 127, 128+n and 137
- Users, root, sudo and rwx permissions
- systemd units, journalctl and where logs live
Exit codes and signals at a glance
| Code | Meaning | Typical cause | What to check |
|---|---|---|---|
| 0 | Success | The program finished normally | — |
| 1 | General error | The program reported a failure itself | App logs |
| 2 | Misuse of a shell builtin or bad arguments (common convention) | Wrong flags | The command line |
| 126 | Found but cannot run | Missing x bit, or a directory or wrong binary format | ls -l, chmod +x |
| 127 | Command not found | Typo, or not in PATH (or missing in the image) | which cmd, echo $PATH |
| 128 + n | Killed by signal n | — | Which signal, and who sent it |
| 130 | 128 + 2, SIGINT | Ctrl+C | — |
| 137 | 128 + 9, SIGKILL | OOM kill, grace period over, kill -9 | kubectl describe pod Reason, dmesg |
| 143 | 128 + 15, SIGTERM | Normal stop request, app did not catch it or exited with the default | Usually fine during shutdown |
| Signal | Number | Can be caught? | Usual meaning |
|---|---|---|---|
| SIGHUP | 1 | Yes | Terminal closed, or "reload config" by convention |
| SIGINT | 2 | Yes | Ctrl+C |
| SIGKILL | 9 | No | Stop now, no cleanup |
| SIGTERM | 15 | Yes | Please stop; the default from kill and from Kubernetes |
Try it yourself
# Processes, parents and users (on a Linux host or VM)
echo $$ # PID of this shell
ps -o pid,ppid,user,cmd -p $$
sleep 300 & # child of this shell
ps -o pid,ppid,cmd --ppid $$
id # your UID, GID and groups
# Signals and exit codes
sleep 300 & kill $!; wait $!; echo "exit $?" # 143 = 128 + 15
sleep 300 & kill -9 $!; wait $!; echo "exit $?" # 137 = 128 + 9
nosuchcmd; echo "exit $?" # 127
bash -c 'trap "echo got TERM; exit 0" TERM; sleep 30 & wait' & sleep 1; kill $!; wait $! # trap runs
# Permissions
echo secret > demo.txt && chmod 600 demo.txt && ls -l demo.txt # -rw-------
printf '#!/bin/sh\necho hi\n' > hi.sh; ./hi.sh; echo "exit $?" # 126, no x bit
chmod +x hi.sh && ./hi.sh
# systemd and logs (on a Linux host or a kind node: docker exec -it lab-control-plane bash)
systemctl status kubelet --no-pager
journalctl -u kubelet --since "10 min ago" --no-pager | tail
ls /var/log/pods /var/log/containers | head
Check yourself
Further reading: signal(7) · chmod(1) · journalctl · Pod termination · Graceful shutdown — going down without losing requests · How Linux Isolates a Container