Bootstrap FreeKB - OpenShift - Resolve 502 Bad Gateway
OpenShift - Resolve 502 Bad Gateway

Updated:   |  OpenShift articles

Let's say something like this is being returned when requesting your app running in a pod on OpenShift.

 

This often means:

  • timeout
  • not enough CPU
  • not enough memory

If you are not familiar with the oc command, refer to OpenShift - Getting Started with the oc command.

This one-liner can be used to return the real time amount of memory in MB being used by the default container in the pod.

~]$ bytes=$(oc exec my-pod-9mzm2 -- cat /sys/fs/cgroup/memory/memory.usage_in_bytes); echo $(($bytes / 1024 / 1024 ))
240

 

Notice in this example that the pod is using 240 MB of memory. If there is a limit to only allow the pod to use 256 MB of memory this could cause the pod to get Killed which could cause 502 Bad Gateway to be returned.

The oc get limits command can be used to determine if a limits resource has been created in the same namespace as the pod is in.

~]$ oc get limits --namespace my-project
NAME          CREATED AT
my-limits     2022-07-26T12:25:53Z

 

The oc describe limits command can be used to display more details about a limit. In this example, since the container memory default limit is 256Mi this means the pod may be killed if any container in the pod uses 256Mi of memory.

~]$ oc describe limits my-limits
Name:       my-limits
Namespace:  foo
Type        Resource  Min   Max  Default Request  Default Limit  Max Limit/Request Ratio
----        --------  ---   ---  ---------------  -------------  -----------------------
Pod         cpu       200m  2    -                -              -
Pod         memory    6Mi   1Gi  -                -              -
Container   cpu       100m  2    200m             300m           10
Container   memory    4Mi   1Gi  100Mi            256Mi          -

 

Likewise, the resource that manages the pod, such as a deployment, deployment config, stateful set, or rollout, may be configured with requests / limits. In this example, the deployment is limiting the container to 256Mi of memory.

spec:
  template:
    spec:
      containers:
      - name: hello-world
        resources:
          requests:
            cpu: 10m
            memory: 128Mi
          limits:
            cpu: 500m
            memory: 256Mi

 

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter e3bde9 in the box below so that we can be sure you are a human.