如何远程调试托管在 Azure K8s 集群中的应用程序

How to remote debug an application hosted in Azure K8s Cluster

基本背景

我的应用程序是一个 Java 应用程序,我的应用程序正在部署到 Azure 集群中。 万事皆安。但我想知道如何将 Eclipse 调试器与 Azure 集群中的应用程序 运行 连接。

在启动脚本中,JPDA 端口与 8000 绑定,在 dockerfile8000 端口被公开。

问题是如何在 Azure 集群中使用代码 运行 连接 eclipse 调试器。

I tried to put the IP address in Remote Java Application connection properties Host: but not a success.

需要程序,用于远程调试。

所以在谷歌搜索之后,我发现了一种忍者技术。我们称为 port-forwarding.

的技术

所以基本思想是将 运行ning 应用程序的端口转发到我们本地系统的可用端口。

所以我找到了一个用于端口转发的命令:

kubectl port-forward pods/<podName> 8000:8000 -n <namespace>

在这个命令中,我们需要知道。为此,我们需要了解 Azure 上的 Kubernetes 集群中的 运行ning pods。这意味着我们需要使用 Azure 连接或验证您的本地计算机 CLI。

Download Azure CLI from this link and Install https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest

  • 现在打开 PowerShell 运行 命令

    az login

  • 您的默认浏览器将打开添加您的 Azure 凭据并进行身份验证,因此当您的 authentication 完成后,您的 PowerShell 将显示以下消息。

 
C:\Users\MachineName> az login
You have logged in. Now let us find all the subscriptions to which you have access...

[
  {
    "cloudName": "",
    "id": "",
    "isDefault": true,
    "name": "",
    "state": "Enabled",
    "user": {
      "name": "",
      "type": ""
    }
  }
]
  • 现在 运行 的下一个命令是:

    az aks get-credentials --resource-group <ResourseGroupName> --name <Name of Kubernetes cluster>

  • 运行 命令在特定命名空间中获取 运行ning pods(如果已定义)。

    kubectl get pods -n <namespace>

  • 现在您将在 Azure 云的 Kubernetes 集群中的特定命名空间中拥有您的 运行ning pods。


NAME                         READY STATUS  RESTARTS    AGE

application-8664866df5-x4zns 2/2           Running 0   21m
  • 是时候 运行 我们的初始命令了。

    kubectl port-forward pods/<application-8664866df5-x4zns> 6000:8000 -n myNameSpace

  • 在命令行中你会看到


Forwarding from 127.0.0.1:6000 -> 8000
Forwarding from [::1]:6000 -> 8000

可能会混淆为什么我使用 6000 端口,因为,我的 8000 端口已被使用。

连接 Eclipse 的时间: 项目 Right-click > debug > debug configuration > 搜索 Remote Java Application.

为调试器设置一个名称,比如我的是 debugCluster Host: 127.0.0.1 Port: 6000

现在应用并按下调试按钮,一段时间后您将看到调试器与 Azure 集群中的实例 运行ning 连接。