Search code examples
dockerdebuggingkubernetesremote-debuggingkind

Debugging NodeJs app running inside pod on Kind (Kubernetes in docker) cluster


I am running a kubernetes cluster with Kind configured as shown bellow:

kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
  - role: control-plane
    kubeadmConfigPatches:
      - |
        kind: InitConfiguration
        nodeRegistration:
          kubeletExtraArgs:
            node-labels: "ingress-ready=true"
    extraPortMappings:
      - containerPort: 80
        hostPort: ${ingress_http_port}
        protocol: TCP
      - containerPort: 443
        hostPort: ${ingress_https_port}
        protocol: TCP
networking:
  kubeProxyMode: "ipvs"

The cluster is running inside the kind-control-plane docker container:

CONTAINER ID   IMAGE                  COMMAND                  CREATED        STATUS       PORTS                                                                 NAMES
53d9511b8282   kindest/node:v1.21.1   "/usr/local/bin/entr…"   5 hours ago    Up 5 hours   0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp, 127.0.0.1:41393->6443/tcp   kind-control-plane

I have also successfully deployed a deployment running a nodeJs application inside a pod and i have already exposed a service to access the app through an ingress controller and everything works as expected:

apiVersion: v1
kind: Service
metadata:
  name: application-deployment
spec:
  ports:
    - name: http
      port: 3000
      protocol: TCP
  selector:
    app: application-deployment
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: application-deployment
spec:
  rules:
    - http:
        paths:
          - path: "/"
            pathType: Prefix
            backend:
              service:
                name: application-deployment
                port:
                  number: 3000

I am using the WebStorm IDE to develop the application running inside the pod and i am trying to configure a remote debugger to connect to the application inside the Kind cluster. I know how to configure a debugger running inside a docker container but i dont know how to run a debugger inside a kubernetes pod running in a docker container.

I have already tried to configure it through WebStrom with the settings bellow:

enter image description here

And these are the settings under the Docker container settings label:

enter image description here

Any suggestions or workarounds in order to accomplish this would be more than appreciated.

Thank you in advance!


Solution

  • Finally I managed to connect the remote debugger by following the steps described bellow:

    1. Start the node process inside the pod with the --inspect-brk arg in order to be able to attach a debugger. (E.g. node --inspect-brk --loader ts-node/esm src/server.ts)
    2. Then I forwarded the debug port from the pod to my local computer by running the command kubectl port-forward deploy/application-deployment 9229:9229
    3. Finally I created an Attach to Node.js/Chrome run/debug configuration on WebStorm instead of the Node.js configuration as I tried on the beginning and everything worked like a charm.

    This linked helped me configure the described solution.