쿠버네티스/기초

Deployment - Recreate, RollingUpdate (기초)

라리음 2022. 8. 5. 17:49

이 글은 인프런의 대세는 쿠버네티스 강의를 보며 정리한 글입니다.

 

 

 

대표적으로 4가지가 있음

 

1. ReCreate (pod들을 삭제하고 새 버전의 pod들을 배포 <downtime>이 발생)

2. Rolling Update (새 버전의 pod를 생성하고 이전 버전의 pod를 죽이고를 순차적으로 시킴 <많은 리소스가 필요>

3. Blue/Green (새로운 버전의 controller을 만들고 service의 라벨을 바꾸어 새로운 버전의 pod들에 연결 / 문제시 롤백이 쉬움 <순간적으로 많은 리소스가 필요>

4. Canary (똑같이 기존의 파드들에 라벨을 (type) 달고 서비스에 연결 -> 새로운 버전의 controller을 만들고 pod2에도 라벨로 연결 (type) 이후 기존 Controller의 replicaset을 0으로 맞춰줘서 다 없앰

컨트롤러들을 연결하는 Ingrees controller이 필요!

 

 

 

 

Recreate에는 strategy에 type에 revisionHistoryLimit이 존재함

replicas가 0인 replicaset을 몇개 남길지 정하는 것

 

이것은 디폴트 값이 10임

 

 

 

rolling update에는 terminationGracePeriodSeconds이 존재함원래 새로운 버전의 replicaset이 만들어져서 pod가 생성되고 지우고 하는 과정이 순식간에 일어나는데이것의 시간을 제어하기 위한 것

 

 

 

 

 

 

 

 

실습

 

 

 

 

 

 

 

1. ReCreate


1-1) Deployment 생성

apiVersion: apps/v1
kind: Deployment
metadata:
  name: deployment-1
spec:
  selector:
    matchLabels:
      type: app
  replicas: 2
  strategy:
    type: Recreate
  revisionHistoryLimit: 1
  template:
    metadata:
      labels:
        type: app
    spec:
      containers:
      - name: container
        image: kubetm/app:v1
      terminationGracePeriodSeconds: 10

 

1-2) Service 생성

apiVersion: v1
kind: Service
metadata:
  name: svc-1
spec:
  selector:
    type: app
  ports:
  - port: 8080
    protocol: TCP
    targetPort: 8080

Command (확인용)

while true; do curl 10.99.5.3:8080/version; sleep 1; done

Kubectl (롤백)

kubectl rollout undo deployment deployment-1 --to-revision=2
kubectl rollout history deployment deployment-1



2. RollingUpdate


2-1) Deployment 생성

apiVersion: apps/v1
kind: Deployment
metadata:
  name: deployment-2
spec:
  selector:
    matchLabels:
      type: app2
  replicas: 2
  strategy:
    type: RollingUpdate
  minReadySeconds: 10
  template:
    metadata:
      labels:
        type: app2
    spec:
      containers:
      - name: container
        image: kubetm/app:v1
      terminationGracePeriodSeconds: 0

2-2) Service

apiVersion: v1
kind: Service
metadata:
  name: svc-2
spec:
  selector:
    type: app2
  ports:
  - port: 8080
    protocol: TCP
    targetPort: 8080

Command 생성

while true; do curl 10.99.5.3:8080/version; sleep 1; done



3. Blue/Green


ReplicaSet 생성 (업데이트 할때는 버전 수정)

apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: replica1
spec:
  replicas: 2
  selector:
    matchLabels:
      ver: v1
  template:
    metadata:
      name: pod1
      labels:
        ver: v1
    spec:
      containers:
      - name: container
        image: kubetm/app:v1
      terminationGracePeriodSeconds: 0

Service 생성

apiVersion: v1
kind: Service
metadata:
  name: svc-3
spec:
  selector:
    ver: v1
  ports:
  - port: 8080
    protocol: TCP
    targetPort: 8080

 

 

 

모든 과정에서 업데이트는 edit으로 버전 수정하면 됨.

 

실습은 꼭 해보기..