How to investigate and troubleshoot "OOMKilled" errors in the SAS® Viya® platform


When a container in a pod tries to use memory that exceeds its limit, the container fails with an OOMKilled (Out of Memory Killed) error.

This SAS KB article explains how to increase the pod's memory limit and circumvent the error. 

For additional information, see Increase the Memory Limit for a Pod.

Workaround

To circumvent this error, two workarounds are available: a temporary resolution and a permanent fix.

Temporary Resolution

1. Confirm that the pod fails with an OOMKilled error. See the Container section in the "kubectl describe" output of the pod.

Here is an example: 
$ kubectl describe pod sas-pod-name

Containers:
  sas-container-name:
    Container ID:   containerd://container-id
    Image:          cr.sas.com/viya-4-x64_oci_linux_2-docker/sas-image-name
    Image ID:       cr.sas.com/viya-4-x64_oci_linux_2-docker/sas-image-id
    Port:           port-number/TCP
    Host Port:      0/TCP
    State:          Waiting
      Reason:       CrashLoopBackOff
    Last State:     Terminated
      Reason:       OOMKilled

 

2. Retrieve the current memory limit setting. 

  1. In the "kubectl describe" output, locate the Controlled By section:
    Controlled By:  object_type/resource_name

    Note
    : In most scenarios, if the object_type is a ReplicaSet, and the resource_name contains a pod-template-hash (for example, 95b45bfd5), that pod is controlled by a Deployment. You can check whether the pod is controlled by a deployment by looking at the "kubectl describe" output of the ReplicaSet.


  2. Check the memory limit setting:
    $ kubectl -n namespace get object_type resource_name -o jsonpath='{.spec.template.spec.containers[container_index].resources.^
    limits.memory}{"\n"}'


    container_index is an ingeter and starts from 0.

  3. Check your desired container index with the following command:
    $ kubectl -n namespace get object_type resource_name -o jsonpath='{.spec.template.spec.containers[*].name}{"\n"}'

  4. Then, modify the memory limit:
    $ kubectl -n namespace patch object_type resource_name --type json -p='[{"op":"replace", "path":"/spec/template/spec/containers/container_index/resources/limits/^
    memory","value":"new_memory_limit"}]'


    Note: This value must be in Kubernetes units. See Kubernetes: Memory Resource Units for additional information. 

Permanent Fix

1. After you locate the object_type and resource_name from the steps in the previous section, add a PatchTransformer in kustomize.yaml.

Here is an example for the sas-identities deployment:
apiVersion: builtin
kind: PatchTransformer
metadata:
  name: patch-identities-mem
patch: |-
  - op: replace
    path: /spec/template/spec/containers/0/resources/limits/memory
    value: 2Gi
target:
  kind: Deployment
  name: sas-identities


2. Save the PatchTransformer in your deployment directory as a yaml file and add the path in the transformers block or kustomize.yaml.