Member-only story

Analysing Java GC in Kubernetes Without Stopping or Changing Anything

Get the current Java memory and GC without restarting with just kubectl exec or docker exec access

Nuno Aguiar
Better Programming
8 min readDec 19, 2022

image by author

Do you run Java in Kubernetes or Docker and need to quickly analyze the Java memory and GC behavior without stopping the process/container?

Is the container running in a protected cluster on which you can only run kubectl and you can’t add JMX or other ports?

Are you running a Java-based container but don’t want to include jstat or other tools?

Here’s a solution.

Note: this will work for any Java HotSpot based JVM.

This solution assumes an “airgap” environment (without internet access) and will allow you to achieve the following progressively:

  • Quickly have a terminal-based glance at the current Java memory and GC metrics for a running container
    (steps 1 to 3)
Terminal-based
  • Pipeline the Java memory and GC metrics gathered to a local Prometheus/Grafana setup to analyze them near real-time
    (step 4)

Nuno Aguiar
Nuno Aguiar

Written by Nuno Aguiar

Senior Cloud Software Architect

No responses yet

Write a response