Alex Flint
Alex Flint

Reputation: 6706

equivalent of init containers that runs after termination

Is it possible to create a pod that will run a container after the main container terminates? I am imagining something similar to an init container, except that runs at the end rather than at the beginning. (I would use this to look for various metadata files created by the main process and send them to our data warehouse)

Upvotes: 3

Views: 1723

Answers (1)

Jose Armesto
Jose Armesto

Reputation: 13749

No, there is not AFAIK. You would have to use pods hooks for that. You can read about pod hooks on this post

enter image description here

As explained on Kubernetes documentation, containers can access a hook by implementing and registering a handler for that hook. There are two types of hook handlers that can be implemented for Containers:

Exec - Executes a specific command, such as pre-stop.sh, inside the cgroups and namespaces of the Container. Resources consumed by the command are counted against the Container. HTTP - Executes an HTTP request against a specific endpoint on the Container.

For your use case, I'd use the pre-stop hook to execute a command inside the container and look for those metadata files.

This hook is called immediately before a container is terminated. It is blocking, meaning it is synchronous, so it must complete before the call to delete the container can be sent. No parameters are passed to the handler.

Upvotes: 8

Related Questions