<p><strong>Basic background</strong></p>

<p>My Application is a Java application, My application is getting deployed in Azure cluster.
everything is good. But I want to know how to connect Eclipse debugger with the application running in Azure cluster.</p>

<p>In the startup script, <code>JPDA</code> port is bind with 8000 and in <code>dockerfile</code> <code>8000</code> port is exposed.</p>

<p>The issue is how to connect eclipse debugger with code running in Azure cluster.</p>

<blockquote>
  <p>I tried to put the IP address in <code>Remote Java Application</code> connection properties <code>Host:</code> but not a success.</p>
</blockquote>

<p>Need procedure, for remote debugging.</p>

Dupinder Singh
<p>So after googling, I found one ninja technique 🤣🤣. A technique we know as <code>port-forwarding</code>.</p>

<p>So basic idea is to forward a running application's port to our local system's available port.</p>

<p>So I found one command for port-forwarding:</p>

<blockquote>
  <p><code>kubectl port-forward pods/&lt;podName&gt; 8000:8000 -n &lt;namespace&gt;</code></p>
</blockquote>

<p>In this command, we need to know . For this, we need to know running pods in Kubernetes cluster on Azure. It means we need to connect or authenticate your local machine CLI with Azure.</p>

<blockquote>
  <p>Download Azure CLI from this link and Install
  <a href="https://learn.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest" rel="nofollow noreferrer">https://learn.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest</a></p>
</blockquote>

<ul>
<li><p>Now open PowerShell run command</p>

<blockquote>
  <p><code>az login</code></p>
</blockquote></li>
<li><p>Your default browser will open add your Azure credentials and Authenticate, so your <code>PowerShell</code> will show you following message when your <code>authentication</code> is done.</p></li>
</ul>

<pre> <code>
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": ""
    }
  }
]
</code></pre>

<ul>
<li><p>Now next command to run is:</p>

<blockquote>
  <p><code>az aks get-credentials --resource-group &lt;ResourseGroupName&gt; --name &lt;Name of Kubernetes cluster&gt;</code></p>
</blockquote></li>
<li><p>Run Command to get running pods in a specific namespace if defined any.</p>

<blockquote>
  <p><code>kubectl get pods -n &lt;namespace&gt;</code></p>
</blockquote></li>
<li><p>Now you will have your running pods in specific namespace in Kubernetes cluster of Azure cloud.</p></li>
</ul>

<pre><code>
NAME                         READY STATUS  RESTARTS    AGE

application-8664866df5-x4zns 2/2           Running 0   21m
</code></pre>

<ul>
<li><p>Time to run our initial command.</p>

<blockquote>
  <p><code>kubectl port-forward pods/&lt;application-8664866df5-x4zns&gt; 6000:8000 -n myNameSpace</code></p>
</blockquote></li>
<li><p>In the cli you will see </p></li>
</ul>

<pre><code>
Forwarding from 127.0.0.1:6000 -> 8000
Forwarding from [::1]:6000 -> 8000
</code></pre>

<p>Might be confused why I use 6000 port, because, my 8000  port is already in use.</p>

<p>Time to connect with eclipse:
Project <code>Right-click</code> > <code>debug</code> > <code>debug configuration</code> > search for <code>Remote Java Application</code>.</p>

<p>Set a name for the debugger like mine is <strong>debugCluster</strong> 
<code>Host</code>: 127.0.0.1 
<code>Port</code>: 6000</p>

<p>Now Apply and Press Debug button in some time you will see your debugger is connected with Instance running in Azure cluster.</p>

<p><a href="https://i.stack.imgur.com/yIq5b.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yIq5b.png" alt="enter image description here"></a></p>
