unable to remote-debug a pod with vscode?

5/21/2021

I am having trouble while debugging the remote spring-boot application using vscode IDE.( I am not using any docker file in development as i am using the jib-maven plugin with skaffold to deploy on k8s. I assume this should cause any issue )

Below is the snapshot for k8s yaml file ( i have deleted few parts and replaced it with dot)

apiVersion: v1
kind: Service
metadata:
  annotations:
    .
	.
	.
	.
	.
	.
	.
	.
	
  name: ABC-service
spec:
  ports:
    - name: http
      port: 8080
      targetPort: 8080
    - name: grpc
      port: 50051
      targetPort: 50051  
  selector:
    app: ABC-service
  type: ClusterIP
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: ABC-service
spec:
  replicas: 1
  selector:
    matchLabels:
      app: ABC-service
  template:
    metadata:
      labels:
        app: ABC-service
    spec:
      containers:
              - ports:
                  - containerPort: 8080
                  - containerPort: 50051
                  - containerPort: 50005
                env:
                  - name: SECURESTORE_SVC_HOST
                    value: securestore-svc
                  - name: SECURESTORE_SVC_PORT
                    value: "50051"
                  - name: IAM_SVC_HOST
                    value: iam-service-svc
                  - name: IAM_SVC_PORT
                    value: "50051"
                name: ABC-service
                imagePullPolicy: Always
                image: ABC/ABC-service
      imagePullSecrets:
        - name: ABC-dev 

Once my service is deployed , I perform below steps to debug

  1. Executing the command in terminal
kubectl port-forward ABC-service-c59667c89-z5pzp 8080:8080
  1. Now my service is accessible via localhost:8080/Hello
  2. Afterwards when i try to connect my vscode debugger on port 8080 using following launch.json configuration
        {
            "type": "java",
            "name": "Debug (Attach)",
            "projectName": "MyApplication",
            "request": "attach",
            "hostName": "localhost",
            "port": 8080
        }

here debugger keeps waiting to connect but never gets attached and eventually times out. I followed many tutorials but not sure what I am messing up.

-- Jim
java
kubernetes
remote-debugging
spring-boot
visual-studio-code

1 Answer

5/21/2021

In launch.json, add

"console": "internalConsole",

Try this and see if question goes away.

-- Molly Wang-MSFT
Source: StackOverflow