apiVersion: v1
kind: Pod
metadata:
  name: lifecycle-check
spec:
  restartPolicy: Never
  terminationGracePeriodSeconds: 30
  initContainers:
  - name: init
    image: busybox
    command: ["sh", "-c"]
    args:
    - |
      echo Start at `date`; sleep 3; echo End at `date`. ; exit 0
  containers:
  - name: motor
    image: busybox
    resources:
      limits:
        cpu: 100m
        memory: 16Mi
      requests:
        cpu: 100m
        memory: 16Mi
    command: ["sh", "-c"]
    args:
    - |
      trap 'echo "Trapped SIGTERM"; sleep 3; echo "See you!!"; exit 0' TERM

      echo Start.

      while true
      do
          date
          sleep 1
      done
    lifecycle:
      postStart:
        exec:
          command:
            - sh
            - -c
            - |
              echo hook postStart.
              date
              exit 0
      preStop:
        exec:
          command:
            - sh
            - -c
            - |
              echo hook preStop.
              date
              exit 0
  - name: sidecar
    image: busybox
    imagePullPolicy: IfNotPresent
    command: ['sh', '-c', 'echo The Pod is running && sleep 60']
    resources:
      limits:
        cpu: 100m
        memory: 16Mi
      requests:
        cpu: 100m
        memory: 16Mi