0

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!

3
  • 2
    Particularly running inside kind, the pod is fairly detached from the actual host system: it's running inside its own isolated filesystem, hidden inside a nested Docker daemon, inside a Docker container that doesn't by default have access to the host. There are tools like Telepresence or Skaffold that are designed to simplify this development sequence; but maybe it would be easier to develop and test your application in a local Node installation, outside a Kubernetes cluster? Commented Feb 18, 2022 at 14:52
  • 1
    There's a good article which may be helpful for you - Easily Debug Java Microservices Running on Kubernetes with IntelliJ IDEA. It also has options for local development like exposing a nodeport or using kubectl port-forward which are good options for testing. Commented Feb 21, 2022 at 9:01
  • Thank you for your responses! I appreciate that! I managed to start a remote debugger by starting an ssh server on the pod and then connecting through it. Although every time i run the debugger i have to wait about 4-5 minutes for a procedure copying the node_modules!! I dont get why this is happening, and how i can avoid it. Commented Feb 21, 2022 at 9:05

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.