Kubernetes/Study

[K8s-1pro] Rolling update 테스트 시나리오

lumination 2025. 6. 20. 12:07

https://sunsh0602@github.com/sunsh0602/study.git

 

kubectl apply -f ./k8s-study/sprint1_anotherclass-123_ns.yaml

kubectl apply -f ./k8s-study/sprint1_anotherclass-123_configmap.yaml

kubectl apply -f ./k8s-study/sprint1_anotherclass-123_hpa.yaml

kubectl apply -f ./k8s-study/sprint1_anotherclass-123_secret.yaml

kubectl apply -f ./k8s-study/sprint1_anotherclass-123_svc.yaml

kubectl apply -f ./k8s-study/sprint1_anotherclass-123_pvc.yaml

kubectl apply -f ./k8s-study/sprint1_anotherclass-123_deploy.yaml

 

쿠버네티스 어나더 클래스

▶ 1. RollingUpdate 하기

// 1) HPA minReplica 2로 바꾸기 (이전 강의에서 minReplicas를 1로 바꿔놨었음)
kubectl patch -n anotherclass-123 hpa api-tester-1231-default -p '{"spec":{"minReplicas":2}}'

// 1) 그외 Deployment scale 명령
kubectl scale -n anotherclass-123 deployment api-tester-1231 --replicas=2
// 1) edit로 모드로 직접 수정
kubectl edit -n anotherclass-123 deployment api-tester-1231

// 2) 지속적으로 Version호출 하기 (업데이트 동안 리턴값 관찰)
while true; do curl http://192.168.56.30:31231/version; sleep 2; echo ''; done; 

// 3) 별도의 원격 콘솔창을 열어서 업데이트 실행 
kubectl set image -n anotherclass-123 deployment/api-tester-1231 api-tester-1231=1pro/api-tester:v2.0.0
kubectl set image -n anotherclass-123 deployment/api-tester-1231

// update 실행 포맷 
// kubectl set image -n <namespace> deployment/<deployment-name> <container-name>=<image-name>:<tag>

 

▶ 2. RollingUpdate (maxUnavailable: 0%, maxSurge: 100%) 하기

apiVersion: apps/v1
kind: Deployment
metadata:
  namespace: anotherclass-123
  name: api-tester-1231
spec:
  replicas: 2
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 25% -> 0%  # 수정
      maxSurge: 25% -> 100%      # 수정
      
kubectl set image -n anotherclass-123 deployment/api-tester-1231 api-tester-1231=1pro/api-tester:v1.0.0
maxUnavailable: 0% => 0%는 못 써도 된다.  Replicas 4일 경우, 기존 1개도 죽지 않음
maxSurge: 100% => 100% 추가로 생성 가능하다.  Replicas 4일 경우, 8개까지 생김

 

▶ 3. Recreate 하기

apiVersion: apps/v1
kind: Deployment
metadata:
  namespace: anotherclass-123
  name: api-tester-1231
spec:
  replicas: 2
  strategy:
    type: RollingUpdate -> Recreate   # 수정
    rollingUpdate:        # 삭제
      maxUnavailable: 0%  # 삭제
      maxSurge: 100%      # 삭제
      
kubectl set image -n anotherclass-123 deployment/api-tester-1231 api-tester-1231=1pro/api-tester:v2.0.0
 

▶ 4. Rollback

// 이전 버전으로 롤백
kubectl rollout undo -n anotherclass-123 deployment/api-tester-1231

 

2-3. 레퍼런스

▶ update

https://kubernetes.io/docs/concepts/workloads/controllers/deployment/