포스팅 목차
ReplicaSet 동작 살펴보기
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 동작
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
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
참조) 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