K8S中,使用openjdk:8-jdk-alpine作为基础镜像,启动服务后,
查看垃圾回收器,
发现,没有启动垃圾回收器。
使用jinfo查看了Serial、Parallel、Parallel Old和G1均没有相应信息,如图下图:
图中,均为-。
Deployment中,通过env配置JVM参数:
JAVA_TOOL_OPTIONS。
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: tutorial
name: tutorial-deployment
name: tutorial
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: tutorial
template:
metadata:
labels:
app: tutorial
spec:
containers:
- image: xdq101/tutorial:v20220211
imagePullPolicy: Always
name: tutorial
env:
- name: JAVA_TOOL_OPTIONS
value: -XX:InitialHeapSize=100m -XX:MaxHeapSize=100m -XX:+UseG1GC -XX:G1HeapRegionSize=1M
ports:
- containerPort: 9121
name: tutorial-port
volumeMounts:
- name: log
mountPath: /home/xindaqi/project/tutorial/logs
volumes:
- name: log
nfs:
path: /data/webapp/logs/tutorial
server: 192.168.211.129
配置垃圾回收器G1之后,通过jinfo查看垃圾回收器,结果如下图:
图中G1垃圾回收器为:+,表示正在使用该垃圾回收器。
openjdk:8-jdk-alpine在K8S中,没有默认垃圾回收器;通过JAVA_TOOL_OPTIONS手动配置垃圾回收器;



