How to Expose Jmx in Kubernetes?

1 min readNov 24, 2021



In this short post I will show you how we can easily expose Jmx in Kubernetes. If we want to temporarily debug our application with JMX the easiest way is forward JMX port from Kubernetes pod to your local PC with kubectl port-forward.

Let’s start

Add JVM options to your application

Important part is:

  • We need use same port as jmxremote.port and jmxremote.rmi.port. This is needed to forward one port only.
  • As rmi.server.hostname we should pass This is needed for JMX connection to work via port-forwarding.

Forward the JMX port (5000) to your local PC via kubectl

λ kubectl port-forward "your-app-pod" 5000

Open connection with jconsole to your local port 5000

λ jconsole

In this way makes it possible to debug any Java pod via JMX without having to publicly expose JMX via K8 service which is better from security perspective then expose this JMX via service.





DevOps Consultant. I’m strongly focused on automation, security, and reliability.