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

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

deployment 의 리소스 제약

  • stress tool을 사용하여 실습해 보자.
  • 먼저 stress container yaml 파일을 만들어 제약 조건을 yaml 파일에 추가하면서 테스트 해본다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# 기본으로 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>
This post is licensed under CC BY 4.0 by the author.

[kubernetes-실습] 간단한 application 배포, yaml템플릿, 서비스 expose 해보기

[kubernetes-실습] namespace 를 위한 resource limit 설정