This guide explains how to create and enforce a resource quota in an OpenShift project using YAML manifests and deploying a pod.
In this guide, you’ll learn how to create and enforce a resource quota in an OpenShift project. By following these steps, you will set up a project, define a resource quota using a YAML manifest, and deploy a pod that respects the quota limitations.
Open your code editor (for example, VS Code) and create a YAML manifest file named limit.yaml. This manifest defines a resource quota that limits the total memory requests for the namespace “limittester” to 512 MiB. In this case, the resource quota is part of the core API group.
Next, test the quota by deploying a pod that requests memory. Create or open a deployment manifest file named deployment.yaml. In this file, the namespace is explicitly set to “limittester” to ensure the deployment is part of the correct project. Combine the metadata and pod specification in one deployment configuration:
The metadata.namespace field ensures that the deployment is created within the “limittester” project.
The container carts-db is configured to request 100 MiB of memory.
Apply the deployment with:
Copy
Ask AI
oc apply -f deployment.yaml
You might receive a warning regarding pod security, but the deployment will be created successfully.
Verify that the deployment is running by executing:
Copy
Ask AI
oc get deployments -n limittester
Then, check the resource quota again to see the updated memory usage:
Copy
Ask AI
oc get resourcequota -n limittester
Expected output:
Copy
Ask AI
PS C:\Users\mike\Desktop> oc get resourcequota -n limittesterNAME AGE REQUEST LIMITmemlimit 3m14s requests.memory: 100Mi/512Mi
This output confirms that 100 MiB of the allowed 512 MiB has been requested by the deployment, indicating that the resource quota is functioning as expected.With these steps, you have successfully created a project, defined a resource quota, and deployed a pod with a memory request within the specified limits.For further details and advanced configurations, consider exploring additional OpenShift and Kubernetes documentation.