LimitRange는 namespace에서 Request와 Limit 사이의 비율을 계산, 저장 또는 적용하는데 사용된다. 이 섹션에서는 컴퓨터 워크로드를 low-usage, high-usage 그리고 unrestricted-usage로 구분한다.
먼저 분리된 Namespace를 만든다.
mkdir ~/environment/resource-management
kubectl create namespace low-usage
kubectl create namespace high-usage
kubectl create namespace unrestricted-usage
ㅁ Create Limit Range
low-usage와 high-usage namespace level에 대한 LimitRange spec을 만든다. unrestricted-usage는 어떤 제한도 적용되지 않는다.
cat <<EoF > ~/environment/resource-management/low-usage-limit-range.yml
apiVersion: v1
kind: LimitRange
metadata:
name: low-usage-range
spec:
limits:
- max:
cpu: 1
memory: 300M
min:
cpu: 0.5
memory: 100M
type: Container
EoF
kubectl apply -f ~/environment/resource-management/low-usage-limit-range.yml --namespace low-usage
cat <<EoF > ~/environment/resource-management/high-usage-limit-range.yml
apiVersion: v1
kind: LimitRange
metadata:
name: high-usage-range
spec:
limits:
- max:
cpu: 2
memory: 2G
min:
cpu: 1
memory: 1G
type: Container
EoF
kubectl apply -f ~/environment/resource-management/high-usage-limit-range.yml --namespace high-usage
ㅁ Deploy Pods
실패 시도
# Error due to higher memory request than defined in low-usage namespace: wanted 1g memory above max of 300m
kubectl run --namespace low-usage --requests=memory=1G,cpu=0.5 --image hande007/stress-ng basic-request-pod --restart=Never -- --vm-keep --vm-bytes 2g --timeout 600s --vm 1 --oomable --verbose
# Error due to lower cpu request than defined in high-usage namespace: wanted 0.5 below min of 1
kubectl run --namespace high-usage --requests=memory=1G,cpu=0.5 --image hande007/stress-ng basic-request-pod --restart=Never -- --vm-keep --vm-bytes 2g --timeout 600s --vm 1 --oomable --verbose
ㅇ
eksuser:~/environment $ kubectl run --namespace low-usage --requests=memory=1G,cpu=0.5 --image hande007/stress-ng basic-request-pod --restart=Never -- --vm-keep --vm-bytes 2g --timeout 600s --vm 1 --oomable --verbose
The Pod "basic-request-pod" is invalid: spec.containers[0].resources.requests: Invalid value: "1G": must be less than or equal to memory limit
eksuser:~/environment $ kubectl run --namespace high-usage --requests=memory=1G,cpu=0.5 --image hande007/stress-ng basic-request-pod --restart=Never -- --vm-keep --vm-bytes 2g --timeout 600s --vm 1 --oomable --verbose
Error from server (Forbidden): pods "basic-request-pod" is forbidden: minimum cpu usage per Container is 1, but request is 500m
성공 시도
kubectl run --namespace low-usage --image hande007/stress-ng low-usage-pod --restart=Never -- --vm-keep --vm-bytes 200m --timeout 600s --vm 2 --oomable --verbose
kubectl run --namespace high-usage --image hande007/stress-ng high-usage-pod --restart=Never -- --vm-keep --vm-bytes 200m --timeout 600s --vm 2 --oomable --verbose
kubectl run --namespace unrestricted-usage --image hande007/stress-ng unrestricted-usage-pod --restart=Never -- --vm-keep --vm-bytes 200m --timeout 600s --vm 2 --oomable --verbose
Pod Limit 검증
eval 'kubectl -n='{low-usage,high-usage,unrestricted-usage}' get pod -o=custom-columns='Name:spec.containers[*].name','Namespace:metadata.namespace','Limits:spec.containers[*].resources.limits';'
eksuser:~/environment $ eval 'kubectl -n='{low-usage,high-usage,unrestricted-usage}' get pod -o=custom-columns='Name:spec.containers[*].name','Namespace:metadata.namespace','Limits:spec.containers[*].resources.limits';'
Name Namespace Limits
low-usage-pod low-usage map[cpu:1 memory:300M]
Name Namespace Limits
high-usage-pod high-usage map[cpu:2 memory:2G]
Name Namespace Limits
unrestricted-usage-pod unrestricted-usage <none>
Clean up
kubectl delete namespace low-usage
kubectl delete namespace high-usage
kubectl delete namespace unrestricted-usage
'AWS EKS 실습 > EKS Intermediate' 카테고리의 다른 글
CI/CD with CodePipeline (다시 볼것) (0) | 2021.03.19 |
---|---|
Deploying Jenkins for Kubernetes (0) | 2021.03.19 |
Pod Priority And Preemption (0) | 2021.03.18 |
Resource Quotas (0) | 2021.03.18 |
Resource management 기본 (0) | 2021.03.18 |