How to terminate another container in the same pod when your main container finish its job

3/12/2020

Using OpenShift 3.9, I run a daily CronJob that consists of 2 containers:

  1. A Redis server
  2. A Python script that uses the Redis server

When the python script finishes its execution, the container is terminated normally but the Redis server container stays up.

Is there a way to tell the Redis server container to automatically terminate its execution when the python script exit? Is there an equivalent to the depends_on of docker compose?

-- jfpatenaude
kubernetes
openshift

1 Answer

3/12/2020

Based on Dawid Kruk comment, I added this line at the end of my python script to shutdown the server:

os.system('redis-cli shutdown NOSAVE')

It effectively terminate the container.

-- jfpatenaude
Source: StackOverflow