pod lifecycles [e0b55c49]
Tags: kubernetes (k8s)
1. Three states
1. Three states
- waiting
- running
-
terminated
- use kubectl describe
2. Terminating Gracefully
2. Terminating Gracefully
- Cleanups?
- Resources?
- Forced termination?
- SIGTERM/SIGKILL
-
Lifecycle
- Set the grace period -> terminating state -> traffic
- preStop hook -> grace of 2 seconds
- send SIGTERM to pid 1
- grace period sends SIGKILL
- API server deletes the pod's API object
3. Health Probes
3. Health Probes
- Kubelet brings up the containers and keeps them running, also responsible for restarts
- uses some Process Health Checks to check the status
- Stalls?
-
Types of probes
-
Exec
- Runs every so often, checks for the exit code
- TCP socket
- HTTP get
-
-
Liveness Probes
- Check if the container is alive or dead
- Always define a liveness probe for prod apps
- Have the application expose a health-check API that doesn't require auth
- Keep probes light as CPU resources
- Readniess Probes
-
Startup probes
- Indicates whether the container has started
- Disables other probes until this is done
4. Hooks
4. Hooks
4.1. postStart hook
4.1. postStart hook
- Runs after container is created, async
- No guarantees of running
- postStart is a blocking call
- container remains in Waiting until the handler completes
4.2. preStop
4.2. preStop
- Call sent to container before terminated
- use when reacting to SIGTERM
- always ends before SIGKILL is sent
- used for graceful termination
4.3. initContainers
4.3. initContainers
- runs various preconditions before the container startup
-
exaples
- DB, create user accounts, DB migrations
4.4. Scheduling and resources
4.4. Scheduling and resources
- Effective request/limit is the max(sum request/limit for all the application containers, effective request limit)
5. Init vs postStart hook vs Startup Probe
5. Init vs postStart hook vs Startup Probe
- Probes and hooks run in the same container, init containers run on the whole pod
- hooks have no guarantees
-
usages:
-
postStart
- signal to external listeners
-
init
- initalization
-
probes
- slow starting containers
-