how to connect chrome debugger to kubernetes pod

4/26/2018

I need to debug (with chrome://inspect/ debugger) my nodejs app while it is deployed in a kubernetes pod. I tried adding a port to the service in front of the deployment but this is not working.

I added the port 42126

apiVersion: v1
kind: Service
metadata:
  name: account-service # matches name in nginx.conf 
spec:
  ports:
  - name: traffic
    port: 80
    targetPort: 80
  - name: debug
    port: 42126
    targetPort: 42126
  type: NodePort # speculating need this so nginx can route to this ???????
  selector:
    app: account-pod # matches name of pod created by deployment account-deployment

The deployment is not modified

apiVersion: apps/v1beta2 # for version 1.8, once 1.9 switch to apps/v1
kind: Deployment
metadata:
  name: account-deployment # name of the deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: account-pod # matches name of pod to create
  template:
    metadata:
      labels:
        app: account-pod # name of pod, matches deployment and service definition
    spec:
      containers:
      - name: account-container # name of docker container
        image: us.gcr.io/purple01-0000000/purple_account:2018_04_25_18_08

The docker image is created with the following. I know this works since I use it for debugging locally when running docker compose with all my modules.

FROM node:9.4
WORKDIR /app

COPY . /app/
RUN npm install

# comment out normal mode and created one for the debug
#CMD node ./bin/www  
CMD node --inspect-brk=0.0.0.0:42126 ./bin/www

EXPOSE 80 42126

The configured ingress send the http traffic to an nginx service that serves static files and routes to various micro services.

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: basic-ingress
  annotations: 
    kubernetes.io/ingress.global-static-ip-name: ingress-ip 
spec:
  tls:
  - secretName: tls-secret
  backend:
    serviceName: purple-front-end-service 
    servicePort: 80

I am new to kubernetes, so any advice is appreciated.

One of the many things I don't get: ingress terminates https and sends the http to my purple-front-end-service (a nginx service). How is port 42126 on the account-service made available to the outside so I can connect to it via chrome?

What do I configure in the "Target discovery settings" for "chrome://inspect/#devices".

-- grabbag
google-kubernetes-engine
kubernetes

1 Answer

4/26/2018

in the Dockerfile that creates your application, enable debugging (see line CMD)

FROM node:9.4
WORKDIR /app
COPY ./app.js /app/app.js
COPY ./package.json /app/package.json
RUN npm install
CMD node --inspect-brk=0.0.0.0:42132 ./bin/www

Using the "Google Cloud Platform" website Kubernetes Engine / Workloads / Select the deployment from the displayed list to show details. Scroll down to "Managed pods" and note the name.

In the detail section of the service there is a "port forwarding" button that reveals the command. enter image description here

On your desktop, run the command using the pods name and port # you want to use. kubectl port-forward account-deployment-85f7dcf65b-v27zx 8080:42126

-- grabbag
Source: StackOverflow