{"id":9107,"date":"2021-01-08T11:58:43","date_gmt":"2021-01-08T03:58:43","guid":{"rendered":"https:\/\/jpuyy.com\/?p=9107"},"modified":"2021-01-08T12:02:48","modified_gmt":"2021-01-08T04:02:48","slug":"k8s-pod-oomkill-exit-code-137","status":"publish","type":"post","link":"https:\/\/jpuyy.com\/?p=9107","title":{"rendered":"k8s pod OOMKill Exit Code:    137"},"content":{"rendered":"<p>Identify it is OOMKill<\/p>\n<p>Reason should be OOMKill and the time is Finished<\/p>\n<p>kubectl get pods testapp-v092-p8czf -o yaml | less -i<\/p>\n<p>&#8230;<br \/>\n    Last State:     Terminated<br \/>\n      Reason:       OOMKilled<br \/>\n      Exit Code:    137<br \/>\n      Started:      Fri, 11 Sep 2020 11:00:08 +0800<br \/>\n      Finished:     Mon, 14 Sep 2020 13:00:46 +0800<br \/>\n&#8230;<\/p>\n<p>OOM heap dump ( when oomkill happen )<\/p>\n<p>Container entrypoints add java start params<\/p>\n<p>-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=<PATH_FOLDER>\\<file_name>.hprof<\/p>\n<p>2. Mount an emptyDir for the pod In the pod lifecycle, \/var\/log\/dump is durable.<\/p>\n<p>3. Compress the dumpfile and download<\/p>\n<p>gzip heapdump2020-09-15-03-198523874477783269974.hprof<br \/>\nkubectl cp  testapp-v1127-xnbhq:\/var\/log\/dump\/heapdump2020-09-15-03-198523874477783269974.hprof.gz \/tmp\/heapdump2020-09-15-03-198523874477783269974.hprof.gz<\/p>\n<p>Check List ( pod is already restarted )<\/p>\n<p>check stackdirver applictaion logs<\/p>\n<p>check memory and cpu limits<\/p>\n<p> $ kubectl get pods testapp-v203-trsfl -o yaml<br \/>\n &#8230;<br \/>\n    resources:<br \/>\n      limits:<br \/>\n        cpu: 1500m<br \/>\n        memory: 1229Mi<br \/>\n      requests:<br \/>\n        cpu: 300m<br \/>\n        memory: 1Gi<br \/>\n &#8230;<\/p>\n<p>check kubectl top status<\/p>\n<p>$ kubectl top pod testapp-v203-trsfl &#8211;containers<br \/>\nPOD                         NAME             CPU(cores)   MEMORY(bytes)<br \/>\ntestapp-v203-trsfl   testapp   13m          1144Mi<br \/>\ntestapp-v203-trsfl   istio-proxy      5m           47Mi<\/p>\n<p>new relic pod memory:<\/p>\n<p>commands investigate java stack heap (inside pod)<\/p>\n<p>apk add &#8211;no-cache jattach &#8211;repository http:\/\/dl-cdn.alpinelinux.org\/alpine\/edge\/community\/<br \/>\njattach pid inspectheap<br \/>\njattach pid jcmd VM.info<\/p>\n<p>ps find RSS of process (inside pod)<\/p>\n<p>$ kubectl exec -it testapp-v203-trsfl \/bin\/bash<br \/>\nps -o pid,user,vsz,rss,comm,args<br \/>\nPID   USER     VSZ  RSS  COMMAND          COMMAND<br \/>\n    1 root     4332  720 tini             \/tini &#8212; \/entrypoint.sh java<br \/>\n    7 test 6.3g 1.1g java             java -XX:+UseG1GC -Xms768m -Xmx768m -DREGION=gcp_hk -XX:+ExitOnOutOfMemoryError -XX:+UseStringDeduplication -XX:StringDeduplicationAgeThreshold=3 -agentlib:jdwp=transport=dt_socket,ser<br \/>\n18215 root     2620 2316 bash             \/bin\/bash<br \/>\n18267 root     1572   20 ps               ps -o pid,user,vsz,rss,comm,args<\/p>\n<p>Issues:<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Identify it is OOMKill Reason should be OOMKill and the time is Finished kubectl get pods testapp-v092-p8czf -o yaml | less -i &#8230; Last State: Terminated Reason: OOMKilled Exit Code: 137 Started: Fri, 11 Sep 2020 11:00:08 +0800 Finished: Mon, 14 Sep 2020 13:00:46 +0800 &#8230; OOM heap dump ( when oomkill happen ) Container [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-9107","post","type-post","status-publish","format-standard","hentry","category-life"],"_links":{"self":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/9107","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9107"}],"version-history":[{"count":8,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/9107\/revisions"}],"predecessor-version":[{"id":9235,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/9107\/revisions\/9235"}],"wp:attachment":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9107"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9107"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9107"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}