PID 1, SIG Handling, Hooks & Probes: Managing Container Lifecycle Correctly

Anmol Krishan Sachdeva at KubeCon + CloudNativeCon North America 2020

The lifecycle of an application should be tightly linked to the container hosting it. In an environment like Kubernetes where the Pods get created and deleted left, right, and centre, if an application hasn't implemented signal handling correctly, ungraceful termination of that application is most likely to happen and it could lead to disrupted services. For running the containers in a reliable fashion with proper signal handling and lifecycle management, there are a few strategies that should be followed which this talk would be covering: ~ Signal handling through `init` system - covers PID 1, orphans and zombie processes, Linux signals, `dumb-init` or `tini`. ~ Utilizing postStart and preStop lifecycle hooks for initialization and graceful termination. ~ Liveness, Readiness, and Startup probes. ~ Key differences between the postStart hook, initContainer, and Startup Probe.