Pretty much the title of the question.
I am working with an Ubuntu system that has a k8s deployment with multiple nodes and with multiple pods that run Docker containers. A few of the pods are nodeJS microservices which run the following command at initiation:
node app.js
Sometimes I need to debug the microservice by adding logs, changing logic inside, etc.
Working with the same microservices in Windows I could just change the source code and restart the node.exe
process. How would I achieve doing the same in Linux with a Kubernetes deployment?
I attempted to run a shell:
user@node1:~$ kubectl exec my-microservice-XXXX -it -- sh
Change source code and save:
nano app.js
Find the node
process:
ps aux
PID USER TIME COMMAND
1 root 0:00 npm
22 root 0:00 npm
42 root 0:27 node --max-http-header-size=65000 app.js
Then send SIGTERM
to PID 42
:
kill SIGTERM 42
And this results in me being booted out of the pod:
/usr/src/app # kill SIGTERM 42
sh: invalid number 'SIGTERM'
/usr/src/app # command terminated with exit code 137
test@node1:~$
And a new pod starts automatically:
my-microservice-XXXX 0/1 Completed 1 19h
my-microservice-XXXX 1/1 Running 2 19h
SIGTERM
is a default signal so you don't have to specify its type and you could actually use onlykill 42
. If you want to specify the type of the signal, you should use following syntax:kill -<signal> <pid>
,-s <signal>
or--signal <signal>
e.g.kill -SIGTERM 42
. – marioKubernetes
it isn't meant to be done like that. Rather than for debugging it should be used for running working images. And an image should be immutable i.e. if you change the code of your application, you're supposed to swap the old image with the new one which contains new code. It's just not the way you're supposed to use Kubernetes. See also answer provided by @Sagar Chilukuri. As he mentioned, application code should be the integral part of the image and shouldn't be stored in volumes. – mario