본문 바로가기

Kubernetes

[Kubernetes] Pod에 Resource 할당하기

반응형

Pod Resource 요청 및 제한

 

Resource Requests

 - 파드를 실행하기 위한 최소 리소스 양을 요청

Resource Limits

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

 - memory limit을 초과해서 사용되는 파드는 종료(OOM Kill) 되며 다시 스케줄링 된다.

 

requests 설정 

 

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

 

kubectl describe pod nginx-pod-resource 
Name:             nginx-pod-resource
Namespace:        default
Priority:         0
Service Account:  default
Node:             node1.example.com/10.100.0.101
Start Time:       Fri, 02 Dec 2022 16:26:44 +0900
Labels:           <none>
Annotations:      <none>
Status:           Running
IP:               10.36.0.1
IPs:
  IP:  10.36.0.1
Containers:
  nginx-container:
    Container ID:   containerd://39b85170076be6f563793cccc3425003a49980aee7c19f99d2692be084e1ecb4
    Image:          nginx:1.14
    Image ID:       docker.io/library/nginx@sha256:f7988fb6c02e0ce69257d9bd9cf37ae20a60f1df7563c3a2a6abe24160306b8d
    Port:           80/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Fri, 02 Dec 2022 16:26:46 +0900
    Ready:          True
    Restart Count:  0
    Requests:
      cpu:        1
      memory:     500Mi
    Environment:  <none>
    Mounts:

 

limits 설정

 

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

 

limits 를 설정하면 requests는 limits 설정과 동일하게 구성

 

kubectl describe pod nginx-pod-resource 
Name:             nginx-pod-resource
Namespace:        default
Priority:         0
Service Account:  default
Node:             node1.example.com/10.100.0.101
Start Time:       Fri, 02 Dec 2022 16:29:09 +0900
Labels:           <none>
Annotations:      <none>
Status:           Running
IP:               10.36.0.1
IPs:
  IP:  10.36.0.1
Containers:
  nginx-container:
    Container ID:   containerd://7f1ccdd222dec7be0811f891f88b2e34cdbae6287e58cb44e2c616903bd0b4c7
    Image:          nginx:1.14
    Image ID:       docker.io/library/nginx@sha256:f7988fb6c02e0ce69257d9bd9cf37ae20a60f1df7563c3a2a6abe24160306b8d
    Port:           80/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Fri, 02 Dec 2022 16:29:11 +0900
    Ready:          True
    Restart Count:  0
    Limits:
      cpu:     1
      memory:  500Mi
    Requests:
      cpu:        1
      memory:     500Mi
    Environment:  <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-wf42v (ro)

 

reqeusts, limits 동시 설정

 

apiVersion: v1
kind: Pod
metadata:
  name: nginx-pod-resource
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

 

kubectl describe pod nginx-pod-resource 
Name:             nginx-pod-resource
Namespace:        default
Priority:         0
Service Account:  default
Node:             node1.example.com/10.100.0.101
Start Time:       Fri, 02 Dec 2022 16:34:20 +0900
Labels:           <none>
Annotations:      <none>
Status:           Running
IP:               10.36.0.1
IPs:
  IP:  10.36.0.1
Containers:
  nginx-container:
    Container ID:   containerd://0b9ea322634f0cc2150cfea8178c0289546195f43fd046e29871ac9cc0e7c49a
    Image:          nginx:1.14
    Image ID:       docker.io/library/nginx@sha256:f7988fb6c02e0ce69257d9bd9cf37ae20a60f1df7563c3a2a6abe24160306b8d
    Port:           80/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Fri, 02 Dec 2022 16:34:22 +0900
    Ready:          True
    Restart Count:  0
    Limits:
      cpu:     1
      memory:  1Gi
    Requests:
      cpu:        200m
      memory:     500Mi
    Environment:  <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-9k75q (ro)

 

 

[참고]

- https://www.youtube.com/watch?v=lxCtyWPsb-0&list=PLApuRlvrZKohaBHvXAOhUD-RxD0uQ3z0c&index=15

반응형