0
votes

I have set pod definition config as below. i set both heap memory and memory limits on container,

spec:
  containers:
    - command:
        - sh
        - '-c'
        - >-
          exec java -XX:+UseG1GC -Xms512m -Xmx512m -XX:MaxRAM=640m
      ports:
        - containerPort: 8080
          name: http
          protocol: TCP
        - containerPort: 8443
            name: https
            protocol: TCP
        - containerPort: 8081
            name: management
            protocol: TCP
     resources:
       limits:
         cpu: 200m
         memory: 950Mi
       requests:
         cpu: 100m
         memory: 128Mi

but pod fequently gets killed with OOM. in that case what values should i change. whether resources part or heap memory .

also would like to how memory as jvm arguments and memory as resources works together.

1

1 Answers

0
votes

First of all your configurations seem fine. I don't think you need "-XX:MaxRAM=640m". If you are using Java 10+ you don't even need these flags at all, with Java 8 there is a flag that helps you remove these flags as well.

I think your problem is actual resources on nodes are not sufficient, because pod isn't in pending state which means there is at least 128Mi empty memory reservation but not the actual resource. Problem may be 2 reasons:

1: Your bursting isn't enough(200 mcpu, 950Mi memory) and your app crashes while starting. This is common problem with Java based apps, especially with Spring Boot. To check this remove memory limit part from configuration and see if you have still OOM kills. If this fixes your problem, then find the sweet spot for memory limit your app needs.

2: Your nodes working at near full capacity and your app has only 128Mi as guaranteed but not much after that since you may have more bursting apps working above requested power. You can simply monitor it with "free -h" in nodes. This is the reason it's considered best by some group to set requests and limits same to provide stability.