IT/쿠버네티스 / / 2020. 1. 29.

[kubernetes-실습] deployment 의 CPU, Memory 제약

포스팅 목차

    deployment 의 리소스 제약 실습해보기

    stress tool을 사용하여  실습해 보자.
    먼저 stress container yaml 파일을 만들어 제약 조건을 yaml 파일에 추가하면서 테스트 해본다.

    기본으로 stress app 배포

    ps0107@k8smaster1:~$ kubectl create deployment stress --image vish/stress
    deployment.apps/stress created

     

    deployment 리소스 확인

    ps0107@k8smaster1:~$ kubectl get deployment                                                                                               
    NAME     READY   UP-TO-DATE   AVAILABLE   AGE
    stress   1/1     1            1           9s

     

    stress 객체 자세히 보기

    ps0107@k8smaster1:~$ kubectl describe deployment stress                                                                                   
    Name:                   stress
    Namespace:              default
    CreationTimestamp:      Wed, 29 Jan 2020 06:49:09 +0000
    Labels:                 app=stress
    Annotations:            deployment.kubernetes.io/revision: 1
    Selector:               app=stress
    Replicas:               1 desired | 1 updated | 1 total | 1 available | 0 unavailable
    StrategyType:           RollingUpdate
    MinReadySeconds:        0
    RollingUpdateStrategy:  25% max unavailable, 25% max surge
    Pod Template:
      Labels:  app=stress
      Containers:
       stress:
        Image:        vish/stress
        Port:         <none>
        Host Port:    <none>
        Environment:  <none>
        Mounts:       <none>
      Volumes:        <none>
    Conditions:
      Type           Status  Reason
      ----           ------  ------
      Available      True    MinimumReplicasAvailable
      Progressing    True    NewReplicaSetAvailable
    OldReplicaSets:  <none>
    NewReplicaSet:   stress-6678575566 (1/1 replicas created)
    Events:
      Type    Reason             Age   From                   Message
      ----    ------             ----  ----                   -------
      Normal  ScalingReplicaSet  30s   deployment-controller  Scaled up replica set stress-6678575566 to 1

     

    stress 리소스에서 yaml 형태 정보 보기

    ps0107@k8smaster1:~$ kubectl get deployment stress -o yaml                                                                                
    apiVersion: extensions/v1beta1
    kind: Deployment
    metadata:
      annotations:
        deployment.kubernetes.io/revision: "1"
      creationTimestamp: "2020-01-29T06:49:09Z"
      generation: 1
      labels:
        app: stress
      name: stress
      namespace: default
      resourceVersion: "108105"
      selfLink: /apis/extensions/v1beta1/namespaces/default/deployments/stress
      uid: 9336e33d-f185-4184-bcc1-e10c01e6cce0
    spec:
      progressDeadlineSeconds: 600
      replicas: 1
      revisionHistoryLimit: 10
      selector:
        matchLabels:
          app: stress
      strategy:
        rollingUpdate:
          maxSurge: 25%
          maxUnavailable: 25%
        type: RollingUpdate
      template:
        metadata:
          creationTimestamp: null
          labels:
            app: stress
        spec:
          containers:
          - image: vish/stress
            imagePullPolicy: Always
            name: stress
            resources: {}
            terminationMessagePath: /dev/termination-log
            terminationMessagePolicy: File
          dnsPolicy: ClusterFirst
          restartPolicy: Always
          schedulerName: default-scheduler
          securityContext: {}
          terminationGracePeriodSeconds: 30
    status:
      availableReplicas: 1
      conditions:
      - lastTransitionTime: "2020-01-29T06:49:13Z"
        lastUpdateTime: "2020-01-29T06:49:13Z"
        message: Deployment has minimum availability.
        reason: MinimumReplicasAvailable
        status: "True"
        type: Available
      - lastTransitionTime: "2020-01-29T06:49:09Z"
        lastUpdateTime: "2020-01-29T06:49:13Z"
        message: ReplicaSet "stress-6678575566" has successfully progressed.
        reason: NewReplicaSetAvailable
        status: "True"
        type: Progressing
      observedGeneration: 1
      readyReplicas: 1
      replicas: 1
      updatedReplicas: 1

     

    stress 리소스로 부터 yaml 템플릿 생성하기

    ps0107@k8smaster1:~$ kubectl get deployment stress --export -o yaml > stress.yaml                                                         
    Flag --export has been deprecated, This flag is deprecated and will be removed in future.
    
    # stress yaml 파일 설정에 resource 의 memory 설정 추가하기
    ps0107@k8smaster1:~$ vi stress.yaml    
    ....    
          resources:
              limits:
                memory: 4Gi
              requests:
                memory: 2500Mi
    ....

     

    현재 설정되어 있는 stress 리소스 업데이트

    ps0107@k8smaster1:~$ kubectl replace -f stress.yaml 
    deployment.extensions/stress replaced

     

    업데이트 된 stress 리소스에 수정 사항 반영 되었는지 확인해보기

    ps0107@k8smaster1:~$ kubectl get deployment stress -o yaml                                                                               
    apiVersion: extensions/v1beta1
    kind: Deployment
    metadata:
      annotations:
        deployment.kubernetes.io/revision: "2"
      creationTimestamp: "2020-01-29T06:49:09Z"
      generation: 2
      labels:
        app: stress
      name: stress
      namespace: default
      resourceVersion: "108620"
      selfLink: /apis/extensions/v1beta1/namespaces/default/deployments/stress
      uid: 9336e33d-f185-4184-bcc1-e10c01e6cce0
    spec:
      progressDeadlineSeconds: 600
      replicas: 1
      revisionHistoryLimit: 10
      selector:
        matchLabels:
          app: stress
      strategy:
        rollingUpdate:
          maxSurge: 25%
          maxUnavailable: 25%
        type: RollingUpdate
      template:
        metadata:
          creationTimestamp: null
          labels:
            app: stress
        spec:
          containers:
          - image: vish/stress
            imagePullPolicy: Always
            name: stress
            resources:
              limits:
                memory: 4Gi
              requests:
                memory: 2500Mi
            terminationMessagePath: /dev/termination-log
            terminationMessagePolicy: File
          dnsPolicy: ClusterFirst
          restartPolicy: Always
          schedulerName: default-scheduler
          securityContext: {}
          terminationGracePeriodSeconds: 30
    status:
      availableReplicas: 1
      conditions:
      - lastTransitionTime: "2020-01-29T06:49:13Z"
        lastUpdateTime: "2020-01-29T06:49:13Z"
        message: Deployment has minimum availability.
        reason: MinimumReplicasAvailable
        status: "True"
        type: Available
      - lastTransitionTime: "2020-01-29T06:49:09Z"
        lastUpdateTime: "2020-01-29T06:55:17Z"
        message: ReplicaSet "stress-5454644b8d" has successfully progressed.
        reason: NewReplicaSetAvailable
        status: "True"
        type: Progressing
      observedGeneration: 2
      readyReplicas: 1
      replicas: 1
      updatedReplicas: 1

     

    현재 pod 리스트 확인

    ps0107@k8smaster1:~$ kubectl get po
    NAME                      READY   STATUS    RESTARTS   AGE
    stress-5454644b8d-vlpwf   1/1     Running   0          51s

     

    특정 파드에 대한 로그 확인하기

    ps0107@k8smaster1:~$ kubectl logs stress-5454644b8d-vlpwf 
    I0129 06:55:16.672508       1 main.go:26] Allocating "0" memory, in "4Ki" chunks, with a 1ms sleep between allocations
    I0129 06:55:16.672581       1 main.go:29] Allocated "0" memory

     

    stress.yaml 파일 resource 설정에 cpu 추가하기

    stress를 주기위해 args를 추가한다.

    ps0107@k8smaster1:~$ vi stress.yaml 
    ....
            resources: 
              limits:
                cpu: "1"
                memory: "4Gi"
              requests:
                cpu: "0.5"
                memory: "500Mi"
            args:
            - -cpus
            - "2"
            - -mem-total
            - "950Mi"
            - -mem-alloc-size
            - "100Mi"
            - -mem-alloc-sleep
            - "1s"
    ....

     

    수정된 내용 적용하기 위해 지우고 다시 배포

    ps0107@k8smaster1:~$ kubectl delete deployment stress                                                                                    
    deployment.extensions "stress" deleted
    
    ps0107@k8smaster1:~$ kubectl create -f stress.yaml 
    deployment.extensions/stress created

     

    생성된 pod 정보를 보고 worker 노드에 생성이 된걸 알수 있다. 

    실제 worker node에 TOP 명령으로 리소스를 확인해 본다.


    master, second node에 접속하여 top 명령 수행하여 확인하면, 즉시 memory가 100M chunk로 할당되고 cpu 사용률이 증가 됨을 확인 할 수 있다.

    ps0107@k8smaster1:~$ kubectl get pod -o wide                                                                                              
    NAME                      READY   STATUS    RESTARTS   AGE   IP            NODE         NOMINATED NODE   READINESS GATES
    stress-56444c5d8b-h4qtf   1/1     Running   0          23s   192.168.1.9   k8sworker1   <none>           <none>

     

     

     

     


    참조) CKA 대비 간단 실습

    01. kubeadm 을 이용한 설치 및 세팅
    02. kubernetes 클러스터 노드 확장 및 셋팅
    03. 간단한 application 배포, yaml템플릿, 서비스 expose 해보기
    04. deployment 의 CPU, Memory 제약
    05. namespace 를 위한 resource limit 설정
    06. 좀더 복잡한 deployment 배포해보기
    07. 기본 Node 의 maintenance (유지보수)
    08. API AND ACCESS
    09. API 객체
    10. Managing State with Deployments
    11. Service Resource
    12. Volumes and Data : ConfigMap 간단 테스트
    13. PV 와 PVC 생성
    14. ResourceQuota 사용 (PVC Count 와 Usage를 제한)
    15. ingress 간단 실습
    16. Scheduling - label 사용한 pod 할당
    17. Scheduling - Taint를 이용한 pod 배포 관리
    18. 로깅과 트러블슈팅 : 로그위치와 로그 출력 보기
    19. 로깅과 트러블슈팅 : Metrics와 DashBoard
    20. CRD (Custom Resource Definition)
    21. helm
    22. Security - TLS
    23. Security - Authentication, Authorization, Admission
    24. HA(High Availability) 구성 - master node


    • 네이버 블로그 공유
    • 네이버 밴드 공유
    • 페이스북 공유
    • 카카오스토리 공유