Reputation: 3187
In Kubernetes, there is an init container that can run before the main container starts running. Does Kubernetes, provide a "tear down" container so that I can signal other service the pod is going down?
Upvotes: 0
Views: 536
Reputation: 44637
No there is no concept of tear down container. You can have PreStop hook
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. A call to the preStop hook fails if the container is already in terminated or completed state. 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
Pod termination sequence is documented here
You have not provided details as to why other pods need to be notified when a pod is going down but if it's to avoid calling the pod which is going down from other pods then the failure, retry and backoff logic need to be implemented at client side. This is called circuit breaker pattern.
If you want to monitor a pod Kubernetes APIs can be used for that. Kubernetes provides watch for almost all of the resources including pod. This is the API called by kubectl watch
and you can call the REST API as well.
Upvotes: 2