ReplicaSet 동작
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
# ReplicaSet 생성을 위한 yaml 파일 생성
ps0107@k8smaster1:~$ vi rs.yaml
apiVersion: extensions/v1beta1
kind: ReplicaSet
metadata:
name: rs-one
spec:
replicas: 2
template:
metadata:
labels:
system: ReplicaOne
spec:
containers:
- name: nginx
image: nginx:1.11.1
ports:
- containerPort: 80
# ReplicaSet 생성
ps0107@k8smaster1:~$ kubectl create -f rs.yaml
replicaset.extensions/rs-one created
# 생성된 ReplicaSet 상세 내용 확인
ps0107@k8smaster1:~$ kubectl describe rs rs-one
Name: rs-one
Namespace: default
Selector: system=ReplicaOne
Labels: system=ReplicaOne
Annotations: <none>
Replicas: 2 current / 2 desired
Pods Status: 0 Running / 2 Waiting / 0 Succeeded / 0 Failed
Pod Template:
Labels: system=ReplicaOne
Containers:
nginx:
Image: nginx:1.11.1
Port: 80/TCP
Host Port: 0/TCP
Environment: <none>
Mounts: <none>
Volumes: <none>
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal SuccessfulCreate 10s replicaset-controller Created pod: rs-one-dxxl2
Normal SuccessfulCreate 10s replicaset-controller Created pod: rs-one-k4nm9
# 생성된 pod 확인
ps0107@k8smaster1:~$ kubectl get pods
NAME READY STATUS RESTARTS AGE
rs-one-dxxl2 1/1 Running 0 24s
rs-one-k4nm9 1/1 Running 0 24s
# ReplicaSet 객체만 삭제하고 하위에 pod는 그냥 놔둠 (--cascade=false)
ps0107@k8smaster1:~$ kubectl delete rs rs-one --cascade=false
replicaset.extensions "rs-one" deleted
# ReplicaSet 삭제된거 확인
ps0107@k8smaster1:~$ kubectl describe rs rs-one
Error from server (NotFound): replicasets.extensions "rs-one" not found
# pod는 남아 있는지 확인
ps0107@k8smaster1:~$ kubectl get pods
NAME READY STATUS RESTARTS AGE
rs-one-dxxl2 1/1 Running 0 76s
rs-one-k4nm9 1/1 Running 0 76s
# 다시 ReplicaSet을 생성해 본다.
ps0107@k8smaster1:~$ kubectl create -f rs.yaml
replicaset.extensions/rs-one created
# 생성이 잘되었다.
ps0107@k8smaster1:~$ kubectl get rs
NAME DESIRED CURRENT READY AGE
rs-one 2 2 2 6s
# 하지만 pod는 기존에 생성했던 pod 들이다.
ps0107@k8smaster1:~$ kubectl get pod
NAME READY STATUS RESTARTS AGE
rs-one-dxxl2 1/1 Running 0 107s
rs-one-k4nm9 1/1 Running 0 107s
# pod 하나의 label을 수정해보자 (system: IsolatedPod 로..)
ps0107@k8smaster1:~$ kubectl edit po rs-one-dxxl2
pod/rs-one-dxxl2 edited
# ReplicaSet을 조회해 보면 그대로 2개 러닝중이다.
ps0107@k8smaster1:~$ kubectl get rs
NAME DESIRED CURRENT READY AGE
rs-one 2 2 2 2m6s
# pod를 system 이라는 label 로 조회해 본다.
# 수정한 거 빼고 새로 하나가 올라온걸 볼수 있다.
# 2개를 유지하려고 하고 있다.
ps0107@k8smaster1:~$ kubectl get pod -L system
NAME READY STATUS RESTARTS AGE SYSTEM
rs-one-95sch 1/1 Running 0 23s ReplicaOne
rs-one-dxxl2 1/1 Running 0 3m56s IsolatedPod
rs-one-k4nm9 1/1 Running 0 3m56s ReplicaOne
# ReplicaSet을 삭제 한다
ps0107@k8smaster1:~$ kubectl delete rs rs-one
replicaset.extensions "rs-one" deleted
# system 라벨이 IsolatedPod는 그대로 남아 있다.
ps0107@k8smaster1:~$ kubectl get pod
NAME READY STATUS RESTARTS AGE
rs-one-dxxl2 1/1 Running 0 4m26s
# ReplicaSet은 삭제 되어있다.
ps0107@k8smaster1:~$ kubectl get rs
No resources found.
ps0107@k8smaster1:~$ kubectl get po
NAME READY STATUS RESTARTS AGE
rs-one-dxxl2 1/1 Running 0 4m43s
# system=IsolatedPod 라벨링 되어 있는 pod를 삭제한다.
ps0107@k8smaster1:~$ kubectl delete po -l system=IsolatedPod
pod "rs-one-dxxl2" deleted
ps0107@k8smaster1:~$ kubectl get pod
No resources found.
DaemonSet 동작
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
# DaemonSet 생성을 위한 yaml 파일 생성
ps0107@k8smaster1:~$ cat ds.yaml
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
name: ds-one
spec:
template:
metadata:
labels:
system: ReplicaOne
spec:
containers:
- name: nginx
image: nginx:1.11.1
ports:
- containerPort: 80
# DaemonSet 생성
ps0107@k8smaster1:~$ kubectl create -f ds.yaml
daemonset.extensions/ds-one created
# 각 노드에 한개씩 러닝이라 현재 2개 확인 가능
ps0107@k8smaster1:~$ kubectl get ds
NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE
ds-one 2 2 2 2 2 <none> 4s
# 생성된 pod가 각 노드에 한개씩 러닝중이다.
ps0107@k8smaster1:~$ kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
ds-one-6sjkv 1/1 Running 0 13s 192.168.0.29 k8smaster1 <none> <none>
ds-one-hpx96 1/1 Running 0 13s 192.168.1.70 k8sworker1 <none> <none>
# 현재 러닝중인 nginx의 이미지 버전확인
ps0107@k8smaster1:~$ kubectl describe po ds-one-6sjkv | grep "Image:"
Image: nginx:1.11.1
Rolling Updates And Rollback
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# ---------------------------------------------------------------
# updateStrategy의 설정을 OnDelete 로 했을때 테스트
# ---------------------------------------------------------------
# 현재 updateStrategy 설정 확인
# OnDelete : 이미지를 변경하더라도 이전 버전을 수동 삭제해야 새로운 버전으로 생성됨.
ps0107@k8smaster1:~$ kubectl get ds ds-one -o yaml | grep -A 1 Strategy
updateStrategy:
type: OnDelete
# daemonSet의 nginx이미지 버전을 수정해보자
ps0107@k8smaster1:~$ kubectl set image ds ds-one nginx=nginx:1.12.1-alpine
daemonset.extensions/ds-one image updated
# pod들의 이미지 버전을 보면 아직 바뀐상태가 아니다.
ps0107@k8smaster1:~$ kubectl describe po ds-one-6sjkv | grep "Image:"
Image: nginx:1.11.1
# 삭제를 해야 바뀐다. 삭제를 해보자.
ps0107@k8smaster1:~$ kubectl delete po ds-one-6sjkv
pod "ds-one-6sjkv" deleted
ps0107@k8smaster1:~$ kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
ds-one-hpx96 1/1 Running 0 9m4s 192.168.1.70 k8sworker1 <none> <none>
ds-one-rvrdb 0/1 ContainerCreating 0 6s <none> k8smaster1 <none> <none>
ps0107@k8smaster1:~$ kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
ds-one-hpx96 1/1 Running 0 9m19s 192.168.1.70 k8sworker1 <none> <none>
ds-one-rvrdb 1/1 Running 0 21s 192.168.0.30 k8smaster1 <none> <none>
# 기존 pod 의 이미지버전
ps0107@k8smaster1:~$ kubectl describe po ds-one-hpx96 | grep "Image:"
Image: nginx:1.11.1
# 삭제후 새로 생성된 이미지의 버전 이다. (잘 바귄걸로 올라왔다)
ps0107@k8smaster1:~$ kubectl describe po ds-one-rvrdb | grep "Image:"
Image: nginx:1.12.1-alpine
# edit로 수정후 history를 확인 할 수도 있다.
ps0107@k8smaster1:~$ kubectl rollout history ds ds-one
daemonset.extensions/ds-one
REVISION CHANGE-CAUSE
1 <none>
2 <none>
# revision 1번은 1.11.1 이전 버전
ps0107@k8smaster1:~$ kubectl rollout history ds ds-one --revision=1
daemonset.extensions/ds-one with revision #1
Pod Template:
Labels:system=ReplicaOne
Containers:
nginx:
Image:nginx:1.11.1
Port:80/TCP
Host Port:0/TCP
Environment:<none>
Mounts:<none>
Volumes:<none>
# revision 2번은 새로 수정한 버전임을 알수 있다.
ps0107@k8smaster1:~$ kubectl rollout history ds ds-one --revision=2
daemonset.extensions/ds-one with revision #2
Pod Template:
Labels:system=ReplicaOne
Containers:
nginx:
Image:nginx:1.12.1-alpine
Port:80/TCP
Host Port:0/TCP
Environment:<none>
Mounts:<none>
Volumes:<none>
# 이전 버전인 1.11.1버전으로 rollout undo를 실행하여 본다.
ps0107@k8smaster1:~$ kubectl rollout undo ds ds-one --to-revision=1
daemonset.extensions/ds-one rolled back
# 그런데 바로 바뀌지 않는다...
ps0107@k8smaster1:~$ kubectl describe po ds-one-rvrdb | grep "Image:"
Image: nginx:1.12.1-alpine
ps0107@k8smaster1:~$ kubectl describe po ds-one-hpx96 | grep "Image:"
Image: nginx:1.11.1
# 바로 위에서 본 updateStrategy 설정 때문에 pod를 삭제 해야 다시 뜨면서 적용된다.
ps0107@k8smaster1:~$ kubectl delete po ds-one-rvrdb
pod "ds-one-rvrdb" deleted
# 삭제 후 새로 생성된 pod를 확인할 수 있다
ps0107@k8smaster1:~$ kubectl get po
NAME READY STATUS RESTARTS AGE
ds-one-65r2h 1/1 Running 0 4s
ds-one-hpx96 1/1 Running 0 12m
# 새로 생성된 pod의 이미지 버전을 확인해본다. 정상적으로 undo 되어 올라왔다.
ps0107@k8smaster1:~$ kubectl describe po ds-one-65r2h | grep "Image:"
Image: nginx:1.11.1
# 현재 ds-one 객체의 상세 정보를 확인해본다.
ps0107@k8smaster1:~$ kubectl get ds ds-one -o yaml
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
creationTimestamp: "2020-02-03T03:08:40Z"
generation: 3
labels:
system: ReplicaOne
name: ds-one
namespace: default
resourceVersion: "670771"
selfLink: /apis/extensions/v1beta1/namespaces/default/daemonsets/ds-one
uid: cd8e3a1e-8c9a-4a74-96ea-b0030e5711ae
spec:
revisionHistoryLimit: 10
selector:
matchLabels:
system: ReplicaOne
template:
metadata:
creationTimestamp: null
labels:
system: ReplicaOne
spec:
containers:
- image: nginx:1.11.1
imagePullPolicy: IfNotPresent
name: nginx
ports:
- containerPort: 80
protocol: TCP
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
templateGeneration: 3
updateStrategy:
type: OnDelete
status:
currentNumberScheduled: 2
desiredNumberScheduled: 2
numberAvailable: 2
numberMisscheduled: 0
numberReady: 2
observedGeneration: 3
updatedNumberScheduled: 2
# ---------------------------------------------------------------
# updateStrategy의 설정을 RollingUpdate 로 수정후 테스트 해보자
# ---------------------------------------------------------------
# 기존 객체에서 복사해서 name과 updateStrategy 부분을 수정해 보자
ps0107@k8smaster1:~$ kubectl get ds ds-one -o yaml --export > ds2.yaml
Flag --export has been deprecated, This flag is deprecated and will be removed in future.
ps0107@k8smaster1:~$ vi ds2.yaml
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
creationTimestamp: null
generation: 1
labels:
system: ReplicaOne
name: ds-two
selfLink: /apis/extensions/v1beta1/namespaces/default/daemonsets/ds-one
spec:
revisionHistoryLimit: 10
selector:
matchLabels:
system: ReplicaOne
template:
metadata:
creationTimestamp: null
labels:
system: ReplicaOne
spec:
containers:
- image: nginx:1.11.1
imagePullPolicy: IfNotPresent
name: nginx
ports:
- containerPort: 80
protocol: TCP
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
templateGeneration: 3
updateStrategy:
type: RollingUpdate
status:
currentNumberScheduled: 0
desiredNumberScheduled: 0
numberMisscheduled: 0
numberReady: 0
# 새로운 ds-two객체를 생성해 보자.
ps0107@k8smaster1:~$ kubectl create -f ds2.yaml
daemonset.extensions/ds-two created
# 새로 pod가 2개 생성되었다.
ps0107@k8smaster1:~$ kubectl get po
NAME READY STATUS RESTARTS AGE
ds-one-65r2h 1/1 Running 0 4m30s
ds-one-hpx96 1/1 Running 0 16m
ds-two-49d8t 1/1 Running 0 6s
ds-two-sgpdh 1/1 Running 0 6s
# 생성된 pod의 이미지 버전을 확인해보자 (1.11.1 이다)
ps0107@k8smaster1:~$ kubectl describe po ds-two-49d8t | grep "Image:"
Image: nginx:1.11.1
# edit 명령으로 이미지 버전을 수정해 보자 (1.12.1-alpine으로)
ps0107@k8smaster1:~$ kubectl edit ds ds-two
daemonset.extensions/ds-two edited
# ds-two의 상태 확인
ps0107@k8smaster1:~$ kubectl get ds ds-two
NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE
ds-two 2 2 1 1 1 <none> 82s
# 생성된 pod를 확인해 본다.
ps0107@k8smaster1:~$ kubectl get pod
NAME READY STATUS RESTARTS AGE
ds-one-65r2h 1/1 Running 0 6m8s
ds-one-hpx96 1/1 Running 0 18m
ds-two-2px2q 1/1 Running 0 19s
ds-two-kpsfx 1/1 Running 0 35s
# 두개의 pod 가 버전이 수정된걸로 다시 생성되었다.
ps0107@k8smaster1:~$ kubectl describe po ds-two-2px2q | grep "Image:"
Image: nginx:1.12.1-alpine
ps0107@k8smaster1:~$ kubectl describe po ds-two-kpsfx | grep "Image:"
Image: nginx:1.12.1-alpine
# rollout 된 상태 확인
ps0107@k8smaster1:~$ kubectl rollout status ds ds-two
daemon set "ds-two" successfully rolled out
ps0107@k8smaster1:~$ kubectl rollout history ds ds-two
daemonset.extensions/ds-two
REVISION CHANGE-CAUSE
1 <none>
2 <none>
ps0107@k8smaster1:~$ kubectl rollout history ds ds-two --revision=2
daemonset.extensions/ds-two with revision #2
Pod Template:
Labels:system=ReplicaOne
Containers:
nginx:
Image:nginx:1.12.1-alpine
Port:80/TCP
Host Port:0/TCP
Environment:<none>
Mounts:<none>
Volumes:<none>
# 테스트한 객체 삭제
ps0107@k8smaster1:~$ kubectl delete ds ds-two
daemonset.extensions "ds-two" deleted