Bootstrap FreeKB - OpenShift - List CPU Memory Limits using the oc get limits command
OpenShift - List CPU Memory Limits using the oc get limits command

Updated:   |  OpenShift articles

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

  • Limits can be used to set the minimum and maximum amount of CPU/memory/storage for:
    • a single deployment related asset (e.g. container / pod) in a namespace and is typically defined in deployment YAML or deployment config YAML
    • all deployment related assets (e.g. containers / pods) in a namespace
  • Quotas can be used to:
    • set the maximum amount of CPU and memory that can be used in a namespace
    • set the maximum number of running resources (e.g. persistent volume claims, pods, replication controllers, routes, secrets, services, et cetera) in a namespace
  • Cluster Resource Quotas is the same as Quotas except the minimum and maximum are associated with:
    • A user
    • One or more namespaces

You can set both requests and limits.

  • requests
    • the amount of memory / CPU that is reserved or allocated for the container.
  • limit
    • the maximum amount of memory / CPU a container can use
    • if a container reaches the CPU limit, the container will be throttled (won’t let it consume any more CPU)
    • if a container reaches the memory limit, Out Of Memory (OOM) should occur and the pod should be killed
    • if a container reaches the storage limit, the pod should be evicted

The oc get limits command can be used to list the limits that have been created in the currently selected project / namespace.

TIP

The -A or --all-namespaces flag can be used to list the limits in every project / namespace.

The -n or --namespace flag can be used to list the limits in a certain project / namespace.

~]$ oc get limits
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.

  • requests - the minimum of CPU/memory that is reserved or allocated for the container
  • limits - the maximum amount of CPU/memory that can be used by the container
~]$ 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            200Mi          -

 

Or, the oc get limits command with the --output json​ or --output yaml option can be used.

~]$ oc get limits my-limits --output json
{
    "apiVersion": "v1",
    "kind": "LimitRange",
    "metadata": {
        "creationTimestamp": "2022-07-28T01:34:20Z",
        "name": "my-limits",
        "namespace": "foo",
        "resourceVersion": "446036011",
        "uid": "3c6a5bb0-1f1b-490c-84ab-1621d48fb3df"
    },
    "spec": {
        "limits": [
            {
                "max": {
                    "cpu": "2",
                    "memory": "1Gi"
                },
                "min": {
                    "cpu": "200m",
                    "memory": "6Mi"
                },
                "type": "Pod"
            },
            {
                "default": {
                    "cpu": "300m",
                    "memory": "200Mi"
                },
                "defaultRequest": {
                    "cpu": "200m",
                    "memory": "100Mi"
                },
                "max": {
                    "cpu": "2",
                    "memory": "1Gi"
                },
                "maxLimitRequestRatio": {
                    "cpu": "10"
                },
                "min": {
                    "cpu": "100m",
                    "memory": "4Mi"
                },
                "type": "Container"
            }
        ]
    }
}

 

The --output jsonpath option can be used to print the value of a specific JSON key.

~]$ oc get limits my-limits --output jsonpath={.spec.limits[0].max.memory}
1Gi

 




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 756b09 in the box below so that we can be sure you are a human.