Create a namespace named limited configured so that:
lab157deploy.There are two different places where memory requests appear in Kubernetes:
This answers:
What does this individual pod want?
resources:
requests:
memory: 32Mi
This answers:
How much can the entire namespace consume?
spec:
hard:
requests.memory: 1Gi
resources.requests.memoryrequests.memory
kubectl create ns limited
Create quota.yaml:
apiVersion: v1
kind: ResourceQuota
metadata:
name: quota
namespace: limited
spec:
hard:
pods: "5"
requests.memory: 1Gi
Apply it:
kubectl apply -f quota.yaml
To enforce that every container requests at least 32Mi memory.
Create limitrange.yaml:
apiVersion: v1
kind: LimitRange
metadata:
name: mem-limit
namespace: limited
spec:
limits:
- type: Container
min:
memory: 32Mi
Apply it:
kubectl apply -f limitrange.yaml
Create deploy.yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: lab157deploy
namespace: limited
spec:
replicas: 3
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: nginx
image: nginx
resources:
requests:
memory: 32Mi
Apply it:
kubectl apply -f deploy.yaml
kubectl get resourcequota -n limited kubectl describe resourcequota quota -n limited
kubectl get limitrange -n limited kubectl describe limitrange mem-limit -n limited
kubectl get deploy,pods -n limited
If you forget the YAML during the exam:
kubectl explain resourcequota.spec.hard
This often reminds you of:
pods requests.cpu requests.memory limits.cpu limits.memory
For LimitRange:
kubectl explain limitrange.spec.limits
pods: requests.cpu: requests.memory: limits.cpu: limits.memory:
These are by far the most commonly used ResourceQuota fields encountered in CKA troubleshooting and configuration tasks.