2 min read | by Jordi Prats
If we need to execute some actions at container startup of before stopping the container we can me use of the container lifecycle hooks
We have the following hooks available:
apiVersion: apps/v1
kind: Deployment
(...)
template:
spec:
(...)
containers:
- name: pet2cattle
(...)
lifecycle:
postStart:
exec:
command: [ "/usr/local/bin/python", "/code/cachewarmer.py" ]
apiVersion: v1
kind: Pod
(...)
spec:
containers:
- name: lifecycle-demo
(...)
lifecycle:
preStop:
exec:
command: ["/bin/sh","-c","nginx -s quit; while killall -0 nginx; do sleep 1; done"]
Posted on 24/09/2021