적당한 이미지를 deploy한다.



$ kubectl create deployment hog --image vish/stress

deployment.apps/hog created





$ kubectl get deployments

NAME      DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE

hog       1         1         1            1           7m





$ kubectl describe deployment hog

Name:                   hog

Namespace:              default

CreationTimestamp:      Mon, 26 Nov 2018 20:32:09 +0900

Labels:                 app=hog

Annotations:            deployment.kubernetes.io/revision=2

Selector:               app=hog

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=hog

  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:   hog-58d797c5d8 (1/1 replicas created)

Events:

  Type    Reason             Age   From                   Message

  ----    ------             ----  ----                   -------

  Normal  ScalingReplicaSet  8m    deployment-controller  Scaled up replica set hog-5cc4fdb68 to 1

  Normal  ScalingReplicaSet  2m    deployment-controller  Scaled up replica set hog-58d797c5d8 to 1

  Normal  ScalingReplicaSet  2m    deployment-controller  Scaled down replica set hog-5cc4fdb68 to 0




이를 yaml로 변경할 수 있다. 배포형태로 변경 가능하다.



$ kubectl get deployment hog -o yaml

apiVersion: extensions/v1beta1

kind: Deployment

metadata:

  annotations:

    deployment.kubernetes.io/revision: "2"

  creationTimestamp: 2018-11-26T10:32:09Z

  generation: 2

  labels:

    app: hog

  name: hog

  namespace: default

  resourceVersion: "6576"

  selfLink: /apis/extensions/v3/namespaces/default/deployments/hog

  uid: 873e80d8-f166-11e8-9a46-fa163e964181

spec:

  progressDeadlineSeconds: 600

  replicas: 1

  revisionHistoryLimit: 10

  selector:

    matchLabels:

      app: hog

  strategy:

    rollingUpdate:

      maxSurge: 25%

      maxUnavailable: 25%

    type: RollingUpdate

  template:

    metadata:

      creationTimestamp: null

      labels:

        app: hog

    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: 2018-11-26T10:32:15Z

    lastUpdateTime: 2018-11-26T10:32:15Z

    message: Deployment has minimum availability.

    reason: MinimumReplicasAvailable

    status: "True"

    type: Available

  - lastTransitionTime: 2018-11-26T10:32:09Z

    lastUpdateTime: 2018-11-26T10:38:33Z

    message: ReplicaSet "hog-58d797c5d8" has successfully progressed.

    reason: NewReplicaSetAvailable

    status: "True"

    type: Progressing

  observedGeneration: 2

  readyReplicas: 1

  replicas: 1

  updatedReplicas: 1



설정 파일을 다운받고 deployment를 다시 진행한다.



$ kubectl get deployment hog --export -o yaml > hog.yaml


$ vi hog.yaml


resources: {} 부분을 다음과 같이 변경한다


resources: 

  limits:

    memory: "4Gi"

  requests:

    memory: "2500Mi"





이제 변경된 내용으로 배포한다.



$ kubectl replace -f hog.yaml



반영된 부분을 확인할 수 있다. 


$ kubectl get deployment hog -o yaml


  resources:

          limits:

            memory: 4Gi

          requests:

            memory: 2500Mi



pod는 잘 동작하고 있다.



$ kubectl get po

NAME                   READY     STATUS    RESTARTS   AGE

hog-58d797c5d8-r5lvd   1/1       Running   0          9m

$ kubectl logs hog-58d797c5d8-r5lvd

I1126 10:38:33.299667       1 main.go:26] Allocating "0" memory, in "4Ki" chunks, with a 1ms sleep between allocations

I1126 10:38:33.299827       1 main.go:29] Allocated "0" memory




자원 스트레스를 주기 위해 resources 설정을 변경한다.



        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"



그리고 deployment을 삭제하고 생성한다.


$ kubectl delete deployment hog

deployment.extensions "hog" deleted


$ kubectl apply -f hog.yaml

deployment.extensions/hog created


$ kubectl get pod

NAME                  READY     STATUS    RESTARTS   AGE

hog-786d4f7b8-mccsn   1/1       Running   0          44s


$ kubectl logs hog-786d4f7b8-mccsn

I1126 10:51:52.311973       1 main.go:26] Allocating "950Mi" memory, in "100Mi" chunks, with a 1s sleep between allocations

I1126 10:51:52.312143       1 main.go:39] Spawning a thread to consume CPU

I1126 10:51:52.312179       1 main.go:39] Spawning a thread to consume CPU

I1126 10:52:05.368902       1 main.go:29] Allocated "950Mi" memory






출처 : linux foundation 공부 자료에서 

Posted by 김용환 '김용환'

댓글을 달아 주세요