<1> 특정 네임스페이스에 할당 되는 자원의 범위 , 기본값지정 limitrange
<2> 삭제
<3> 범위 넘어선 Pod 생성 시도
<4> limitrange 삭제
<1> 특정 네임스페이스에 할당 되는 자원의 범위 , 기본값지정 limitrange
각 컨테이너에 적용
1
topasvga@cloudshell:~ (ap-seoul-1)$ cat << EOF > limitrange.yaml
> apiVersion: v1
> kind: LimitRange
> metadata:
> name: limit-range
> spec:
> limits:
> - default: # 1. 자동으로 설정될 기본 Limit 값
> memory: 256Mi
> cpu: 250m
> defaultRequest: # 2. 자동으로 설정될 기본 Request 값
> memory: 128Mi
> cpu: 125m
> max: # 3. 자원 할당량의 최대값
> memory: 0.5Gi
> cpu: 500m
> min: # 4. 자원 할당량의 최소값
> memory: 100Mi
> cpu: 100m
> type: Container # 5. 각 컨테이너에 적용
> EOF
2
topasvga@cloudshell:~ (ap-seoul-1)$ kubectl apply -f limitrange.yaml
limitrange/limit-range created
3
topasvga@cloudshell:~ (ap-seoul-1)$ kubectl get limitranges
NAME CREATED AT
limit-range 2023-02-23T01:13:44Z
4
topasvga@cloudshell:~ (ap-seoul-1)$ kubectl describe limitranges limit-range
Name: limit-range
Namespace: default
Type Resource Min Max Default Request Default Limit Max Limit/Request Ratio
-------- -------- --- --- --------------------------------------- ------------- ---------
Container cpu 100m 500m 125m 250m -
Container memory 100Mi 512Mi 128Mi 256Mi -
5
topasvga@cloudshell:~ (ap-seoul-1)$ kubectl run webpod --image nginx
pod/webpod created
6
topasvga@cloudshell:~ (ap-seoul-1)$ kubectl get pods
NAME READY STATUS RESTARTS AGE
webpod 1/1 Running 0 27s
7
topasvga@cloudshell:~ (ap-seoul-1)$ kubectl describe pod webpod | grep Limits -A 5
Limits:
cpu: 250m
memory: 256Mi
Requests:
cpu: 125m
memory: 128Mi
8
topasvga@cloudshell:~ (ap-seoul-1)$ kubectl delete pod webpod
pod "webpod" deleted
<3> 범위 넘어선 Pod 생성 시도
1
topasvga@cloudshell:~ (ap-seoul-1)$ cat << EOF > pod-exceed.yaml
> apiVersion: v1
> kind: Pod
> metadata:
> name: pod-exceed
> spec:
> containers:
> - name: ubuntu
> image: ubuntu
> command: ["tail"]
> args: ["-f", "/dev/null"]
> resources:
> limits:
> memory: "800Mi"
> cpu: "750m"
> requests:
> memory: "500Mi"
> cpu: "500m"
> EOF
2
topasvga@cloudshell:~ (ap-seoul-1)$ kubectl apply -f pod-exceed.yaml
Error from server (Forbidden): error when creating "pod-exceed.yaml": pods "pod-exceed" is forbidden: [maximum cpu usage per Container is 500m, but limit is 750m, maximum memory usage per Container is 512Mi, but limit is 800Mi]
3
topasvga@cloudshell:~ (ap-seoul-1)$ kubectl delete -f limitrange.yaml
limitrange "limit-range" deleted
감사합니다.