The Wayback Machine - https://web.archive.org/web/20240930215901/https://www.geeksforgeeks.org/enable-remote-debugging-for-java-application-deployed-in-kubernetes-environment/
Open In App

Enable Remote Debugging For Java Application Deployed in Kubernetes Environment

Last Updated : 30 Mar, 2023
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

During Development, developers have to debug their applications to resolve code problems. In order to debug a java application which is deployed on remote machine in a Kubernetes cluster, first developer has to do some steps to enable its application ready for debugging. Below are the manual steps to enable remote debugging for any java application running as a container in Kubernetes environment.

Step by Step Implementation

Step 1: Edit the deployment. Let’s say deployment name is “my-app”.

kubectl edit deployment my-app

Step 2: Add the java options (JAVA_OPTS )and its value for enabling debugging as a variable in “env” section in the deployment as follows:

– name: JAVA_OPTS

value: “-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=9991”

After saving the changes to the deployment, Kubernetes will automatically redeploy all the pods with the new changes.

Step 3: Create a debug service for your application. Let’s say you have named it as “my-app-debug-svc.yaml”  or change the existing service yaml file if present. Refer below sample service yaml file, do the highlighted changes in your service yaml file. Adding nodePort enables outside application (here your IDE) to access containers deployed in Kubernetes Cluster.

apiVersion: v1

kind: Service

metadata:

 name: my-app-debug-svc

 namespace: <namespace>

 labels:

   service: my-app-debug

   release: “1.0”

spec:

 type: NodePort

 ports:

   – port: 9991

     nodePort: 9991

     protocol: TCP

     name: debug-port

 selector:

   app: my-app

   service: my-app-debug

   release: “1.0”

Step 4: Start the debug service using below command. 

Kubectl create -f my-app-debug-svc.yaml

Step 5: Edit configuration in your IDE to do remote debugging. Here are the steps to edit configuration in IntelliJ IDE:

  • Open your codebase in InteliiJ IDE.
  • Go to Edit Configuration:
  • Click on + sign and select Remote. Give any name for your remote-debugging configuration. For say,  my-debug. Give Host name and port of the server machine where application is running which you want to debug. “Command line arg for remote jvm” field value will be automatically populated. Click Apply and then OK.

IntelliJ Remote Debug Edit Configuration

  • Set the breakpoints.
  • Click on debug icon.
  • Check the console. It should say “Connected to the target VM, address: ‘<hostname>:<portnumber>’, transport: ‘socket'”.

IntelliJ Console: Connected to VM: Ready for Debugging.

That’s all you are ready to debug your Java Application remotely!


Previous Article
Next Article

Similar Reads

