1

I have a kubernetes manifest file which has 2 containers. Main container is collecting data at a certain time period and other (logstash) container reading logs for the main container and shipping it to the ELK stack. Once the main container completed its job, what is the best way to gracefully signal or shutdown the logstash container?

David Maze
  • 130,717
  • 29
  • 175
  • 215
Leinz
  • 151
  • 3
  • 15

1 Answers1

2

Currently, there is no way to explicitly mark a container as "Sidecar" (though there is a long-lasting KEP to implement it).

It means that the best you can do is to define Container Lifecycle Hook with the command to gracefully shutdown your sidecar container. Something like:

  containers:
  - name: logstash-container
    image: logstash-image
  - name: your-main-container
    image: your-main-container-image
    lifecycle:
      preStop:
        exec:
          command: ["/bin/sh", "-c", "gracefully terminate logstash"]done"]
Rafał Leszko
  • 4,939
  • 10
  • 19
  • 2
    I believe it's not correct, as k8s doesn't trigger preStop hook when the container complete the work as expected - hook is triggered only when container is terminated: https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#container-hooks – jado Feb 04 '22 at 12:25