The livenessProbe works, but the lifecycle preStop does not.
My yaml:
- image: localhost:32000/worker:2022-08-28-h
name: worker-container
ports:
- containerPort: 55001
name: name-b
livenessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 60
periodSeconds: 15
failureThreshold: 3
timeoutSeconds: 10
lifecycle:
preStop:
httpGet:
path: /prestop
port: 8080
The pod:
const express = require('express');
const app = express();
app.get('/prestop', (req, res) => {
console.log("rx prestop")
.....
res.send("prestop passed");
});
app.get('/healthz', (req, res) => {
console.log("health check rx")
.....
res.send("Health check passed");
});
When I apply my yaml file, I see the health probe working as expected with logs "health check rx" and "Health check passed".
When I change the code in "...." to return
res.status(500).send('Health check did not pass')
I see microk8s kubectl restart my module after 3 failed probes. I was expecting the restart of the container to trigger lifecycle preStop but it does not.
Am I correct in assuming a container restart because of failed liveness problems will trigger the preStop event? The documentation I could find is not explicit about this.
microk8s kubectl delete -f k8s/production/transcribe-worker.yaml
Also does not trigger the preStop event.
So I suspect I do not understand how preStop works. Maybe a limitation of microk8s? Help would be appreciated.