How to Enable JMX For Java Application Running in the Kubernetes Cluster?
Many times we want to monitor our application's CPU utilization, background thread behavior, and most importantly memory consumptions for tasks that deal with loads for data (500MB - 1GB) or much more data. Such monitoring helps to find which operation is causing heavy CPU or Memory utilization and helps to find the reason behind Memory leak issues
3 min read
Kubernetes - Monolithic Architecture of Kubernetes
There is a new way of developing software apps using a microservices architecture. That's when all the buzz around containers and container orchestration has increased but we have been developing and using these large software apps even before most of us were born. So in this article, we will be discussing what is that old software architecture we
7 min read
Why Kubernetes? Benefits of using Kubernetes
The popularity of container orchestration technologies specially Kubernetes comes from its use cases and the problems that it solves. Kubernetes is the most popular container orchestration and is widely used by Cloud Native Computing Foundation (CNCF), the foundation to which Kubernetes as a project was donated by Google, estimates that about 92% b
8 min read
Kubernetes Controller VS Kubernetes Operator
Kubernetes Controllers are ideal for managing stateless apps and maintaining the correct number of copies, but Kubernetes Operators are more appropriate for complicated, stateful applications that require human-like decision-making abilities. Kubernetes ControllerKubernetes Controllers are ideal for managing stateless apps and maintaining the corre
4 min read
Java Application Deployment In Kubernetes With Jenkins CI/CD Pipeline
In modern software development, deploying applications to Kubernetes clusters has become a common practice due to their scalability and reliability. Automating this deployment process using continuous integration and continuous deployment (CI/CD) pipelines with Jenkins streamlines the development workflow and ensures consistent, reliable deployment
5 min read
How to Deploy Java Application in Kubernetes?
Kubernetes is a platform for automating deployment, scaling, and management of containerized applications. Pods are basic units that hold one or more containers. Deployments manage application deployment and updates. Services provide stable endpoints for accessing pods. Ingress manages external access to services. Together, they streamline applicat
6 min read
Top 5 Java Debugging Tips
Debugging is the process of finding and fixing errors or bugs in the source code of any software. When software does not work as expected, computer programmers study the code to determine why any errors occurred. Here, we are going to discuss the Java Debugging tips with proper examples. Top 5 Java Debugging Tips Debugging is a critical part of the
4 min read
Deploying a React Application in Kubernetes
Kubernetes is an open-source free manager for your computer program. These programs can be in the containers. Each container holds a program and everything it needs to run. To Keep track of all these containers that contain your application this is where the Kubernetes role comes in. Kubernetes does this for us. It can automate, scale, and manage t
5 min read
Deploying A Node.js Application In kubernetes
Kubernetes, or K8s, is an open-sourced container orchestration technology that is used to automate the manual processes of deploying, managing, and scaling applications with the help of containers. Kubernetes was originally developed by engineers at Google, and In 2015, it was donated to CNCF (Cloud Native Computing Foundation). In this tutorial, w
9 min read
How To Deploy PHP Application On Kubernetes ?
Prologue to deploying a PHP applications on Kubernetes starts with understanding the containerization, where applications and their libraries are packaged into convenient, lightweight containers. Docker is generally utilized for this reason. Kubernetes then deals with these containers, abstracting away basic infrastructure complexities. To begin, y
9 min read
How to Deploy Node.js Application in Kubernetes?
Deploying the Node.js application on Kubernetes in a containerized manner makes it highly scalable, and fault-tolerant, and allows zero downtime. Kubernetes allows container orchestration that can be used in many ways during deployment. Load balancing is provided, which helps with automatic load transfer to multiple pods. So getting all these benef
4 min read
How to Deploy Spring Boot Application in Kubernetes ?
The Spring Boot framework provides an assortment of pre-configured templates and tools to make the development of Java-based applications simpler. With little configuration, it enables developers to quickly design production-ready, stand-alone apps. Kubernetes, commonly referred to as K8s, is an open-source platform meant to automate the deployment
7 min read
How to Deploy a Django Application in Kubernetes
In this article, we will study how we can deploy Django web applications to Kubernetes. We will also see how to dockerize and build an image of the Django application using Dockerfile. For this article, you should know about setting up a VM in Azure. We will see how to deploy applications on Linux Server. Introduction to DjangoDjango is a Python fr
5 min read
Spring Boot Application Deployment in Kubernetes with Jenkins CI/CD Pipeline
As we know in the modern world we use Continuous Integration and Continuous Deployment for fast and and efficient delivery of our application to the market. Here in this Article, we are deep-diving into how we can actually deploy Spring boot applications on Kubernetes with the help of Jenkins CI/CD. Project WorkFlow.java files: These files contain
14 min read
Step-by-Step Guide to Access Application Logs in Kubernetes Pods
In a Kubernetes environment monitoring application logs is essential for debugging performance tuning and maintaining the overall health of our application. The Kubernetes pods which are the smallest deployable units in Kubernetes can generate logs that provide valuable insights inside them. In this article we explain about process of accessing the
5 min read
Node.Js Application Deployment in Kubernetes with Jenkins CI/CD Pipeline
As we know in the modern world we use Continuous Integration and Continuous Deployment for fast and and efficient delivery of our application to the market. Here in this Article, we are deep-diving into how Actually we can deploy Nodejs applications on Kubernetes with the help of Jenkins CI/CD. Primary TerminologiesNode.js: This is a free, open-sou
9 min read
Debugging with Stetho in Android
Stetho is an open-source debug library developed by Facebook. It allows you to use chrome debugging tools to troubleshoot network traffic., thus it provides a rich, interactive debugging experience for android developers. Stetho easily and smoothly debug network calls. It is a Sophisticated Debug Bridge for Android Applications. When enabled, devel
4 min read
Servlet - Debugging
One of the most difficult components of building servlets is testing and debugging. Because servlets include a lot of client/server interaction, they're prone to errors–though they're hard to come by. Because servlets operate inside a strongly multithreaded and typically complicated web server, they don't function well with ordinary debuggers, it m
5 min read
Remote Method Invocation in Java
Note:java.rmi package: Remote Method Invocation (RMI) has been deprecated in Java 9 and later versions, in favor of other remote communication mechanisms like web services or Remote Procedure Calls (RPC). Remote Method Invocation (RMI) is an API that allows an object to invoke a method on an object that exists in another address space, which could
5 min read
Setting up Java Competitive Programming Environment
An operating system is required to be installed on your system. here we will be discussing the setup in windows. However, you can choose any operating system. Install JDK (Java Development Kit) JDK, is a program that allows you to write Java code from the comfort of your desktop. It contains a variety of tools that are very useful for creating, run
5 min read
How to Setup IntelliJ IDEA For Java Competitive Programming Environment?
IntelliJ IDEA is a popular Integrated Development Environment (IDE) used by many developers for Java programming. In this article, we'll walk through the steps to set up IntelliJ IDEA for competitive programming. Competitive programming is a popular activity among computer science students and professionals, as it provides an opportunity to test th
4 min read
Environment Variables in Java
In Java, Environment variables are widely used by operating systems to deliver configuration data to applications. Environment variables are key/value pairs with both the key and the value being strings, similar to properties in the Java platform. What are Environment Variables in Java?In Java, Environment variables are values that are stored outsi
5 min read
Setting up the environment in Java
Java is a general-purpose computer programming language that is concurrent, class-based, object-oriented, etc. Java applications are typically compiled to bytecode that can run on any Java virtual machine (JVM) regardless of computer architecture. The latest version is Java 22. Below are the environment settings for both Linux and Windows. JVM, JRE
6 min read
Web Browsers that support Java Applets and how to enable them
Pre-requisite: Java Tutorials This article is about the support of Java on browsers. Why we need the support of Java on a browser? If you learned or have some knowledge or have worked in Java then it is likely that you must have come across this concept of Java Applet. So, an Applet is nothing but a Java program but the only difference is that it c
2 min read
Spring Boot - application.yml/application.yaml File
Spring is widely used for creating scalable applications. For web applications Spring provides. In Spring Boot, whenever we create a new Spring Boot Application in spring starter, or inside an IDE (Eclipse or STS) a file is located inside the src/main/resources folder named as application.properties file which is shown in the below media: So in a s
4 min read
Fetching Updates From a Remote Repository Using JGit
JGit is a lightweight Java library that can be implemented for Git version control systems. It allows developers to perform Git operations programmatically within Java applications. One of the essential tasks in Git is fetching updates from a remote repository, ensuring that the local repository stays in sync with the remote repository. This articl
3 min read
Pushing changes to a remote repository with JGit
JGit is the lightweight and pure Java library implementing the Git version control system. It can allow the developers to perform Git operations programmatically with Java applications. This article will guide you how to push the changes to a remote repository using JGit in the Maven project. PrerequisitesBasic knowledge of Java and Git. JDK is ins
3 min read
Environment setup for JSP
The environment setup for JSP mainly consists of 3 steps: Setting up the JDK. Setting up the webserver (Tomcat). Starting tomcat server. All the steps are discussed in details below: Setting up Java Development Kit : Step 1: This step involves downloading JDK from Download JDK. Step 2: Setting up the PATH environment variable appropriately. For win
2 min read
How to Pull Environment Variables with Helm Charts
Helm Chart is widely regarded as the package manager for Kubernetes. While it may appear to be just another package manager, it extends a great deal more. Helm makes managing application components easy by grouping those parts into charts, which can then be easily installed and upgraded. What is Helm Charts?Helm charts leverage a packaging format.
5 min read
Hibernate - Enable and Implement First and Second Level Cache
If you're a Java developer, you've probably heard of Hibernate. It's a free, open-source ORM framework that lets you map your Java objects to tables in a relational database. Basically, it makes database programming a breeze since you don't have to worry about writing SQL queries - you can just work directly with Java objects. In contrast, caching
10 min read
Article Tags :
Practice Tags :