Check Java parameters in Kubernetes pods

When checking the Java parameters running on Kubernetes, there is a stumbling block unique to k8s (or Docker), so I will share the method that worked.

Editing Dockerfile

Normally, the PID of the process started by Docker will be 1, but since jcmd and jinfo described later cannot be attached to the process with PID 1, it is necessary to change the PID.

A package called Tini is introduced to change the PID. Also, set ENTRYPOINT to tini and pass the application you actually want to start as a parameter.


FROM openjdk:8-jdk-alpine
LABEL MAINTAINER="[email protected]"
WORKDIR /opt/docker
ADD --chown=daemon:daemon opt /opt
USER daemon
ENTRYPOINT ["/sbin/tini", "--", "/opt/docker/your/app/entrypoint"]
CMD []
USER root
RUN apk --update add bash
RUN apk add --no-cache tini
USER daemon

If you are using distortion other than Alpine, please refer to Tini's GitHub for installation instructions.

Login to Pod

Login to the pod is the same as the usual method.

$ kubectl get pod
NAME                                             READY     STATUS             RESTARTS   AGE
pod-name-xxxxxxxxxx-xxxxx                        1/1       Running            0          10h
$ kubectl exec -it pod-name-xxxxxxxxxx-xxxxx bash

Check the default values of the parameters

$ java -XX:+PrintFlagsFinal -version
[Global flags]
     intx ActiveProcessorCount                      = -1                                  {product}
    uintx AdaptiveSizeDecrementScaleFactor          = 4                                   {product}
    uintx AdaptiveSizeMajorGCDecayTimeScale         = 10                                  {product}

Check the parameters of the running Java program

Check the PID of the target process with the jps command.

$ jps -v
7 ProdServerStart -Duser.dir=/opt/docker
142 Jps -Dapplication.home=/usr/lib/jvm/java-1.8-openjdk -Xms8m

You can display a list of valid parameters by specifying the PID checked with the jcmd command.

$ jcmd 7 VM.flags -all
[Global flags]
     intx ActiveProcessorCount                      = -1                                  {product}
    uintx AdaptiveSizeDecrementScaleFactor          = 4                                   {product}
    uintx AdaptiveSizeMajorGCDecayTimeScale         = 10                                  {product}

Use the jinfo command to see the settings for a particular parameter. The following is an example of checking the maximum heap memory setting.

$ jinfo -flag MaxHeapSize 7

Java parameter related reference site

Recommended Posts

Check Java parameters in Kubernetes pods
Check https connection in Java
Stop apps (pods) in Kubernetes
Partization in Java
Java version check
Changes in Java 11
Rock-paper-scissors in Java
Java check process
Pi in Java
FizzBuzz in Java
Check static and public behavior in Java methods
[java] sort in list
Read JSON in Java
Interpreter implementation in Java
Rock-paper-scissors app in Java
Constraint programming in Java
Put java8 in centos7
NVL-ish guy in Java
Combine arrays in Java
"Hello World" in Java
Callable Interface in Java
Comments in Java source
Format XML in Java
Simple htmlspecialchars in Java
Boyer-Moore implementation in Java
Hello World in Java
Use OpenCV in Java
webApi memorandum in java
Type determination in Java
Ping commands in Java
Various threads in java
Heapsort implementation (in java)
[Java] Arguments and parameters
Zabbix API in Java
ASCII art in Java
Compare Lists in Java
Express failure in Java
Create JSON in Java
Date manipulation in Java 8
What's new in Java 8
Check coverage with Codecov in Java + Gradle + Wercker configuration
Use PreparedStatement in Java
What's new in Java 9,10,11
Parallel execution in Java
Initializing HashMap in Java
Memo: [Java] How to check groupId etc. described in pom.xml
Easy way to check method / field list in Java REPL
Read binary files in Java 1
Avoid Yubaba's error in Java
[Neta] Sleep Sort in Java
Edit ini in Java: ini4j
Java history in this world
Let Java segfault in 6 lines
Try calling JavaScript in Java
Try developing Spresense in Java (1)
Enable strong parameters in devise
I made roulette in Java.
Create hyperlinks in Java PowerPoint
Implement two-step verification in Java
Refactoring: Make Blackjack in Java