티스토리 뷰
Replicaset
실습 디렉토리 이동
cd ~/k8s/lab4-rs
1. Replicaset 확인
kubectl get replicaset
kubectl get rs
2. yaml 확인
cat rs.yaml
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: lab4-rs
spec:
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.0
3. yaml 을 활용한 replicaset 생성
kubectl create -f rs.yaml
4. replicaset, pod 확인
kubectl get rs
kubectl get pod
NAME DESIRED CURRENT READY AGE
lab4-rs 2 2 2 5s
NAME READY STATUS RESTARTS AGE
lab4-rs-kn9xf 1/1 Running 0 20m
lab4-rs-lzpb8 1/1 Running 0 20m
5. pod 1개 삭제
kubectl delete pod <pod명>
6. pod 재배포 확인
kubectl get po
NAME READY STATUS RESTARTS AGE
lab4-rs-g8lxw 1/1 Running 0 6s
lab4-rs-lzpb8 1/1 Running 0 21m
7. replicaset 삭제
kubectl delete rs --all
8. replicaset 삭제 확인
kubectl get rs
kubectl get pod
Deployment
실습 디렉토리 이동
cd ~/k8s/lab5-deploy
1. Deployment 확인
kubectl get deployment
kubectl get deploy
2. yaml 확인
cat deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: lab5-deploy
spec:
replicas: 3
strategy:
type: Recreate
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.0
ports:
- containerPort: 80
3. yaml 을 활용한 Deployment 생성
kubectl create -f deploy.yaml
4. deployment, replicaset, pod 확인
kubectl get deploy
kubectl get rs
kubectl get pod
NAME READY UP-TO-DATE AVAILABLE AGE
lab5-deploy 3/3 3 3 5s
NAME DESIRED CURRENT READY AGE
lab5-deploy-6fb8db976b 3 3 3 21s
NAME READY STATUS RESTARTS AGE
lab5-deploy-6fb8db976b-7dcx8 1/1 Running 0 33s
lab5-deploy-6fb8db976b-c8dh7 1/1 Running 0 33s
lab5-deploy-6fb8db976b-rvcxz 1/1 Running 0 33s
deployment의 ready 3개는 pod 3개 중에 3개가 준비상태라는 뜻이다.
5. pod 1개 삭제
kubectl delete pod <pod명>
6. pod 재배포 확인
kubectl get po
NAME READY STATUS RESTARTS AGE
lab5-deploy-6fb8db976b-2rzmq 1/1 Running 0 8s
lab5-deploy-6fb8db976b-c8dh7 1/1 Running 0 73s
lab5-deploy-6fb8db976b-rvcxz 1/1 Running 0 73s
7. Deployment 삭제
kubectl delete deploy --all
8. Deployment 삭제 확인
kubectl get deploy
kubectl get pod
9. 터미널을 하나 더 오픈하여 모니터링용 터미널을 생성합니다.
watch -n 0.5 kubectl get pod
Every 0.5s: kubectl get pod ip-172-31-31-56: Thu May 30 05:53:09 2024
sh: 1: kubectl: not found
10. create 명령으로 deployment 생성
-deployment 조건-
deployment name : lab5-deploy2
container image : nginx:1.14.0
container port : 80
replicas : 3
kubectl create deploy lab5-deploy2 --image=nginx:1.14.0 --port=80 --replicas=3
11. 컨테이너 이미지 1.15.0으로 버전 업데이트
kubectl set image deployment/lab5-deploy2 nginx=nginx:1.15.0 --record=true
이때 명령어 수행 직후 모니터링 터미널로 동작 확인 record=true 값으로 해야 히스토리 확인시 어떤 내용인지 확인 가능
12. 업데이트 내역 확인
kubectl describe pod
kubectl describe deploy
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 104s default-scheduler Successfully assigned default/lab5-deploy2-c54b5b8bc-xdbv5 to k8s-worker1
Normal Pulling 103s kubelet Pulling image "nginx:1.15.0"
Normal Pulled 99s kubelet Successfully pulled image "nginx:1.15.0" in 3.766s (3.766s including waiting)
Normal Created 99s kubelet Created container nginx
Normal Started 99s kubelet Started container nginx
Normal ScalingReplicaSet 2m13s deployment-controller Scaled up replica set lab5-deploy2-646c46676b to 3
Normal ScalingReplicaSet 2m3s deployment-controller Scaled up replica set lab5-deploy2-c54b5b8bc to 1
Normal ScalingReplicaSet 118s deployment-controller Scaled down replica set lab5-deploy2-646c46676b to 2 from 3
Normal ScalingReplicaSet 118s deployment-controller Scaled up replica set lab5-deploy2-c54b5b8bc to 2 from 1
Normal ScalingReplicaSet 113s deployment-controller Scaled down replica set lab5-deploy2-646c46676b to 1 from 2
Normal ScalingReplicaSet 113s deployment-controller Scaled up replica set lab5-deploy2-c54b5b8bc to 3 from 2
Normal ScalingReplicaSet 111s deployment-controller Scaled down replica set lab5-deploy2-646c46676b to 0 fr
13. 업데이트 방식 변경
kubectl edit deploy lab5-deploy2
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
를
strategy:
type: Recreate
vi 편집기 사용법과 동일합니다.
deploy 만들 때 지정하지 않으면 자동으로 rolling update가 된다.
14. 컨테이너 이미지 1.16.0 으로 버전 업데이트
kubectl set image deployment/lab5-deploy2 nginx=nginx:1.16.0 --record=true
이때 명령어 수행 직후 모니터링 터미널로 동작 확인
15. 업데이트 내역 확인
kubectl describe pod
kubectl describe deploy
Normal Scheduled 7s default-scheduler Successfully assigned default/lab5-deploy2-78dcd75f56-tjh94 to k8s-worker1
Normal Pulling 6s kubelet Pulling image "nginx:1.16.0"
Normal Pulled 2s kubelet Successfully pulled image "nginx:1.16.0" in 3.86s (3.86s including waiting)
Normal Created 2s kubelet Created container nginx
Normal Started 2s kubelet Started container nginx
Type Status Reason
---- ------ ------
Available True MinimumReplicasAvailable
Progressing True NewReplicaSetAvailable
OldReplicaSets: lab5-deploy2-646c46676b (0/0 replicas created), lab5-deploy2-c54b5b8bc (0/0 replicas created)
NewReplicaSet: lab5-deploy2-78dcd75f56 (3/3 replicas created)
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal ScalingReplicaSet 13m deployment-controller Scaled up replica set lab5-deploy2-646c46676b to 3
Normal ScalingReplicaSet 12m deployment-controller Scaled up replica set lab5-deploy2-c54b5b8bc to 1
Normal ScalingReplicaSet 12m deployment-controller Scaled down replica set lab5-deploy2-646c46676b to 2 from 3
Normal ScalingReplicaSet 12m deployment-controller Scaled up replica set lab5-deploy2-c54b5b8bc to 2 from 1
Normal ScalingReplicaSet 12m deployment-controller Scaled down replica set lab5-deploy2-646c46676b to 1 from 2
Normal ScalingReplicaSet 12m deployment-controller Scaled up replica set lab5-deploy2-c54b5b8bc to 3 from 2
Normal ScalingReplicaSet 12m deployment-controller Scaled down replica set lab5-deploy2-646c46676b to 0 from 1
Normal ScalingReplicaSet 95s deployment-controller Scaled down replica set lab5-deploy2-c54b5b8bc to 0 from 3
Normal ScalingReplicaSet 95s deployment-controller Scaled up replica
16. 롤 아웃 기록 확인
kubectl rollout history deploy/lab5-deploy2
REVISION CHANGE-CAUSE
1 <none>
2 kubectl set image deployment/lab5-deploy2 nginx=nginx:1.15.0 --record=true
3 kubectl set image deployment/lab5-deploy2 nginx=nginx:1.16.0 --recor
17. 직전 버전으로 롤백
kubectl rollout undo deploy/lab5-deploy2
18. 버전 확인
kubectl describe deploy
Pod Template:
Labels: app=lab5-deploy2
Containers:
nginx:
Image: nginx:1.15.0
Port: 80/TCP
Host Port: 0/TCP
Environment: <none>
Mounts: <none>
Volumes: <none>
Conditions:
Type Status Reason
---- ------ ------
Progressing True NewReplicaSetAvailable
Available True MinimumReplicasAvailable
OldReplicaSets: lab5-deploy2-646c46676b (0/0 replicas created), lab5-deploy2-78dcd75f56 (0/0 replicas created)
NewReplicaSet: lab5-deploy2-c54b5b8bc (3/3 replicas created)
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal ScalingReplicaSet 14m deployment-controller Scaled up replica set lab5-deploy2-646c46676b to 3
Normal ScalingReplicaSet 13m deployment-controller Scaled up replica set lab5-deploy2-c54b5b8bc to 1
Normal ScalingReplicaSet 13m deployment-controller Scaled down replica set lab5-deploy2-646c46676b to 2 from 3
Normal ScalingReplicaSet 13m deployment-controller Scaled up replica set lab5-deploy2-c54b5b8bc to 2 from 1
Normal ScalingReplicaSet 13m deployment-controller Scaled down replica set lab5-deploy2-646c46676b to 1 from 2
Normal ScalingReplicaSet 13m deployment-controller Scaled up replica set lab5-deploy2-c54b5b8bc to 3 from 2
Normal ScalingReplicaSet 13m deployment-controller Scaled down replica set lab5-deploy2-646c46676b to 0 from 1
Normal ScalingReplicaSet 2m35s deployment-controller Scaled down replica set lab5-deploy2-c54b5b8bc to 0 from 3
Normal ScalingReplicaSet 2m35s deployment-controller Scaled up replica set lab5-deploy2-78dcd75f56 to 3
Normal ScalingReplicaSet 8s deployment-controller Scaled down replica set lab5-deploy2-78dcd75f56 to 0 from 3
Normal ScalingReplicaSet 6s deployment-controller Scaled up replica set lab5-deploy2-c54b5b8bc to 3 from 0
19. 리비전 지정하여 롤백
kubectl rollout undo deploy/lab5-deploy2 --to-revision=1
20. 버전 확인
kubectl describe deploy
Pod Template:
Labels: app=lab5-deploy2
Containers:
nginx:
Image: nginx:1.14.0
Port: 80/TCP
Host Port: 0/TCP
Environment: <none>
Mounts: <none>
Volumes: <none>
Conditions:
Type Status Reason
---- ------ ------
Progressing True NewReplicaSetAvailable
Available True MinimumReplicasAvailable
OldReplicaSets: lab5-deploy2-c54b5b8bc (0/0 replicas created), lab5-deploy2-78dcd75f56 (0/0 replicas created)
NewReplicaSet: lab5-deploy2-646c46676b (3/3 replicas created)
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal ScalingReplicaSet 14m deployment-controller Scaled up replica set lab5-deploy2-646c46676b to 3
Normal ScalingReplicaSet 14m deployment-controller Scaled up replica set lab5-deploy2-c54b5b8bc to 1
Normal ScalingReplicaSet 14m deployment-controller Scaled down replica set lab5-deploy2-646c46676b to 2 from 3
Normal ScalingReplicaSet 14m deployment-controller Scaled up replica set lab5-deploy2-c54b5b8bc to 2 from 1
Normal ScalingReplicaSet 14m deployment-controller Scaled down replica set lab5-deploy2-646c46676b to 1 from 2
Normal ScalingReplicaSet 14m deployment-controller Scaled up replica set lab5-deploy2-c54b5b8bc to 3 from 2
Normal ScalingReplicaSet 14m deployment-controller Scaled down replica set lab5-deploy2-646c46676b to 0 from 1
Normal ScalingReplicaSet 3m26s deployment-controller Scaled up replica set lab5-deploy2-78dcd75f56 to 3
Normal ScalingReplicaSet 59s deployment-controller Scaled down replica set lab5-deploy2-78dcd75f56 to 0 from 3
Normal ScalingReplicaSet 57s deployment-controller Scaled up replica set lab5-deploy2-c54b5b8bc to 3 from 0
Normal ScalingReplicaSet 8s (x2 over 3m26s) deployment-controller Scaled down replica set lab5-deploy2-c54b5b8bc to 0 from 3
Normal ScalingReplicaSet 7s deployment-controller Scaled up replica set lab5-deploy2-646c46676b to 3 from 0
21. 스케일링
kubectl scale deploy/lab5-deploy2 --replicas=5
22. 결과 확인
kubectl get pod
kubectl describe deploy
NAME READY STATUS RESTARTS AGE
lab5-deploy2-646c46676b-7nvbs 1/1 Running 0 5s
lab5-deploy2-646c46676b-8kwq6 1/1 Running 0 5s
lab5-deploy2-646c46676b-n2lxh 1/1 Running 0 55s
lab5-deploy2-646c46676b-rkn5j 1/1 Running 0 55s
lab5-deploy2-646c46676b-w5v2z 1/1 Running 0 55s
Pod Template:
Labels: app=lab5-deploy2
Containers:
nginx:
Image: nginx:1.14.0
Port: 80/TCP
Host Port: 0/TCP
Environment: <none>
Mounts: <none>
Volumes: <none>
Conditions:
Type Status Reason
---- ------ ------
Progressing True NewReplicaSetAvailable
Available True MinimumReplicasAvailable
OldReplicaSets: lab5-deploy2-c54b5b8bc (0/0 replicas created), lab5-deploy2-78dcd75f56 (0/0 replicas created)
NewReplicaSet: lab5-deploy2-646c46676b (5/5 replicas created)
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal ScalingReplicaSet 16m deployment-controller Scaled up replica set lab5-deploy2-646c46676b to 3
Normal ScalingReplicaSet 15m deployment-controller Scaled up replica set lab5-deploy2-c54b5b8bc to 1
Normal ScalingReplicaSet 15m deployment-controller Scaled down replica set lab5-deploy2-646c46676b to 2 from 3
Normal ScalingReplicaSet 15m deployment-controller Scaled up replica set lab5-deploy2-c54b5b8bc to 2 from 1
Normal ScalingReplicaSet 15m deployment-controller Scaled down replica set lab5-deploy2-646c46676b to 1 from 2
Normal ScalingReplicaSet 15m deployment-controller Scaled up replica set lab5-deploy2-c54b5b8bc to 3 from 2
Normal ScalingReplicaSet 15m deployment-controller Scaled down replica set lab5-deploy2-646c46676b to 0 from 1
Normal ScalingReplicaSet 4m31s deployment-controller Scaled up replica set lab5-deploy2-78dcd75f56 to 3
Normal ScalingReplicaSet 2m4s deployment-controller Scaled down replica set lab5-deploy2-78dcd75f56 to 0 from 3
Normal ScalingReplicaSet 2m2s deployment-controller Scaled up replica set lab5-deploy2-c54b5b8bc to 3 from 0
Normal ScalingReplicaSet 73s (x2 over 4m31s) deployment-controller Scaled down replica set lab5-deploy2-c54b5b8bc to 0 from 3
Normal ScalingReplicaSet 72s deployment-controller Scaled up replica set lab5-deploy2-646c46676b to 3 from 0
Normal ScalingReplicaSet 22s deployment-controller Scaled up replica set lab5-deploy2-646c46676b to 5 from 3
23. deployment 삭제
kubectl delete deploy --all