Open In App

How to Enable JMX For Java Application Running in the Kubernetes Cluster?

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

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 or Out of Memory errors. In order to make our java application ready for analysis, one way is to enable the JMX port for the application and monitor its performance using java tools like JvisualVM, JConsole which are packages with JDK and can be used easily from external machines having jdk installed. Below is the guide to enable JMX manually and the steps to configure jvisualvm and jconsole. Connecting to these monitoring tools and seeing CPU, memory, thread consumption is the first step to start solving any performance-related issue in the system. For further analysis, we may need to analyze heap dumps of memory using memory analyzing tools like Eclipse Memory Analyzer or online free tools. One issue is identified that which class objects are taking too much space, you can go deeper into your system code to fix the issue. It could be a bug in the database model or java code which depends on the kind of issue and application. 

Below are the steps to enable jmx manually by setting the environment variable

Step 1: Edit the my-app-deployment.yaml by running the below command.

kubectl edit deployment  my-app-deployment

In the container’s environments section, add the following parameter (change the NODE_NAME accordingly and use any unused port: 9991)

– name: JAVA_TOOL_OPTIONS

 value: -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9991 -Dcom.sun.management.jmxremote.rmi.port=9991 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.local.only=false -Djava.rmi.server.hostname=<NODE_NAME>

If you want to generate Heap Dump to analyze memory-related issues like “Out of Memory error”, give the value of JAVA_TOOL_OPTIONS as below:

value: -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9991 -Dcom.sun.management.jmxremote.rmi.port=9991 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.local.only=false -Djava.rmi.server.hostname=<host-name> -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/dumps/heapdumpJ.hprof

And mount the /dumps like below block:

(If you don’t want to mount, use an existing folder of container like /tmp folder instead of /dumps)

volumeMounts:

– name: heap-dumps

mountPath: /dumps

volumes:

– name: heap-dumps

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

Step 2: Edit my-app-svc.yaml by running the below command

kubectl edit service my-app-svc

Add type: NodePort and expose nodePort, refer below sample my-app-svc.yaml

apiVersion: v1

kind: Service

metadata:

 name: my-app-svc

 namespace: <namespace>

spec:

 type: NodePort

 ports:

   – name: main-port

     port: 9992

     protocol: TCP

   – port: 9991

     nodePort: 9991

     protocol: TCP

     name: jconsole-port

 selector:

   app: my-app

After saving the changes to the deployment, Kubernetes will automatically restart the service with new changes.

Step 3: Run the below command and check 9991 port is available.

kubectl get service -n <namespace> | grep my-app-svc 

Once JMX is enabled for your application, connect to any Performance Analysis Tool to monitor CPU, Memory, Thread Usage of Application.

Running JConsole

  1. Run jconsole.exe
  2. JConsole window should appear.
  3. Click Remote Process and enter the following value, replace the hostname below with your hostname.
  4. Click Connect. Select the insecure connection. Then jconsole loads up the CPU, Memory, Thread utilization all performance-related metrics:-

Running JVisualVM

  1. Run jvisualvm.exe
  2. Right-click Remote and select Add Remote Host.
  3. Enter your hostname.
  4. The host should now appear under the Remote section.
  5. Right-click the newly added host and select Add JMX.
  6. Enter the <hostname>:<port> for connection, replacing the hostname and port with your actual server.
  7. Select Do not require an SSL connection.
  8. Click OK.
  9. After doing this, a new entry should appear under the host, selecting it will give a remote profile overview.

You are all set to do a performance analysis of your Java Application deployed in the Kubernetes cluster.


Previous Article
Next Article

Similar Reads

