{"id":23527992,"url":"https://github.com/nerdingitout/oc-quota","last_synced_at":"2026-01-21T09:33:19.035Z","repository":{"id":84627210,"uuid":"329262324","full_name":"nerdingitout/oc-quota","owner":"nerdingitout","description":"Enforcing resource consumption limits using OpenShift ResourceQuota","archived":false,"fork":false,"pushed_at":"2021-02-01T10:11:34.000Z","size":53,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-14T10:32:28.550Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nerdingitout.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-01-13T09:50:47.000Z","updated_at":"2021-02-01T10:11:36.000Z","dependencies_parsed_at":null,"dependency_job_id":"5d7effb8-13aa-4390-9aeb-932d31bfe8e6","html_url":"https://github.com/nerdingitout/oc-quota","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/nerdingitout/oc-quota","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nerdingitout%2Foc-quota","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nerdingitout%2Foc-quota/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nerdingitout%2Foc-quota/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nerdingitout%2Foc-quota/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nerdingitout","download_url":"https://codeload.github.com/nerdingitout/oc-quota/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nerdingitout%2Foc-quota/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28631158,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-21T04:47:28.174Z","status":"ssl_error","status_checked_at":"2026-01-21T04:47:22.943Z","response_time":86,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-25T20:19:02.237Z","updated_at":"2026-01-21T09:33:19.013Z","avatar_url":"https://github.com/nerdingitout.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Enforcing resource consumption limits using OpenShift ResourceQuota\n## Introduction\nWhen several users or teams share a cluster with a fixed number of nodes, there is a concern that one team could use more than its fair share of resources. Therefore, resource quota is a tool for administrators to address this concern.\u003cbr\u003e\nA resource quota provides constraints that limit aggregate resource consumption per project or pod/container. It can limit the quantity of objects that can be created in a project by type, as well as the total amount of compute and storage resources that may be consumed by resources in that project.\u003cbr\u003e\nIn Red Hat OpenShift, you can manage constraints on a project level using the Resource Quota object or on a pod/container level using the Limit Range object.\u003cbr\u003e\nIn Limit Ranges, you can specify the minimum and maximum usage of memory and CPU. As for Resource Quotas, you can specify amount of memory and CPU and number of Pods, replication controllers, services, secrets and presistent volume claims.\u003cbr\u003e\nA resource quota is enforced on a project or pod/container when there is ResourceQuota/LimitRange specified.\n\n## Prerequisites\nFor this tutorial you will need:\n- Red Hat OpenShift Cluster 4.3 or higher on IBM Cloud.\n- oc CLI (can be downloaded from this \u003ca href=\"https://mirror.openshift.com/pub/openshift-v4/clients/oc/4.3/\"\u003elink\u003c/a\u003e or you can use it at \u003ca href=\"http://shell.cloud.ibm.com/\"\u003ehttp://shell.cloud.ibm.com/.\u003cbr\u003e\n## Estimated Time\nIt will take you around 30 minutes to complete this tutorial.\n## Steps\n- Create a Project \u0026 Enforce Resource Quota\n- Configure a Pod Quota for a Namespace\n- Verify that the Pod Quota works\n- Configure Memory and CPU for a Namespace\n- Verify that the CPU and Memory Quotas work\n\n## Login to the CLI \u0026 Create a Project\n- Go to the web console and click on your username at the top right then 'Copy Login Command', then display the token and copy the ```oc login``` command in your terminal.\u003cbr\u003e\n![login](https://user-images.githubusercontent.com/36239840/97104809-26821500-16d0-11eb-936e-c2b7fb914523.JPG)\n- From the CLI, create a project and name it 'quota-demo' as shown in the following command.\u003cbr\u003e\n```\noc new-project quota-demo\n```\n## Configure a Pod Quota for a Namespace\n- Create a ResourceQuota for the project that limits the number of pods to 2 using the following command\n```\noc apply -f https://raw.githubusercontent.com/nerdingitout/oc-quota/main/project-quota.yaml\n```\n- Check if the ResourceQuota has been created successfully.\n```\noc get resourcequota\n```\n![get resourcequota](https://user-images.githubusercontent.com/36239840/105810654-cba8d400-5fc4-11eb-9687-6b4b64f57192.JPG)\n- You can also view the resource quota on the web console from the Administrator Perspective. Go to \u003cb\u003eAdministration \u0026#8594; Resource Quotas\u003c/b\u003e as shown in the image below.\n![resourcequota webconsole](https://user-images.githubusercontent.com/36239840/105811063-791be780-5fc5-11eb-8aa5-7950c7dc3b4a.JPG)\n- If you view the details of the resource quota and scroll down to Resource Quota Details table, you can notice information on used and maximum resources. Since you haven't delpoyed any pods yet, it will show 0 pods used.\n![quota details](https://user-images.githubusercontent.com/36239840/105811625-5b02b700-5fc6-11eb-8a95-06414df4b7d1.JPG)\n\n## Verify that the Pod Quota works\n- Deploy a simple application, we will scale it to 2 replicas in the next step\n```\noc create deployment myguestbook --image=ibmcom/guestbook:v1 -n quota-demo\n```\n![image](https://user-images.githubusercontent.com/36239840/106387970-cc42cf80-63f5-11eb-8770-bec826f9a75e.png)\n- If you use the the ```oc get pods``` command you will notice that the pod is in running state.\n![image](https://user-images.githubusercontent.com/36239840/106388021-06ac6c80-63f6-11eb-9565-558f020633e2.png)\n- If you go back to the Resource Quota 'pod-demo' on the web console, you will notice the number of used pods is now 1 as expected. This shows that the ResourceQuota has correctly accounted our Pod against the specified Quota\n![image](https://user-images.githubusercontent.com/36239840/106388036-14fa8880-63f6-11eb-8c56-2411c358184d.png)\n- Next, you will need to scale the application to 2 replicas. You can scale the application from both web console and command line. In this step, you will perform it from the web console. Go to \u003cb\u003eWorkloads \u0026#8594; Deployments\u003c/b\u003e and click on 'myguestbook' deployment.\n![deployments](https://user-images.githubusercontent.com/36239840/106388296-458ef200-63f7-11eb-8d7b-e0b354d7c2f0.JPG)\n- Clicking on the upper arrow will increase number of replicas, down arrow decreases number of replicas. In this step you will need to increase number of replicas to 2.\n![scale pods](https://user-images.githubusercontent.com/36239840/106388343-7bcc7180-63f7-11eb-9372-2c11b8ac2081.JPG)\n- If you go back to the Resource Quota 'pod-demo' on the web console, you will notice the number of pods used has increased to 2.\n![image](https://user-images.githubusercontent.com/36239840/106388411-d534a080-63f7-11eb-813f-515a2266fc20.png)\n- Now, let's try exceeding the quota by adding another pod.\n```\noc create deployment myguestbookv2 --image=ibmcom/guestbook:v2 -n quota-demo\n```\n![image](https://user-images.githubusercontent.com/36239840/106388658-06fa3700-63f9-11eb-8035-b1ff546b2868.png)\n- If you run ```oc get pods``` you will notice that there are only 2 pods running even though you created a total of 3 pods.\n![image](https://user-images.githubusercontent.com/36239840/106388687-2beeaa00-63f9-11eb-8518-0b487b8efde6.png)\n- Go back to the web console and go to \u003cb\u003eWorkloads \u0026#8594; Deployments\u003c/b\u003e. Notice the status of the pod showing '0 of 1 pods'\n![deployments 2](https://user-images.githubusercontent.com/36239840/106388766-6ce6be80-63f9-11eb-9fc8-2ce9cb4a15d2.JPG)\n- Click on the 'myguestbook2' deployment to view more details. You will notice that the pod hasn't been deployed.\n![image](https://user-images.githubusercontent.com/36239840/106388869-db2b8100-63f9-11eb-82a4-b1a54011c9d9.png)\n- If you scroll all the way down, you will notice the conditions section which shows that the pod has failed because the quota has been exceeded.\n![failed pod](https://user-images.githubusercontent.com/36239840/106388947-2ba2de80-63fa-11eb-9b77-1c6db42271eb.JPG)\n- Before moving to the next step, make sure to delete all resources and the resource quota you created in this step. You can delete the resource quota from the web console. Use the following commands to delete all resources for 'myguestbook' and 'myguestbookv2' deployments.\n```\noc delete all --selector app=myguestbook\noc delete all --selector app=myguestbookv2\n```\n![delete all](https://user-images.githubusercontent.com/36239840/106389819-d9b08780-63fe-11eb-87a0-90d5df2ecbbb.JPG)\n## Configure Memory and CPU for a Namespace\n- Create a new ResourceQuota for memory and CPU using the following ```oc apply``` command.\n```\noc apply -f https://raw.githubusercontent.com/nerdingitout/oc-quota/main/quota-mem-cpu.yaml\n```\n![image](https://user-images.githubusercontent.com/36239840/106389379-660d7b00-63fc-11eb-8b8b-8e5c5103214b.png)\n- The YAML file contains the following details for the quota\n```\napiVersion: v1\nkind: ResourceQuota\nmetadata:\n  name: mem-cpu-demo\nspec:\n  hard:\n    requests.cpu: \"1\"\n    requests.memory: 1Gi\n    limits.cpu: \"2\"\n    limits.memory: 2Gi\n```\nAs you can notice, when defining the quota got CPU and memory you are defining minimum (requests) and maximum (limits) resources to be used. Once created, you can view the resource quota on the web console. The following screenshot shows that the resources haven't been used yet.\n![image](https://user-images.githubusercontent.com/36239840/106389845-095f8f80-63ff-11eb-93d6-325469edbfca.png)\n![image](https://user-images.githubusercontent.com/36239840/106389890-4166d280-63ff-11eb-8024-025cc95c7ba7.png)\n\nThis ResourceQuota places these requirements on the quota-demo namespace: Every Container must have a memory request, memory limit, cpu request, and cpu limit. \n- The memory request total for all Containers must not exceed 1 GiB. \n- The memory limit total for all Containers must not exceed 2 GiB.\n- The CPU request total for all Containers must not exceed 1 core. \n- The CPU limit total for all Containers must not exceed 2 cores.\n## Verify that the CPU and Memory Quotas work\n- Create an Nginx application using the following command.\n```\noc apply -f https://raw.githubusercontent.com/nerdingitout/oc-quota/main/nginx-app.yaml\n```\n![image](https://user-images.githubusercontent.com/36239840/106390215-bab2f500-6400-11eb-8993-8b9c3456863d.png)\n- The yaml definition specfies the memory and CPU for the pod as shown below.\n```\napiVersion: v1\nkind: Pod\nmetadata:\n  name: nginx-app\nspec:\n  containers:\n  - name: quota-mem-cpu-demo-ctr\n    image: nginx\n    resources:\n      limits:\n        memory: \"800Mi\"\n        cpu: \"800m\"\n      requests:\n        memory: \"600Mi\"\n        cpu: \"400m\"\n```\n- Since the requests and limits for the CPU and memory are within the quota, the pod should be created successfully.\n![image](https://user-images.githubusercontent.com/36239840/106390264-ee8e1a80-6400-11eb-8311-a4a7dacf5e3c.png)\n- On the web console, if you go back to the resource quota, you will notice that the Nginx Pod’s CPU and Memory requests and limits are correctly accounted for against the ResourceQuota.\n![image](https://user-images.githubusercontent.com/36239840/106390279-082f6200-6401-11eb-83cc-33496b634321.png)\n![image](https://user-images.githubusercontent.com/36239840/106390287-12516080-6401-11eb-8ce9-040be9d51594.png)\n- Now, try to exceed the quota by creating a new application using redis docker image. The yaml defitnition includes the following details. Keep in mind that it will exceed the quota, therefore the application won't be created.\n```\napiVersion: v1\nkind: Pod\nmetadata:\n  name: redis-app\nspec:\n  containers:\n  - name: quota-mem-cpu-demo-2-ctr\n    image: redis\n    resources:\n      limits:\n        memory: \"1Gi\"\n        cpu: \"800m\"\n      requests:\n        memory: \"700Mi\"\n        cpu: \"400m\"\n```\n- Use the following command to create the application\n```\noc apply -f https://raw.githubusercontent.com/nerdingitout/oc-quota/main/redis-app.yaml\n```\n- You will notice the following error and that's because the application exceeded the quota.\n![image](https://user-images.githubusercontent.com/36239840/106390512-3b262580-6402-11eb-90bc-2617cda77f37.png)\n- You can increase the resource quota to fit in the new application. Go to the YAML definition of the 'mem-cpu-demo' resource quota and edit it under the spec section (between lines 65 and  71) as shown below and then save your changes.\n![image](https://user-images.githubusercontent.com/36239840/106390761-5fcecd00-6403-11eb-8521-105abff0aeb2.png)\n```\nspec:\n  hard:\n    limits.cpu: '4'\n    limits.memory: 4Gi\n    requests.cpu: '1'\n    requests.memory: 2Gi\n```\n- Attempt to create the same redis application again, it will be created successfully.\n```\noc apply -f https://raw.githubusercontent.com/nerdingitout/oc-quota/main/redis-app.yaml\n```\n![image](https://user-images.githubusercontent.com/36239840/106390780-7ecd5f00-6403-11eb-994a-32e49fefcec1.png)\n- If you use ```oc get pods``` you will see that the new applciation has been created successfully.\n![image](https://user-images.githubusercontent.com/36239840/106390869-ebe0f480-6403-11eb-9621-82f169bea672.png)\n- If you go back to the 'mem-cpu-demo' details page, you will notice that it has changed and now the consumed resources are counted for both applications\n![image](https://user-images.githubusercontent.com/36239840/106390818-b76d3880-6403-11eb-9bf8-db3d9d7af3bd.png)\n![image](https://user-images.githubusercontent.com/36239840/106390856-d66bca80-6403-11eb-8d26-616ff6e98f39.png)\n\n## Summary\nIn this tutorial, you learned what is a resource quota and how to create resource quotas for namespaces and pods. With resource quota you can control CPU usage, memory usgae, number of pods, replication controllers, services, secrets and presistent volume claims. You performed several tasks to control resources and saw changes in the project and pods and learned what happens when you exceed the resource quota and how to change it.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnerdingitout%2Foc-quota","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnerdingitout%2Foc-quota","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnerdingitout%2Foc-quota/lists"}