如何将chrome调试器连接到kubernetes pod

时间:2018-04-26 01:38:43

标签: kubernetes google-kubernetes-engine

我需要调试(使用chrome:// inspect / debugger)我的nodejs app,当它部署在kubernetes pod中时。我尝试在部署前向服务添加端口,但这不起作用。

我添加了端口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

未修改部署

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

使用以下内容创建泊坞窗图像。我知道这很有效,因为我在使用所有模块运行docker compose时用它进行本地调试。

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

配置的入口将http流量发送到nginx服务 提供静态文件和路由到各种微服务。

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

我是kubernetes的新手,所以任何建议都表示赞赏。

我没有得到的许多东西之一:ingress终止https并将http发送到我的紫色前端服务(nginx服务)。如何将帐户服务上的端口42126提供给外部,以便我可以通过chrome连接到它?

我在“chrome:// inspect /#devices”的“目标发现设置”中配置了什么。

1 个答案:

答案 0 :(得分:1)

在创建应用程序的Dockerfile中,启用调试(参见行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

使用" Google Cloud Platform"网站 Kubernetes发动机/工作负载/ 从显示的列表中选择部署以显示详细信息。 向下滚动到"托管窗格"并记下名字。

在服务的详细信息部分,有一个"端口转发"显示命令的按钮。 enter image description here

在桌面上,使用要使用的pod名称和端口#运行命令。     kubectl port-forward account-deployment-85f7dcf65b-v27zx 8080:42126