I'm using Kubernete to run a node script in a permanent loop. When the pod is created, it runs "npm start" which start the script with default parameters in loop mode. It works perfectly for that.
I also sometimes need to run some node commands in the pod.
(eg: node dist/index run --parameter=xyz)
For that I use kubectl :
kubectl exec -it PODNAME NAMESPACE -- /bin/ash
It allows me to run the script with other parameters as I wish BUT
I don't find a way to put the main process ('npm start') on hold while I run my others commands.
I want the loop to be paused while I execute those node commands (They can't run in parallel). I tried to kill the main processed which are shown by typing "ps -aef" but it doesn't work. It either restart automatically (restartPolicy: Always) or it make the pods go in error and I can't type my node commands.
Any idea on how to achieve this ?
What you could do is send a signal to the main process, SIGUSR2 is meant for this kind of purpose. You can catch the signal with an event handler and set a variable, then let your normal code check the variable at intervals or at set points in the code to judge wether it should do stuff.
On the CLI side of issuing the pause you can simply use the kill
command to send the signal to the process.
See also:
But, maybe you shouldn't try to pause a pod, simply gracefully let it shut down, and pick up remaining workloads later, in a new pod? Would probably be a cleaner way to go about it, but depends on what you're trying to achieve ofcourse.