본문 바로가기

IT Study/Kubernetes

kubernetes deploymemt rollingupdate

kubernetes deploymemt rollingupdate

디플로이먼트는 쿠버네티스에서 상태가없는 앱을 배포할때 가장 기본적인 컨트롤러이다.

디플로이먼트는 레프리카셋을 관리하면서 앱 배포를 더 세밀하게 관리한다.

파드갯수를 보장해주는것 뿐만아니라 롤링,롤백업데이트를 지원한다.

 

롤링업데이트(rollingupdate): 파드를 점진적으로 새로운것으로 업데이트 하여 서비스 중단 없이

이루어질 수 있도록 함

 

레플리카셋을 제어해주는 부모역할을 하는 디플로이먼트.

 

 

●deployment Controller 생성 ,관리 및 확인

 

 

 

NAME                                                    READY       STATUS    RESTARTS   AGE
pod/nginx-deploy-84455b7b7c-7ffbf        1/1             Running             0          13s
pod/nginx-deploy-84455b7b7c-hgbxk     1/1             Running             0          13s
pod/nginx-deploy-84455b7b7c-llpxz        1/1             Running            0          13s

 

■ 디플로이먼트

■ 레플리카세트

■ 파드네임

 

※ 레플리카셋을 삭제해도 디플로이에의해 다시 생성된다. 

 

●rolling update & rolling back 설정

디플로이먼트를 사용하는 가장주된 이유중 하나이다

파드를 점진적,새로운것으로 서비스 중단없이 업데이트,다운그레이드 해주는 기능.

 

롤링,롤백 업데이트 과정 https://www.bluematador.com/blog/kubernetes-deployments-rolling-update-configuration

롤링 업데이트명령어가 전달되면  레플리카셋v2을 하나더 생성한다 생성된 레플리카셋v2에서 업데이트된 pod가 생성되면 기존 레플리카셋v1의 pod app이 삭제되면서 점진적으로 업데이트가 진행된다  

 

rolling update / rolling back 설정

kubectl set image deployment <deploy명> <container명>=<버전이미지>

 

디플로이먼트 생성

 

nginx 1.14버전으로 생성
롤링업데이트 명령어로 nginx 1.15버전으로 롤링업데이트진행
kubectl rollot history deployment [deploy명] 명령어로 롤링업데이트 기록을 확인할수있다.

 

rolling back 설정

kubectl rollout undo deploy [deploy명]  : 롤백 명령어로 history기준 바로 전단계로 롤백

kubectl rollout undo deploy [deploy명] --to-revision=[숫자] : history기준의 REVISION 넘버의 버전으로 롤백

 

 

 

위 과정을 yaml 파일에 정의하여 조금더 세부적으로 사용할수 있다

 

apiVersion: apps/v1
kind: Deployment
metadata:
  name: deploy-nginx
spec:
  progressDeadlineSeconds: 600
  revisionHistoryLimit: 10
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
      type: RollingUpdate
  selector:
    matchLabels:
      app: webui
  replicas: 3
  template:
    metadata:
      labels:
        app: webui
    spec:
      containers:
      - name: web
        image: nginx:1.14
        ports:
        - containerPort: 80

 

●progressDeadlineSeconds : 정해진 시간동안 업데이트를 진행하지못하면 업데이트를 취소

revisionHistoryLimit : 업데이트내역을 history에 최대 몇개까지 기록되는 값

maxSurge : 업데이트를 진행했을 때 생성할수있는 POD의 수 정수와 비율로 지정 높아질수록 업데이트속도가빨라짐

maxUnavailable : 업데이트를 진행했을때 기존POD가 삭제되는 수 정수와 비율로 지정

type: 롤링,롤백 업데이트 타입지정

 

※yaml파일에 정의시 kubectl create -f 가아닌 kubectl apply -f로 배포해야한다.

( create -f / apply -f의차이점은 포스팅됨)

 

 

 

'IT Study > Kubernetes' 카테고리의 다른 글

kubernetes statefulset  (0) 2023.01.29
kubernetes daemonset controller  (0) 2023.01.19
kubernetes replicaset controller  (0) 2023.01.18
kubernetes ReplicationController  (0) 2023.01.17
kubernetes controller  (0) 2023.01.17