Skip to content

Commit

Permalink
new blog post on remote debugging (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
HiranmayaGundu authored Jul 15, 2021
1 parent 221fefe commit 6f8ea43
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 4 deletions.
16 changes: 13 additions & 3 deletions pages/about.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,23 @@ Hi, I'm Hiranmaya Gundu. I'm a software developer from India, currently based in

<br />

I'm a recent graduate of PES University, and as of Jan 2020, have about a year of professional experience in the industry.
I currently work as a Full Stack engineer, and learnt professional JavaScript and Web Development on the job.
I'm an incoming graduate student at University of Southern California, and as of July 2021, have 2.5 years of
professional experience in the industry.

This website was born out of a desire to learn about React's server side rendering capabilities, as well as TypeScript.

<br />

I'm currently actively looking to further my education through a graduate program. I have a strong interest in the Systems fields.
## Work Experience

[MiQ Digital India](https://wearemiq.com) (Jun 2019 - Aug 2021)

_Software Engineer - II_

I was part of the team that built a workflow engine that was used by analysts internally. I helped build and maintain
a drag-and-drop workflow editor, built integrations with other services using both REST APIs as well as using a
cutsom Kafka based messaging system. I also helped contanierize and kuberntize the application, and built CI/CD
pipelines for it.

## Technical Skills

Expand Down
1 change: 0 additions & 1 deletion pages/posts/config-in-kube.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Mark from "components/Mark";
import Head from "components/Head";
import Callout from "components/Callout";

export const meta = {
published: true,
Expand Down
90 changes: 90 additions & 0 deletions pages/posts/debug-java-apps-kube.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import Mark from "components/Mark";
import Head from "components/Head";
import Callout from "components/Callout";

export const meta = {
published: true,
publishedAt: "2021-06-21",
title: "Remote debug Java Applications running on Kubernetes",
summary: "A guide to debugging Java applications running on Kubernetes",
};

<Head
title={meta.title}
description={meta.summary}
image="debug-java-kube-seo.png"
/>

## <Mark> Remote Debugging Java Applications in Kubernetes </Mark>

Recently, when implementing a feature in our application, I had a `NullPointerException` issue that would occur only on Kubernetes.
This issue was not reproducible on local, and was not reproducible running the docker container either. To debug this issue,
I had to set up a remote debugging session. These are the steps to setup this session:-

First, change the Java startup command by adding the jdb parameters.
In my applications case, it meant changing it from

```bash
java -cp ".:./conf/:./lib/\*" -noverify com.app.name
```

to

```bash
java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=_:5005 -cp ".:./conf/:./lib/_" -noverify com.app.name
```

<Callout>

Note that the exact parameters differ based on JDK version. The above example is valid for JDK 9 or higher.

</Callout>

At this point you have an application that has exposed a debug port on port 5005. If you run this application, the first printed
line would be: `Listening for transport dt_socket at address: 5005`. If this gets printed you know that the java application has
been correctly configured.

This application can now be deployed on K8S. We need to expose the 5005 port in the container section of our deployment so that it
is accessible from outside Kubernetes. In your `deployment.yaml` make the following
change to expose the port:

```yaml
spec:
template:
spec:
containers:
- name: java-app
ports:
- containerPort: 5005
name: "debug"
```
Kubectl provides us a port forward command to be able to access a pods port as if it were a local port.
To set this up do the following:
Get the name of the pod using the `get pods` command.

```bash
$ kubectl get pods -n app-namespace
NAME READY STATUS RESTARTS AGE
java-app-6c54c9b858-7bpbp 3/3 Running 1 6d2h
```

Then use the `kubectl port-forward` command to forward the 5005 port of the pod to your local machine.

```bash
$ kubectl port-forward java-app-6c54c9b858-7bpbp 5005:5005 -n app-namespace
# With this, the debug session should be available at localhost:5005.
```

Next, you need to setup the debug configuration in your favourite IDE. My preference is to use IntelliJ IDEA. In IDEA, the steps are as follows:

- From the main menu, select Run | Edit Configurations or press `⌃⌥R` then 0.
- In the Run/Debug Configurations dialog, click the Add New Configuration button and select Remote.
- Fill out the details for host as localhost and port and 5005. Make sure you select the correct JDK version.
- Save the configuration

<br />

With this configuration is saved you can click on the debug icon to debug
at any time!
Binary file added public/images/debug-java-kube-seo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

1 comment on commit 6f8ea43

@vercel
Copy link

@vercel vercel bot commented on 6f8ea43 Jul 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.