Exercise 4.2: Working with CPU and Memory Constraints

  1. CP 노드에 연결된 터미널로 이동

  2. Deployment 생성

    kubectl create deployment stress --image=vish/stress
  3. 위에서 생성한 Deployment를 통해서 생성된 Pod에서 실행중인 컨테이너에 부여된 리소스 할당량 확인

    kubectl get pod -l app=stress \
    -o=jsonpath='{.items[0]..spec.containers[0].resources}{"\n"}'
  4. Pod의 QoS 클래스 확인

    kubectl get pod -l app=stress \
    -o=jsonpath='{.items[0].status.qosClass}{"\n"}'
  5. 생성된 Deployment의 Manifest를 YAML 형식으로 저장

    kubectl get deploy stress -o yaml > stress.yaml
  6. stress.yaml 파일의 spec.template.spec.containers[0].resources 부분을 아래와 같이 수정

    ....
          containers:
          - image: vish/stress
            imagePullPolicy: Always
            name: stress
            resources:
              limits:
                memory: "4Gi"
              requests:
                memory: "2500Mi"
            
    terminationMessagePath: /dev/termination-log
            terminationMessagePolicy: File
    ....
  7. 변경된 컨테이너 스펙을 반영

    kubectl replace -f stress.yaml
  8. 6, 7번 단계를 수행하지 않고 아래의 명령어로 대체 가능

    kubectl patch deploy stress \
    --patch '{"spec":{"template":{"spec":{"containers":[{"name":"stress","image":"vish/stress","resources":{"limits":{"memory": "4Gi"},"requests":{"memory":"2500Mi"}}}]}}}}'
  9. 수정분이 반영 됐는지 확인

    kubectl get deployment stress \
    -o=jsonpath='{.spec.template.spec.containers[0].resources}{"\n"}' | jq
  10. Pod의 QoS 클래스 확인

    kubectl get pod -l app=stress \
    -o=jsonpath='{.items[0].status.qosClass}{"\n"}'
  11. 어플리케이션 로그 확인

    kubectl logs deploy/stress
  12. Pod가 생성된 노드 확인

    kubectl get pod -l app=stress -o wide
  13. Pod가 생성된 노드의 리소스 할당 상태 확인

    kubectl describe node $(kubectl get pod -l app=stress \
    -o=jsonpath='{.items[0].spec.nodeName}')
  14. Pod가 생성된 노드에 연결된 터미널에서 top 명령어를 실행해서 리소스 사용량 확인

  15. 위에서 8번 단계를 수행한 경우 아래의 명령어 실행하고 16,17를 건너뛰고 18번으로 이동

    kubectl patch deploy stress --patch '{"spec":{"template":{"spec":{"containers":[{"name":"stress","image":"vish/stress","resources":{"limits":{"cpu":"0.5","memory":"4Gi"},"requests":{"cpu":"0.25","memory":"500Mi"}},"args":["-cpus","2","-mem-total","950Mi","-mem-alloc-size","100Mi","-mem-alloc-sleep","1s"]}]}}}}'
  16. stress.yaml 파일의 spec.template.spec.containers[0].args 부분을 아래와 같이 수정

    ....
            resources:
              limits:
                cpu: "0.5"
                memory: "4Gi"
              requests:
                cpu: "0.25"
                memory: "500Mi"
            args:
              - -cpus
              - "2"
              - -mem-total
              - "950Mi"
              - -mem-alloc-size
              - "100Mi"
              - -mem-alloc-sleep
              - "1s" 
    
    ....
  17. Deployment 삭제 후 재생성

    {
        kubectl delete deployment stress
        kubectl create -f stress.yaml
    }
  18. Stress Pod가 배포된 노드 확인

    kubectl get pod -l app=stress -o wide
  19. 해당 노드에 연결된 터미널에서 top 명령어를 실행해서 리소스 사용량 확인하고 명령어 종료

  20. Deployment 삭제

    kubectl delete deployment stress

Last updated