teamhephy / workflow

Hephy Workflow - An open source fork of Deis Workflow - The open source PaaS for Kubernetes.
MIT License
411 stars 36 forks source link

Feature: lifecycle preStop postStart hooks in Kubernetes pods #15

Open Cryptophobia opened 6 years ago

Cryptophobia commented 6 years ago

From @Cryptophobia on June 12, 2017 20:46

We are trying to implement lifecycle preStop and postStart hooks that will be respected by resque workers inside Kubernetes pods. We want to define scripts that will run in the Deis applications by setting environment variables to run preStop and postStart hooks. Except imagine that the command part is just a long environment variable set in Deis environment variables:

    lifecycle:
      postStart:
        exec:
          command: 
            - "/bin/bash" 
            - "-c" 
            - >
              echo 'Ran the postStart Lifecycle Handler' > test;
      preStop:
        exec:
          command: 
            - "/bin/bash" 
            - "-c" 
            - >
              kill -QUIT 1;

The problem that we are encountering is this:

The deis/kubernetes process is monitoring the worker process, in our case resque-pool with pid 1. Once we send the -QUIT command to this process, the Kubernetes worker pod enters "CrashBackoffLoop" and restarts the main resque-pool worker process. This is great behavior for resiliency, but not the behaviour we want because we want the pod to be terminated after the workers are terminate gracefully. However, the worker pod is restarted because something is monitoring the main process.

Is there a way we can unhook the deis/kubernetes main process monitor from binding to pid 1 from inside the pod or is there a simpler way to implement lifecycle hooks like the example above?

We were hoping for a successful test so that we can contribute to the deis-workflow by adding environment variables for lifecycle hooks and support for them.

Any help would be greatly appreciated.

Copied from original issue: deis/workflow#825

pdomagala commented 5 years ago

@Cryptophobia Any update on that feature?