0

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.

Srividya
  • 1,678
  • 3
  • 10
grabbag
  • 980
  • 1
  • 15
  • 33
  • if you execute microk8s kubectl delete -f k8s/production/transcribe-worker.yaml --force --grace-period=0 does the event trigger ? – jmvcollaborator Aug 28 '22 at 23:35
  • check the pod lifecycle here: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#pod-termination – jmvcollaborator Aug 28 '22 at 23:39
  • delete does not trigger the prestop, but curl http://10.1.56.55:8080/prestop does. Where the IP I got from k describe pod xxxx – grabbag Aug 29 '22 at 13:51
  • another weird thing, exec into container and execute "ps x". PID 1 is /bin/sh -c node .... so this explains why I can't process.once('SIGTERM', function (code) . But I though prestop was a fall back – grabbag Aug 29 '22 at 14:19
  • https://tasdikrahman.me/2019/04/24/handling-singals-for-applications-in-kubernetes-docker/ explains the weird thing that made catching the sigterm not possible hence why I wanted prestop. – grabbag Aug 29 '22 at 14:46

0 Answers0