apiVersion: v1
kind: Pod
metadata:
  name: pod-with-prestop-hook
  namespace: chp17-set1726
spec:
  containers:
  # Cannot use scratch-based image here, since it lacks a shell and we cannot run `sh`, etc
  # - image: georgebaptista/kubia:v1
  - image: luksa/kubia
    name: kubia
    command:
    - sh
    - -c
    - 'echo "`date` start" >> /tmp/log/log.txt ; sleep 10000 ; exit 1'
#    - 'touch /tmp/log/log.txt'
#    - 'echo "`date` start" >> /tmp/log/log.txt ; sleep 500 ; exit 1'
#    livenessProbe:
#      initialDelaySeconds: 5 
#      exec:
#        command:
#        - sh
#        - -c
#        - "exit 1"
    volumeMounts:
    - name: log
      mountPath: /tmp/log
    lifecycle:
      preStop:
        exec:
          command: 
          - sh
          - -c
          - |
            echo "`date` pod termination: preStop, sleep 5" >> tmp/log/log.txt
            sleep 5
            echo "`date` pod termination: final stop" >> tmp/log/log.txt
  volumes:
  - name: log
    emptyDir:
      medium: Memory
