I want to call a script internal to my pod with a pre-delete hook. With the kubernetes hooks it seems like these are executed inside the actual pod, however from what I can tell, in helm these scripts are run in a separate pod, so they will be unable to interact with any processes running in my pod.
Is there a way to call a script internal to the pod being deleted like kubernetes does with helm?
>Solution :
Helm doesn’t have this capability. A Helm hook always creates a new resource, at some specific point in the install/upgrade/delete life cycle, and this is frequently a Job; that means the new Job will create a new Pod. Helm can’t do kubectl exec or otherwise run imperative commands.
In general, "run a command in a container" isn’t a typical workflow, and you should design your application and deployment to avoid this. As one example, in Kubernetes you can very easily run multiple replicas of a Deployment, and you often will want to run more than one of everything just for basic redundancy. Now, if your shutdown hook needs to run a command in a Pod, which one does it do, and what happens to the other two? If it doesn’t matter which one, then launching a dedicated Job to do the cleanup should work fine as well. If every Pod needs to run it, then putting a shutdown hook in your application will be more reliable and work even in non-Kubernetes contexts.