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.
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.
Dockerfile
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
EXPOSE 9000
If you are using distortion other than Alpine, please refer to Tini's GitHub for installation instructions. https://github.com/krallin/tini
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
$ java -XX:+PrintFlagsFinal -version
[Global flags]
intx ActiveProcessorCount = -1 {product}
uintx AdaptiveSizeDecrementScaleFactor = 4 {product}
uintx AdaptiveSizeMajorGCDecayTimeScale = 10 {product}
...
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
7:
[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
-XX:MaxHeapSize=1960837120
https://docs.oracle.com/javase/jp/8/docs/technotes/tools/unix/java.html http://etc9.hatenablog.com/entry/2016/05/11/012037 https://x1.inkenkun.com/archives/367 https://qiita.com/kaikusakari/items/9f96ffd3a6dd71dfd914
Recommended Posts