Openshift Container Platform 3 – Apply quotas and limit ranges to project
As a system:admin user on master host:
- Create a project
oc new-project testowyprojekt --display-name="MaciejTestProjekt"
2. On the master host, create quota definition file – let’s save it as ‘quota5.json’
{
"apiVersion": "v1",
"kind": "ResourceQuota",
"metadata": {
"name": "test5-quota"
},
"spec": {
"hard": {
"memory": "512Mi",
"cpu": "15",
"pods": "2",
"services": "4",
"replicationcontrollers":"4",
"resourcequotas":"1"
}
}
}
3. Apply the file to specify the quota
oc create -f quota5.json --namespace= testowyprojekt
4. Verify that the quota exists:
oc get -n testowyprojekt quota
5. Verify the limits
oc describe -n testowyprojekt quota test5-quota
We can check the limits in the web console as well.
6. To apply limit ranges, create limits5.json file
{
"kind": "LimitRange",
"apiVersion": "v1",
"metadata": {
"name": "limits5",
"creationTimestamp": null
},
"spec": {
"limits": [
{
"type": "Pod",
"max": {
"cpu": "500m",
"memory": "750Mi"
},
"min": {
"cpu": "10m",
"memory": "5Mi"
}
},
{
"type": "Container",
"max": {
"cpu": "500m",
"memory": "750Mi"
},
"min": {
"cpu": "10m",
"memory": "5Mi"
},
"default": {
"cpu": "100m",
"memory": "100Mi"
}
}
]
}
}
7. Apply the limits5.json file to specify the limits.
oc create -f limits5.json --namespace=testowyprojekt
8. Review the limit ranges
oc describe limitranges limits -n testowyprojekt
9. Create POD definition file- lets called it pod5.json file
{
"kind": "Pod",
"apiVersion": "v1",
"metadata": {
"name": "openshift-testmaciej",
"creationTimestamp": null,
"labels": {
"name": "openshift-testmaciej"
}
},
"spec": {
"containers": [
{
"name": "openshift-testmaciej",
"image": "openshift/hello-openshift:v1.2.1",
"ports": [
{
"containerPort": 8080,
"protocol": "TCP"
}
],
"resources": {
},
"terminationMessagePath": "/dev/termination-log",
"imagePullPolicy": "IfNotPresent",
"capabilities": {},
"securityContext": {
"capabilities": {},
"privileged": false
}
}
],
"restartPolicy": "Always",
"dnsPolicy": "ClusterFirst",
"serviceAccount": ""
},
"status": {}
}
10. Create pod using pod5.json file
oc create -f pod5.json
11.View the POD’s details:
oc describe pod openshift-testmaciej
12. And that’s it. Because we defined the quota with a POD value of 1, it’s not possible to create more PODS than 1.