Notice
Recent Posts
Recent Comments
Link
«   2024/09   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
Tags
more
Archives
Today
Total
관리 메뉴

클라우드 엔지니어 꿈나무

kubernetesKubernetes(K8S) 따배쿠 Pod : Pod에 Resource 할당하기 본문

kubernetes

kubernetesKubernetes(K8S) 따배쿠 Pod : Pod에 Resource 할당하기

새싹싹이 2023. 10. 18. 22:47

리소스 제한을 걸지 않으면 pod 하나가 cpu(core)와 memory를 다 쓸 수 있음

pod가 실제 cpu memory를 얼마나 쓰는지 확인하고 제한이 필요

특정 컨테이너 하나를 실행하기 위해 scheduler가 node 들 중 택 1 해서 배치할 때  request/limit을 통해서 resource 제한 가능. ex) cpu는 500mc memory 100mb 여유가 있는 곳 배치 요청

resource request  : 파드를 실행하기 위한 최소한의 리소스 양을 요청

resource Limits : 파드가 사용할 수 있는 최대 리소스 양을 제한

Memory limit 을 초과하는 경우,  사용되는 파드를 종료하여 다시 스케쥴링 

 

 

# vi pod-nginx-resources.yaml

apiVersion: v1
kind: Pod
metadata:
  name: nginx-pod-env
spec:
  containers:
  - name: nginx-container
    image: nginx:1.14
    ports:
    - containerPort: 80
      protocol: TCP
    resources: #이 만큼의 여유가 있는 node에 배치해줘
      requests:
        memory: 500Mi
        cpu: 1 #200밀리코아
      #limits:
       # memory: 500Mi
        #cpu: 1 #코어 개수

#pod 에 컨테이너 별로 resource 설정
#cpu는 코어 수로 카운트  0번 core 1번 core  또는 mc
#1 core를 mc 단위 = 1000mc

# kubectl apply -f pod-nginx-resources.yaml -n alone

# watch kubectl get pods -n alone -o wide

# kubectl describe pod nginx-pod-env -n alone

# vi pod-nginx-resources2.yaml 

apiVersion: v1
kind: Pod
metadata:
  name: nginx-pod-resources
spec:
  containers:
  - name: nginx-container
    image: nginx:1.14
    ports:
    - containerPort: 80
      protocol: TCP
    resources:
      limits:
        memory: 500Mi
        cpu: 1

# kubectl apply -f pod-nginx-resources2.yaml -n alone

# watch kubectl get pods -n alone -o wide

# kubectl describe pod nginx-pod-resources -n alone

limits 만 기재하였는데 Requests도 같이 적용된 것을 확인할 수 있음

limits을 설정한 경우, request 부분은 자동으로 적용된다.

 

# vi pod-nginx-resources3.yaml 

apiVersion: v1
kind: Pod
metadata:
  name: nginx-pod-resources3
spec:
  containers:
  - name: nginx-container
    image: nginx:1.14
    ports:
    - containerPort: 80
      protocol: TCP
    resources:
      requests:
        memory: 500Mi
        cpu: 2

node 들의 cpu가 2개인데 해당 request 부분을 2개로 걸어줌

# kubectl create -f pod-nginx-resources3.yaml -n alone

# watch kubectl get pods -n alone -o wide

cpu가 2개 여유 공간인 node가 없기 때문에 만들어지지 않고 계속 pending 상태로 남아있는 것을 확인할 수 있음

# vi pod-nginx-resources4.yaml

apiVersion: v1
kind: Pod
metadata:
  name: nginx-pod-resources4
spec:
  containers:
  - name: nginx-container
    image: nginx:1.14
    ports:
    - containerPort: 80
      protocol: TCP
    resources: 
      requests:
        memory: 500Mi
        cpu: 200m 
      limits:
        memory: 1Gi
        cpu: 1

requests및 limits 두 개 모두 적용

# kubectl create -f pod-nginx-resources4.yaml -n alone

# watch kubectl get pods -n alone -o wide

# kubectl describe pod nginx-pod-resources4 -n alone

 

<<출처>>

https://youtu.be/lxCtyWPsb-0?si=11aGcHWhd52GELpK