title: How to debug a nodeJS application inside a Kubernetes Pod?
body: <p>Pretty much the title of the question.</p>
  
  <p>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:</p>
  
  <p><code>node app.js</code></p>
  
  <p>Sometimes I need to debug the microservice by adding logs, changing logic inside, etc.  </p>
  
  <p>Working with the same microservices in Windows I could just change the source code and restart the <code>node.exe</code> process. How would I achieve doing the same in Linux with a Kubernetes deployment?</p>
  
  <p>I attempted to run a shell:</p>
  
  <p><code>user@node1:~$ kubectl exec my-microservice-XXXX -it -- sh</code></p>
  
  <p>Change source code and save:
  <code>nano app.js</code></p>
  
  <p>Find the <code>node</code> process:
  <code>ps aux</code></p>
  
  <pre><code>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
  </code></pre>
  
  <p>Then send <code>SIGTERM</code> to <code>PID 42</code>:</p>
  
  <p><code>kill SIGTERM 42</code></p>
  
  <p>And this results in me being booted out of the pod:</p>
  
  <pre><code>/usr/src/app # kill SIGTERM 42
  sh: invalid number 'SIGTERM'
  /usr/src/app # command terminated with exit code 137
  test@node1:~$
  </code></pre>
  
  <p>And a new pod starts automatically:</p>
  
  <pre><code>my-microservice-XXXX                       0/1     Completed   1          19h
  my-microservice-XXXX                       1/1     Running     2          19h
  </code></pre>