Kubernetes Cluster Autoscaler: Dynamically Adjusting Cluster Size
Kubernetes cluster autoscaler allows automatically expanding or decreasing the number of nodes or altering pod resources based on demand. When demand rises, the cluster can add nodes or allocate more resources to pods when demand falls, Kubernetes can remove nodes or assign fewer resources to a pod. This can assist optimize resource utilization and
4 min read
Enable Remote Debugging For Java Application Deployed in Kubernetes Environment
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
2 min read
Kubernetes Cluster
A group of nodes (Computers/Operating systems) working together to communicate with the help of Kubernetes software is known as the Kubernetes cluster. It works in a mechanism in such a way that it performs actions on the worker node with the help of the manager node. Need for a Kubernetes ClusterIn containerization when we launch our application t
6 min read
Setup Jenkins On Kubernetes Cluster
Setting up Jenkins on a Kubernetes cluster involves deploying Jenkins as a containerized application within the cluster. Kubernetes is Born in Google, written in Go/Golang. Donated to CNCF(Cloud native computing foundation) in 2014. Kubernetes v1.0 was released on July 21, 2015. Current stable release v1.29 What Is Kubernetes? Kubernetes is an orch
4 min read
How To Deploy Dashboard UI On A Kubernetes Cluster Locally ?
Docker Desktop is easily the most popular containerization software for developers and teams. But Docker Desktop would not only allow you to play with containers but can enable you to use Kubernetes without downloading any external cluster like Minikube. Docker Desktop is a secure, out-of-the-box containerization software that offers developers a r
6 min read
How to Add Node to Existing Kubernetes Cluster
Kubernetes allows the management and orchestration of containerized deployments. We can use various cluster managing tools, but Kubeadm allows us to create and manage Kubernetes clusters from scratch. Kubernetes cluster can be autoscaled with the use of Cluster management services. In this article, we will see how we can manually add a node to an e
4 min read
Kubernetes Node Vs. Pod Vs. Cluster: What’s The Difference?
Kubernetes automates most container management operations, allowing developers to operate high-performance, modern apps at scale. This includes built-in commands that handle most of the heavy lifting involved in application administration, allowing you to automate day-to-day tasks. Several components make up the system, and it can be difficult to d
7 min read
How to Scale a Kubernetes Cluster ?
Scaling a Kubernetes cluster is crucial to meet the developing needs of applications and ensure the finest performance. As your workload increases, scaling becomes vital to distribute the weight, enhance useful resource usage, and maintain high availability. This article will guide you through the terrific practices and techniques for scaling your
8 min read
How to Configure NCache to Run in a Kubernetes Cluster and Testing
In this article, let us discuss how to deploy and run NCache in a Kubernetes Cluster and how we can integrate this cache cluster with our application. We’ll follow it up with testing stress and then expose performance counters with SNMP. What is NCache?NCache is one of the most popular caching providers available in the market, along with other pla
8 min read
How to Install and Run a Kubernetes Cluster on Ubuntu 22.04 (Step-by-Step)
You can install and configure Kubernetes in different ways on your personal laptops, physical servers, Virtual machines, and as a cloud service. Before moving ahead with this article, we need to have a basic understanding of Kubernetes and its architecture and containers. In this article, we will get a high-level overview of ways you can install Ku
6 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
9 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
Java - Parameters Responsible for Difference in Outputs while Running on Local IDE vs Online IDE
The concept involved in the difference in output between running a Java program on a local IDE and an online IDE is the environment in which the program is being run. The specific version of Java, the settings and configurations of the IDE, and the instructions in the program can all affect the output of the program. To understand the differences i
4 min read
Installing Private Git Server on K8s Cluster with Gitea and AKS
In this article, we are going to install a self-hosted Gitea server on top of Azure Kubernetes Service with Helm and set up a git repo. Having a private Git server might be beneficial these days. Gitea is a community-managed Git-compatible lightweight code hosting solution written in Go. It is published under the MIT license. Azure Kubernetes Servi
4 min read
Setting up Cilium CNI Plugin on a Two Node Cluster on x86 using Kind
Setting up a robust and secure network layer in Kubernetes is crucial for managing containerized applications, especially in multi-node clusters. Cilium, an advanced CNI (Container Network Interface) plugin, offers powerful networking capabilities, including layer 7 policies, load balancing, and high scalability. This guide walks you through the pr
4 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
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 :
three90RightbarBannerImg