Prepare the docker image
为了调试Java应用程序,我们需要向远程应用程序添加一些命令行参数。
- Set the arguments in the kubernetes deployment payload
DEBUG_OPTIONS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005"
- Pass it to the java command in Dockerfile
ENTRYPOINT [ "sh", "-c", "java $DEBUG_OPTIONS -jar app.jar" ]
Expose the port 5005 in the GKE service
In GCP console, go to Kubernetes Engine -> Service & Ingress, choose your service and add the debug port:
ports:- name: httpnodePort: 30060port: 80protocol: TCPtargetPort: 8080- name: debugnodePort: 30080port: 5005protocol: TCPtargetPort: 5005
Forward the pods ports to your localhost:5005
gcloud container clusters get-credentials ${CLUSTER_NAME} --region us-central1 --project ${PROJECT_NAME} \&& kubectl port-forward --namespace ${NAMESPACE} $(kubectl get pod --namespace ${NAMESPACE} --selector="app=${APP}" --output jsonpath='{.items[0].metadata.name}') 5005:5005
您可以通过点击调试端口附近的“端口转发”按钮,从Google控制台生成此命令:
And now debug it as usual from Intelij