brunch

You can make anything
by writing

- C.S.Lewis -

by Master Seo Apr 24. 2022

168. GKE  리소스 제한, 쿼터제한(5/6)


<1>  쿼터  설정

<2>   CPU  와  Memory Quota  설정




<1> 쿼터  설정


1

namespace=front-a에  pod 2개까지만  생성 가능하도록  제한을 걸어보자~


kubectl create quota test-quota --hard=count/pods=2,count/services.loadbalancers=1 --namespace=front-a


[topasseoseo1@instance-4 ~]$ kubectl create quota test-quota --hard=count/pods=2,count/services.loadbalancers=1 --namespace=front-a

resourcequota/test-quota created


2

pod 생성

kubectl run app-server-2 --image=centos --namespace=front-a -- sleep infinity


[topasseoseo1@instance-4 ~]$ kubectl run app-server-2 --image=centos --namespace=front-a -- sleep infinity

pod/app-server-2 created


[topasseoseo1@instance-4 ~]$ kubectl get pods

NAME           READY   STATUS    RESTARTS   AGE

app-server     1/1     Running   0          30m

app-server-2   1/1     Running   0          17s



3

추가 pod 생성 ?

안된다.

제한을 2개로 설정해 놓아서~~


kubectl run app-server-3 --image=centos --namespace=front-a -- sleep infinity


[topasseoseo1@instance-4 ~]$ kubectl run app-server-3 --image=centos --namespace=front-a -- sleep infinity

Error from server (Forbidden): pods "app-server-3" is forbidden: exceeded quota: test-quota, requested: count/pods=1, used: count/pods=2, limited: count/pods=2




4

쿼터수 확인 ?


kubectl describe quota test-quota --namespace=front-a


[topasseoseo1@instance-4 ~]$ kubectl describe quota test-quota --namespace=front-a

Name:                         test-quota

Namespace:                    front-a

Resource                      Used  Hard

--------                      ----  ----

count/pods                    2     2

count/services.loadbalancers  0     1



5

2개에서 22개로 쿼터를 변경해 보자~


sudo yum install nano -y

export KUBE_EDITOR="nano"

kubectl edit quota test-quota --namespace=front-a


편집

ctrl + x

y

<엔터>




6

쿼터수 확인

kubectl describe quota test-quota --namespace=front-a


[topasseoseo1@instance-4 ~]$ kubectl describe quota test-quota --namespace=front-a

Name:                         test-quota

Namespace:                    front-a

Resource                      Used  Hard

--------                      ----  ----

count/pods                    2     22

count/services.loadbalancers  0     1





<2>   CPU  와  Memory Quota  설정


1

cat << EOF > cpu-mem-quota.yaml

apiVersion: v1

kind: ResourceQuota

metadata:

  name: cpu-mem-quota

  namespace: front-a

spec:

  hard:

    limits.cpu: "4"

    limits.memory: "12Gi"

    requests.cpu: "2"

    requests.memory: "8Gi"

EOF


kubectl create -f cpu-mem-quota.yaml


[topasseoseo1@instance-4 ~]$ kubectl create -f cpu-mem-quota.yaml

resourcequota/cpu-mem-quota created


[topasseoseo1@instance-4 ~]$ kubectl get pods

NAME           READY   STATUS    RESTARTS   AGE

app-server     1/1     Running   0          42m

app-server-2   1/1     Running   0          13m



2

cat << EOF > cpu-mem-demo-pod.yaml

apiVersion: v1

kind: Pod

metadata:

  name: cpu-mem-demo

  namespace: front-a

spec:

  containers:

  - name: cpu-mem-demo-ctr

    image: nginx

    resources:

      requests:

        cpu: "100m"

        memory: "128Mi"

      limits:

        cpu: "400m"

        memory: "512Mi"

EOF



kubectl create -f cpu-mem-demo-pod.yaml --namespace=front-a


[topasseoseo1@instance-4 ~]$ kubectl get pods

NAME           READY   STATUS    RESTARTS   AGE

app-server     1/1     Running   0          49m

app-server-2   1/1     Running   0          20m

cpu-mem-demo   1/1     Running   0          15s



3

kind: ResourceQuota 의 cpu-mem-quota   라는 쿼터 이름이다.


kubectl describe quota cpu-mem-quota --namespace=front-a


[topasseoseo1@instance-4 ~]$ kubectl describe quota cpu-mem-quota --namespace=front-a

Name:            cpu-mem-quota

Namespace:       front-a

Resource         Used   Hard

--------         ----   ----

limits.cpu       400m   4

limits.memory    512Mi  12Gi

requests.cpu     100m   2

requests.memory  128Mi  8Gi





4

다음자료


https://brunch.co.kr/@topasvga/2382




5

같이 볼만한 자료


https://brunch.co.kr/@topasvga/1727



https://brunch.co.kr/@topasvga/1835


https://brunch.co.kr/@topasvga/2383


다음과정

https://brunch.co.kr/@topasvga/2382






감사합니다.

매거진의 이전글 167. GKE에서 네임스페이스 생성(4/6)

매거진 선택

키워드 선택 0 / 3 0

댓글여부

afliean
브런치는 최신 브라우저에 최적화 되어있습니다. IE chrome safari