Ran Hassid
Ran Hassid

Reputation: 2788

Is it possible to debug a NodeJS app using Minikube via node-inspector?

I am running minikube on my mac for developing/testing my micro-services locally.

Is it possible to debug my NodeJS in minikube via node-inspector (other tools are also welcome)?

I saw that there is an option to use node-inspector using docker-compose but since I am running all my services in k8s I choose Minikube.

Upvotes: 0

Views: 577

Answers (1)

frankgreco
frankgreco

Reputation: 1516

Say you have this npm script:

"dev": "concurrently -p \"[{name}]\" -n \"NODE INSPECTOR,NODEMON\" -c \"bgBlue.bold,bgGreen.bold\" \"node-inspector --web-port=8081 --debug-port=5860 --preload\" \"cross-env NODE_ENV=development nodemon ./node_modules/babel-cli/bin/babel-node.js --max-old-space-size=512 --debug=5860 ./index.js\""

node-inspector is not running on port 8081.

Now in your kubernetes.yml you could have the following:

---

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  labels:
    app: helloworld
  name: helloworld
  namespace: application
spec:
  replicas: 1
  selector:
    matchLabels:
      app: helloworld
  template:
    metadata:
      labels:
        app: helloworld
    spec:
      containers:
      - name: helloworld
        imagePullPolicy: Always
        image: fbgrecojr/hello-world:latest
        ports:
        - containerPort: 8080
          protocol: TCP
        - containerPort: 8081
          protocol: TCP

---

kind: Service
apiVersion: v1
metadata:
  labels:
    app: helloworld
  name: helloworld
  namespace: application
spec:
  type: NodePort
  ports:
  - port: 8080
    protocol: TCP
    nodePort: 30000
  - port: 8081
    protocol: TCP
    nodePort: 30001
  selector:
    app: helloworld

your app is not accessible from $(minikube ip):30000 and node inspector is available from $(minikube ip):30000

Upvotes: 0

Related Questions