Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rajkrrsingh/15154fb16a9200402a85de431df76203 to your computer and use it in GitHub Desktop.
Save rajkrrsingh/15154fb16a9200402a85de431df76203 to your computer and use it in GitHub Desktop.
Remote Debug Java Application running on Kubernetes Cluster

Following steps can be used to debug java application running on Remote Cluster, for sake of similicity I am using bare minimum pod config to spin the HS2 pod on the cluster.

  1. Build a docker image as per https://gist.github.com/rajkrrsingh/e2a5d02a3a895c7f7e8f1d6d0e71e0e9, The image push the debug config -agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n to the JVM opts, the same can be achieved through the ConfigMap descriptor.

  2. Create HS2 Deployments

apiVersion: apps/v1
kind: Deployment
metadata:
  name: hs2
  namespace: default
  labels:
    app: hs2
spec:
  replicas: 1
  selector:
    matchLabels:
      app: hs2
  template:
      metadata:
        labels:
          app: hs2
      spec:
        containers:
          - name: hs2
            image: rajkrrsingh/hive3-image-debug:latest
            imagePullPolicy: Always
            ports:
              - containerPort: 10000
                name: binary

  1. port forwards
// JDBC endpoint
kubectl port-forward --address 0.0.0.0  hs2-5d6d47b5bd-d86tm 10000:10000
// Debugger endpoint
kubectl port-forward --address 0.0.0.0  hs2-5d6d47b5bd-d86tm 8000:8000
  1. Now though IDE you can connect the debugger to Kubernetes node on port 8000 and start debugging.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment