Keyboard shortcuts

/ or ⌘/Ctrl K
Find a note
j / k
Next / previous section or linked note
h / l
Collapse or go to parent / expand or enter
e or Alt-click
Read a linked note here
o
Open focused note on its own
g g / G
First / last section or linked note
g h / g a
Home / all notes
g b / g t
Backlinks / table of contents
t
Cycle System, Light, Dark
? / Esc
Show / close this reference

Search: ↑/↓ or Ctrl N/P, Enter to open. Shortcuts pause while typing.

pod lifecycles [e0b55c49]

Tags: kubernetes (k8s)

1. Three states

  • waiting
  • running
  • terminated

    • use kubectl describe

2. Terminating Gracefully

  • Cleanups?
  • Resources?
  • Forced termination?
  • SIGTERM/SIGKILL
  • Lifecycle

    1. Set the grace period -> terminating state -> traffic
    2. preStop hook -> grace of 2 seconds
    3. send SIGTERM to pid 1
    4. grace period sends SIGKILL
    5. API server deletes the pod's API object

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.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

  • Call sent to container before terminated
  • use when reacting to SIGTERM
  • always ends before SIGKILL is sent
  • used for graceful termination

4.3. initContainers

  • runs various preconditions before the container startup
  • exaples

    • DB, create user accounts, DB migrations

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

  • 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