preStop lifecycle hook not executed not execued in containers(that are part of deployments


#1

I’m trying to execute some command in preStop hook in container, but I don’t see anything in logs/events. Can someone please help me how to check preStop logs and verify if it was really execute?

`apiVersion: v1
kind: Pod
metadata:
name: lifecycle-demo
spec:
containers:

  • name: lifecycle-demo-container
    image: nginx
    lifecycle:
    postStart:
    exec:
    command: ["/bin/sh", “-c”, ’ echo “i: (date)”; ']
    preStop:
    exec:
    command: ["/bin/sh","-c","echo Hello from the preStop handler "]
    terminationGracePeriodSeconds: 180`

#2

As a hack, if you redirect the echo to a file, and do a sleep afterwards, can’t you see the file created if you attach?