Exercise
-
Create a Namespace named dev
-
Create a ResourceQuota named limit-pod-number limiting the number of pods to 5 in that Namespace
-
Create a Deployment named ghost with 10 replicas based on ghost:4 in the Namespace dev
-
What do you observe ?
-
Get the events which show that some of the Pods cannot be created
-
Delete the Deployment, the ResourceQuota and the Namespace
Documentation
https://kubernetes.io/docs/concepts/policy/resource-quotas/
Solution
- Create a Namespace named dev
k create ns dev
- Create a ResourceQuota named limit-pod-number limiting the number of Pods to 5 in that Namespace
k -n dev create quota limit-pod-number --hard=pods=5
- Create a Deployment named ghost with 10 replicas based on ghost:4 in the Namespace dev
k -n dev create deploy ghost --image=ghost:4 --replicas=10
- What do you observe ?
Only 5 of the 10 replicas are running, the other ones cannot be created in the namespace because of the limitation
k -n dev get po -l app=ghost
NAME READY STATUS RESTARTS AGE
ghost-5d77b859d5-222q2 1/1 Running 0 26s
ghost-5d77b859d5-96z94 1/1 Running 0 26s
ghost-5d77b859d5-hlbbj 1/1 Running 0 26s
ghost-5d77b859d5-kbdf4 1/1 Running 0 26s
ghost-5d77b859d5-w8rfm 1/1 Running 0 26s
- Get the events which show that some of the pods cannot be created
We can get all the events in the dev namespace
k -n dev get events
To get only the one which indicate a creation failure we can add a filter on the reason field:
k -n dev get events --field-selector reason=FailedCreate
- Delete the Deployment, the ResourceQuota and the Namespace
k -n dev delete deploy/ghost quota/limit-pod-number
k delete ns dev