Job Sidecar Terminator

    In Kubernetes world, for job workload, one may expect pods enter phase once the main container exited. However, when these pods have long-running sidecar containers, these sidecars will actually remain running after the main containers completed.

    To solve such problem, job sidecar terminator controller watches and terminates sidecar containers for such job-type Pods when its main containers completed.

    • Enabled JobSidecarTerminator feature gate when installing/upgrading Kruise (defaults to disabled).

    Usage

    It is very easily to use this feature if your Pods run on normal nodes, you just need to add a special env to the sidecar containers you want to terminate in the Pods, and Kruise will terminate them using at the right time:

    Step 1: Prepare a special image

    • This image should exit as soon as it is pulled and started.
    • This image should be compatible with the commands and args of original sidecar container.

    Step 2: Config your sidecar container

    1. kind: Job
    2. spec:
    3. template:
    4. spec:
    5. - name: sidecar
    6. - name: KRUISE_TERMINATE_SIDECAR_WHEN_JOB_EXIT_WITH_IMAGE
    7. value: "example/quick-exit:v1.0.0"
    8. - name: main
    9. ... ...

    Replace "example/quick-exit:v1.0.0" with your prepared image.

    • Your sidecar container must respond the SIGTERM signal, and the entrypoint should when received this signal.

    • This feature can handle the Pods with Never/OnFailure restart policy, and doesn’t care which type of job controllers they’re controlled by.

    • The sidecars will be terminated when ALL main containers completed.

    • In OnFailure restart policy settings, main container will be treated as completed once it exit and exit code must be 0.