[애플리케이션 스케줄링과 라이프사이클 관리] 컨테이너 리소스 제한 및 요구사항 설정

hi·2023년 8월 3일
0

쿠버네티스

목록 보기
46/64
post-thumbnail
post-custom-banner

컨테이너에서 리소스 요구사항

  • CPU와 메모리는 집합적으로 컴퓨팅 리소스 또는 리소스로 부름
  • CPU 및 메모리는 각각 자원 유형을 지니며 자원 유형에는 기본 단위를 사용
  • 리소스 요청 설정 방법
    spec.containers[].resources.requests.cpu
    spec.containers[].resources.requests.memory
  • 리소스 제한 설정 방법
    spec.containers[].resources.limits.cpu
    spec.containers[].resources.limits.memory
  • CPU는 코어 단위로 지정되며 메모리는 바이트 단위로 지정
자원 유형단위
CPUm(millicpu)
Memory…… Ti, Gi, Mi, Ki, T, G, M, K
  • CPU 0.5 = CPU 1개의 절반
  • CPU 0.1 = CPU 100m
  • CPU 1 = CPU 1000m
  • K, M, G의 단위는 1000씩 증가
  • Ki, Mi, Gi의 단위는 1024씩 증가

  • 환경에 따른 CPU의 의미

1 CPU = 1000 millicores/millicpu

1000m(milicores) = 1core = 1vCPU = 1AWSvCPU = 1GCP Core.
100m(milicores) = 0.1core = 0.1vCPU = 0.1AWSvCPU = 0.1GCPCore.


컨테이너에서 리소스 요구사항 yaml 작성 요령

apiVersion: v1
kind: Pod
metadata:
  name: frontend
spec:
  containers:
  - name: app
    image: images.my-company.example/app:v4
    resources:
      requests:
        memory: "64Mi"
        cpu: "250m"
      limits:
        memory: "128Mi"
        cpu: "500m"
  - name: log-aggregator
    image: images.my-company.example/log-aggregator:v6
    resources:
      requests:
        memory: "64Mi"
        cpu: "250m"
      limits:
        memory: "128Mi"
        cpu: "500m"

각 컨테이너 리소스 요구사항
request: 0.25 CPU, 64MIB of memory
limit: 0.5 CPU, 128MiB of memory

따라서 frontend 포드의 리소스 요구사항은..
request: 0.5 CPU and 128 MiB of memory
limit: 1 CPU and 256MiB of memory



연습문제

다음 요구사항에 맞는 deploy를 구현할 것

  • Deploy name: nginx
  • Image: nginx
  • 최소 요구사항
    - CPU: 1m
    • 메모리: 200Mi
  • 리소스 제한
    - CPU: 2m
    - 메모리: 400Mi
  • Port: 80

imkunyoung@master-1:~/yaml$ kubectl create deploy nginx --image=nginx --dry-run=client -o yaml > nginx.yaml

nginx.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: nginx
  name: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: nginx
    spec:
      containers:
      - image: nginx
        name: nginx
        resources: 
          requests:
            memory: "200Mi"
            cpu: "1m"
          limits:
            memory: "400Mi"
            cpu: "2m"
status: {}
imkunyoung@master-1:~/yaml$ kubectl create -f nginx.yaml
deployment.apps/nginx created
imkunyoung@master-1:~/yaml$ kubectl get pods -o wide
NAME                     READY   STATUS    RESTARTS   AGE    IP          NODE       NOMINATED NODE   READINESS GATES
nginx-7d6c69f4cd-76j58   1/1     Running   0          3m4s   10.0.1.95   worker-2   <none>           <none>


imkunyoung@master-1:~/yaml$ kubectl describe pod nginx-7d6c69f4cd-76j58
Name:             nginx-7d6c69f4cd-76j58
Namespace:        default
Priority:         0
Service Account:  default
Node:             worker-2/10.138.0.12
Start Time:       Thu, 03 Aug 2023 05:12:47 +0000
Labels:           app=nginx
                  pod-template-hash=7d6c69f4cd
Annotations:      <none>
Status:           Running
IP:               10.0.1.95
IPs:
  IP:           10.0.1.95
Controlled By:  ReplicaSet/nginx-7d6c69f4cd
Containers:
  nginx:
    Container ID:   containerd://085969f2ad5fe618e69fb0cf5998aecdbcf43b7db7b636fec34b75b5eb059757
    Image:          nginx
    Image ID:       docker.io/library/nginx@sha256:67f9a4f10d147a6e04629340e6493c9703300ca23a2f7f3aa56fe615d75d31ca
    Port:           <none>
    Host Port:      <none>
    State:          Running
      Started:      Thu, 03 Aug 2023 05:12:49 +0000
    Ready:          True
    Restart Count:  0
    Limits:
      cpu:     2m
      memory:  400Mi
    Requests:
      cpu:        1m
      memory:     200Mi
    Environment:  <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-skgzf (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             True 
  ContainersReady   True 
  PodScheduled      True 
Volumes:
  kube-api-access-skgzf:
    Type:                    Projected (a volume that contains injected data from multiple sources)
    TokenExpirationSeconds:  3607
    ConfigMapName:           kube-root-ca.crt
    ConfigMapOptional:       <nil>
    DownwardAPI:             true
QoS Class:                   Burstable
Node-Selectors:              <none>
Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                             node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type    Reason     Age    From               Message
  ----    ------     ----   ----               -------
  Normal  Scheduled  3m42s  default-scheduler  Successfully assigned default/nginx-7d6c69f4cd-76j58 to worker-2
  Normal  Pulling    3m41s  kubelet            Pulling image "nginx"
  Normal  Pulled     3m40s  kubelet            Successfully pulled image "nginx" in 601.53029ms (601.564645ms including waiting)
  Normal  Created    3m40s  kubelet            Created container nginx
  Normal  Started    3m40s  kubelet            Started container nginx


kubernetes-instance-calculator

post-custom-banner

1개의 댓글

comment-user-thumbnail
2023년 8월 3일

정보 감사합니다.

답글 달기