How to run `args` as `command` in kubernetes How to run `args` as `command` in kubernetes kubernetes kubernetes

How to run `args` as `command` in kubernetes


You are using Container Lifecycle Hooks, to be more specific PreStop.

This hook is called immediately before a container is terminated due to an API request or management event such as liveness probe failure, preemption, resource contention and others.

If you want to execute a command when pod is starting you should consider using PostStart.

This hook executes immediately after a container is created. However, there is no guarantee that the hook will execute before the container ENTRYPOINT. No parameters are passed to the handler.

Another option would be using Init Containers, and here are few ideas with examples:

  • Wait for a Service to be created, using a shell one-line command like:
 for i in {1..100}; do sleep 1; if dig myservice; then exit 0; fi; done; exit 1
  • Register this Pod with a remote server from the downward API with a command like:
curl -X POST http://$MANAGEMENT_SERVICE_HOST:$MANAGEMENT_SERVICE_PORT/register -d >'instance=$(<POD_NAME>)&ip=$(<POD_IP>)'
  • Wait for some time before starting the app container with a command like
sleep 60

Please read the documentation on how to use Init containers for more details.


My end goal was to run tls_generator.py right after the load command has completed. This is what I came with and is working fine.

  command: ["/bin/sh", "-c"]  args: ["tini -g -- /app/scripts/entrypoint.sh load && /usr/bin/python               /scripts/tls_generator.py"]

In this case the default command when running "tini -g -- /app/scripts/entrypoint.sh" will be the --help command. But adding load passes it as a command.