클라우드 교육/kubernetes

쿠버네티스 Deployment Update

mellamo 2023. 5. 8. 11:44

 

 

Deployment에는 두가지 업데이트 방식이 있는데, 

 

Recreate , RollingUpdate가 있다. 

 

 

Recreate는 한번에 레플리카셋을 삭제하고  새로 생성하는 방식이다.

 

속도가 빠르고 추가 리소스를 잡아먹지 않지만, 파드가 없는 타이밍이 생기는 단점이 있다

 

 

 

 

 

 

Rolling Update는 업데이트 중에 maxUnabaliable 과 maxSurge를 설정할 수 있는데, 추가 리소스를 사용안하도록 하거나, 파드가 끊기지 않게 전환 할 수 있는 장점이 있다. 

 

 

 

Recreate부터 알아보자. 

 

spec.strategy.type 에 Recreate로 임명하고

apiVersion: apps/v1
kind: Deployment
metadata:
  name: s5
spec:
  strategy:
    type: Recreate
  replicas: 3
  selector:
    matchLabels:
      app: sample-app
  template:
    metadata:
      labels:
        app: sample-app
    spec:
      containers:
        - name: nginx-container
          image: nginx:1.12

 

실행시킨뒤 업데이트를 한다.

 

업데이트는 

kubectl set image deploy <deployment 이름> nginx-container=nginx.1.17

 

터미널을 하나 더 열어두고 아래명령어를 입력한다. 

kubectl get replicaset --watch

 

 

이렇게 보면중간에 한꺼번에 사라지고, 새로 Replicaset가 생성된 것을 확인할 수 있다.

 

 

 

이번엔 RollingUpdate

 

spec.strategy.type에 RollingUpdate를 입력하고, maxUnavailable과 maxSurge를 입력한다. 

apiVersion: apps/v1
kind: Deployment
metadata:
  name: s6
spec:
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 0
      maxSurge: 1
  replicas: 3
  selector:
    matchLabels:
      app: sample-app
  template:
    metadata:
      labels:
        app: sample-app
    spec:
      containers:
        - name: nginx-container
          image: nginx:1.12

그리고 생성 후 업데이트. 

 

역시나 watch로 확인해보면 두 Replicaset이 동시에 존재하는것을 알 수 있다.