简体   繁体   English

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

[英]How to remote debug an application hosted in Azure K8s Cluster

Basic background基本背景

My Application is a Java application, My application is getting deployed in Azure cluster.我的应用程序是 Java 应用程序,我的应用程序正在部署在 Azure 集群中。 everything is good.万事皆安。 But I want to know how to connect Eclipse debugger with the application running in Azure cluster.但我想知道如何将 Eclipse 调试器与在 Azure 集群中运行的应用程序连接起来。

In the startup script, JPDA port is bind with 8000 and in dockerfile 8000 port is exposed.在启动脚本中, JPDA端口与 8000 绑定,在dockerfile中,暴露了8000端口。

The issue is how to connect eclipse debugger with code running in Azure cluster.问题是如何将 eclipse 调试器与在 Azure 集群中运行的代码连接起来。

I tried to put the IP address in Remote Java Application connection properties Host: but not a success.我尝试将IP地址放在Remote Java Application连接属性Host:但没有成功。

Need procedure, for remote debugging.需要程序,用于远程调试。

So after googling, I found one ninja technique.所以在谷歌搜索之后,我发现了一种忍者技术。 A technique we know as port-forwarding .一种我们称为port-forwarding的技术。

So basic idea is to forward a running application's port to our local system's available port.所以基本的想法是将正在运行的应用程序的端口转发到我们本地系统的可用端口。

So I found one command for port-forwarding:所以我找到了一个端口转发命令:

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

In this command, we need to know.在这个命令中,我们需要知道。 For this, we need to know running pods in Kubernetes cluster on Azure.为此,我们需要知道在 Azure 上的 Kubernetes 集群中运行的 pod。 It means we need to connect or authenticate your local machine CLI with Azure.这意味着我们需要使用 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从此链接下载 Azure CLI 并安装https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest

  • Now open PowerShell run command现在打开 PowerShell 运行命令

    az login

  • Your default browser will open add your Azure credentials and Authenticate, so your PowerShell will show you following message when your authentication is done.您的默认浏览器将打开添加您的 Azure 凭据并进行身份验证,因此您的PowerShell将在您的authentication完成后向您显示以下消息。

 
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": ""
    }
  }
]
  • Now next command to run is:现在下一个要运行的命令是:

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

  • Run Command to get running pods in a specific namespace if defined any.运行命令以获取特定命名空间中正在运行的 pod(如果已定义)。

    kubectl get pods -n <namespace>

  • Now you will have your running pods in specific namespace in Kubernetes cluster of Azure cloud.现在,您将在 Azure 云的 Kubernetes 集群中的特定命名空间中运行 pod。


NAME                         READY STATUS  RESTARTS    AGE

application-8664866df5-x4zns 2/2           Running 0   21m
  • Time to run our initial command.是时候运行我们的初始命令了。

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

  • In the cli you will see在 cli 你会看到


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

Might be confused why I use 6000 port, because, my 8000 port is already in use.可能会混淆我为什么使用 6000 端口,因为我的 8000 端口已经在使用中。

Time to connect with eclipse: Project Right-click > debug > debug configuration > search for Remote Java Application .是时候连接 eclipse:项目Right-click > debug > debug configuration > 搜索Remote Java Application

Set a name for the debugger like mine is debugCluster Host : 127.0.0.1 Port : 6000为我的调试器设置一个名称是debugCluster Host :127.0.0.1 Port :6000

Now Apply and Press Debug button in some time you will see your debugger is connected with Instance running in Azure cluster.现在应用并按下调试按钮一段时间后,您将看到您的调试器与在 Azure 集群中运行的实例连接。

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM