쿠버네티스

[클라우드] 7. Deployment strategies

트리스탄1234 2022. 9. 13. 20:51
728x90
반응형

kubernetes 환경에서 애플리케이션의 업데이트를 위한 방법에는 여러가지가 있습니다. 실제 Kubernetes 환경에서의 배포는 CI/CD와 연계를 해서 배포를 합니다. 배포 전략에는 아래와 같이 4가지가 있습니다.

Recreate

첫번째 방식으로 Recreate라는 방식이 있습니다. 기존 버전의 Pod를 삭제를 하고 업데이트된 Pod를 배포하는 방식 입니다. 위의 그림에서 상단 왼쪽에서 부터 보면 우선 기존의 V1 Pod를 삭제를 하고 V2 Pod를 생성하는 방식 입니다. 이 방식은 V1 Pod삭제 후 V2 Pod 생성시까지 서비스 다운타임이 발생을 합니다.

비용이 적게 들고 주로 개발 시스템인 경우에 이 방식을 취하는것을 추천 합니다.

그럼 Yaml 파일을 만들어서 V1 Pod를 배포를 하고 V2 Pod를 다시 배포해 보겠습니다. 아래 로그와 같이 app-v1.yaml파일을 저장할 디렉토리를 생성 후 vi를 사용해 app-v1.yaml 파일에 아래 내용을 입력 후 저장을 합니다.

root@master-VirtualBox:~/test# mkdir deploystrategy
root@master-VirtualBox:~/test# cd deploystrategy/
root@master-VirtualBox:~/test/deploystrategy# mkdir recreate
root@master-VirtualBox:~/test/deploystrategy# cd recreate/
root@master-VirtualBox:~/test/deploystrategy/recreate# vi app-v1.yaml
apiVersion: v1
kind: Service
metadata:
name: my-app
labels:
app: my-app
spec:
type: NodePort
ports:
- name: http
port: 80
targetPort: http
selector:
app: my-app
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
labels:
app: my-app
spec:
replicas: 3
selector:
matchLabels:
app: my-app
strategy:
type: Recreate ==> 버전업 type을 recreate로 정의
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
version: v1.0.0
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: "9101"
spec:
containers:
- name: my-app
image: containersol/k8s-deployment-strategies
ports:
- name: http
containerPort: 8080
- name: probe
containerPort: 8086
env:
- name: VERSION
value: v1.0.0 ==> 버전값을 정의 합니다.
livenessProbe:
httpGet:
path: /live
port: probe
initialDelaySeconds: 5
periodSeconds: 5
readinessProbe:
httpGet:
path: /ready
port: probe
periodSeconds: 5

저장을 완료를 하였으면 이제 배포를 하고 배포된 정보를 조회를해 보겠습니다.

root@master-VirtualBox:~/test/deploystrategy/recreate# kubectl apply -f app-v1.yaml
service/my-app created
deployment.apps/my-app created
oot@master-VirtualBox:~/test/deploystrategy/recreate# kubectl get pod
NAME READY STATUS RESTARTS AGE
my-app-9bb6fb8db-44rlm 1/1 Running 0 4m24s
my-app-9bb6fb8db-5zcnq 1/1 Running 0 4m24s
my-app-9bb6fb8db-swc8x 1/1 Running 0 4m24s
root@master-VirtualBox:~/test/deploystrategy/recreate# kubectl get service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 6d1h
my-nginx-svc NodePort 10.96.95.232 <none> 8080:31793/TCP 19h

위의 로그와 같이 Pod가 3개가 배포 되었고 Service 객체는 1개 Nodeport Type으로 Service Port는 31793으로 열린것을 확인할 수 있습니다 그럼 이제 curl명령을 사용해서 Request 메세제를 보내 정상 동작 하는지 확인해 봅시다.

root@master-VirtualBox:~/test/deploystrategy/recreate# curl localhost:31793
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
Commercial support is available at
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
root@master-VirtualBox:~/test/deploystrategy/recreate#

위와 같인 Request에 대한 응답을 정상적으로 받았습니다.

그럼 이제 app-v2.yaml을 만들어 배포를 하고 어떻게 동작을 하는지 살펴 보겠습니다.

우선 아래와 같이 a--v2.yaml파일을 생성해서 아래 내용을 파일에 입력 후 저장을 합니다.

root@master-VirtualBox:~/test/deploystrategy/recreate# vi app-v2.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
labels:
app: my-app
spec:
replicas: 3
strategy:
type: Recreate ==> 버전업 type을 recreate로 정의
# The selector field tell the deployment which pod to update with
# the new version. This field is optional, but if you have labels
# uniquely defined for the pod, in this case the "version" label,
# then we need to redefine the matchLabels and eliminate the version
# field from there.
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
version: v2.0.0
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: "9101"
spec:
containers:
- name: my-app
image: containersol/k8s-deployment-strategies
ports:
- name: http
containerPort: 8080
- name: probe
containerPort: 8086
env:
- name: VERSION
value: v2.0.0 ==> 버전값을 2.0.0으로 설정
livenessProbe:
httpGet:
path: /live
port: probe
initialDelaySeconds: 5
periodSeconds: 5
readinessProbe:
httpGet:
path: /ready
port: probe
periodSeconds: 5

그럼 이제 app-v2.yaml을 배포를 하고 배포 내용을 점검해 보겠습니다.

root@master-VirtualBox:~/test/deploystrategy/recreate# kubectl apply -f app-v2.yaml
deployment.apps/my-app configured
root@master-VirtualBox:~/test/deploystrategy/recreate# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
my-app-69c46bcf4d-j22t5 1/1 Running 0 41s 172.16.168.215 worknode1-virtualbox <none> <none>
my-app-69c46bcf4d-qmpss 1/1 Running 0 41s 172.16.168.214 worknode1-virtualbox <none> <none>
my-app-69c46bcf4d-vrdr4 1/1 Running 0 41s 172.16.7.142 worknode2-virtualbox <none> <none>

Pod Name 부분이 app-v1.yaml 파일을 배포한 후의 Pod와 다른것을 확인할 수 있습니다. 즉 새로운 Pod가 생성이 된것을 볼수 있습니다.

Ramped(Rolling Update)

두번째 배포 전략으로 Ramped Type이 있습니다. 이 Type은 서비스 무중단 배포 전략으로 recreate와 같이 전체 서비스 중단 후 삭제 및 배포하는 순서가 아니라 한번에 N개의 Pod를 업데이트 합니다.

아래 그림을 살펴 봅시다 .

위의 그림에서 보듯이 기존의 v1을 먼저 삭제 하지 않고 N개의 V2 Pod를 생성한 후 N개의 V1을 삭제하는 구조입니다. 즉 서비스가 중단이 되지 않는 구조 입니다.

그럼 이제 아래와 같이 app-v1.yaml 파일을 생성을 하고 아래 내용을 입력 후 저장을 합니다.

root@master-VirtualBox:~/test/deploystrategy/recreate# vi app-v1.yaml
apiVersion: v1
kind: Service
metadata:
name: my-app
labels:
app: my-app
spec:
type: NodePort
ports:
- name: http
port: 80
targetPort: http
selector:
app: my-app
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
labels:
app: my-app
spec:
replicas: 3
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
version: v1.0.0
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: "9101"
spec:
containers:
- name: my-app
image: containersol/k8s-deployment-strategies
ports:
- name: http
containerPort: 8080
- name: probe
containerPort: 8086
env:
- name: VERSION
value: v1.0.0
livenessProbe:
httpGet:
path: /live
port: probe
initialDelaySeconds: 5
periodSeconds: 5
readinessProbe:
httpGet:
path: /ready
port: probe
periodSeconds: 5

그럼 이제 APP-V1.yaml을 배포를 하고 정보를 조회해 보겠 습니다.

root@master-VirtualBox:~/test/deploystrategy/recreate# kubectl apply -f app-v1.yaml
root@master-VirtualBox:~/test/deploystrategy/recreate# kubectl get pod
NAME READY STATUS RESTARTS AGE
my-app-9bb6fb8db-bl76q 1/1 Running 0 7s
my-app-9bb6fb8db-dbw4k 1/1 Running 0 7s
my-app-9bb6fb8db-j4wwk 1/1 Running 0 7s
root@master-VirtualBox:~/test/deploystrategy/recreate# kubectl get service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 6d2h
my-app NodePort 10.100.224.187 <none> 80:32486/TCP 16s

그럼 이제 app-v2.yaml 파일을 아래와 같이 생성을 한 후에 배포를 하고 조회를해 봅시다.

root@master-VirtualBox:~/test/deploystrategy/recreate# vi app-v2.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
labels:
app: my-app
spec:
replicas: 3
# Here we define the rolling update strategy
# - maxSurge define how many pod we can add at a time
# - maxUnavailable define how many pod can be unavailable
# during the rolling update
#
# Setting maxUnavailable to 0 would make sure we have the appropriate
# capacity during the rolling update.
# You can also use percentage based value instead of integer.
strategy:
type: rollingUpdate ==> 배포 전략을 RollingUpdate로 정의
maxSurge: 1
maxUnavailable: 0
# The selector field tell the deployment which pod to update with
# the new version. This field is optional, but if you have labels
# uniquely defined for the pod, in this case the "version" label,
# then we need to redefine the matchLabels and eliminate the version
# field from there.
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
version: v2.0.0
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: "9101"
spec:
containers:
- name: my-app
image: containersol/k8s-deployment-strategies
ports:
- name: http
containerPort: 8080
- name: probe
containerPort: 8086
env:
- name: VERSION
value: v2.0.0
livenessProbe:
httpGet:
path: /live
port: probe
initialDelaySeconds: 5
periodSeconds: 5
readinessProbe:
httpGet:
path: /ready
port: probe
# Intial delay is set to a high value to have a better
# visibility of the ramped deployment
initialDelaySeconds: 15
periodSeconds: 5

그럼 이제 생성한 app-v2.yaml파일을 배포를 하고 Pod의 상태를 조회해 보겠습니다.

root@master-VirtualBox:~/test/deploystrategy/recreate# kubectl apply -f app-v2.yaml
deployment.apps/my-app configured
root@master-VirtualBox:~/test/deploystrategy/recreate# kubectl get pod
NAME READY STATUS RESTARTS AGE
my-app-5b75d6ddbd-jmn88 0/1 Running 0 11s
my-app-9bb6fb8db-bl76q 1/1 Running 0 3m21s
my-app-9bb6fb8db-dbw4k 1/1 Running 0 3m21s
my-app-9bb6fb8db-j4wwk 1/1 Running 0 3m21s
root@master-VirtualBox:~/test/deploystrategy/recreate#
root@master-VirtualBox:~/test/deploystrategy/recreate# kubectl get pod
NAME READY STATUS RESTARTS AGE
my-app-5b75d6ddbd-jmn88 0/1 Running 0 20s
my-app-9bb6fb8db-bl76q 1/1 Running 0 3m30s
my-app-9bb6fb8db-dbw4k 1/1 Running 0 3m30s
my-app-9bb6fb8db-j4wwk 1/1 Running 0 3m30s
root@master-VirtualBox:~/test/deploystrategy/recreate#
root@master-VirtualBox:~/test/deploystrategy/recreate# kubectl get pod
NAME READY STATUS RESTARTS AGE
my-app-5b75d6ddbd-62kgv 0/1 ContainerCreating 0 5s
my-app-5b75d6ddbd-jmn88 1/1 Running 0 25s
my-app-9bb6fb8db-bl76q 1/1 Running 0 3m35s
my-app-9bb6fb8db-dbw4k 1/1 Running 0 3m35s

위의 로그에서 보듯이 Pod ID중 끝자리가 jimn88인 Pod가 신규로 생서이 되고 Running 상태로 변환이 된 후에 j4wwk라는 Pod가 삭제됨을 볼수 있습니다.

Blue/Green deployments

Blue/green deployment는 Blue는 기존 버전, Green은 새로운 기능을 포함한 새로운 버전으로, 두 버전이 모두 운영환경에 존재하는 상태에서 운영환경에서 Green버전을 테스트한 후 문제가 없으면 Green으로 연결된 트래픽을 Green으로 변경해 배포하는 전략입니다. 장점으로는 배포한 버전(Green)이 문제가 발생했을 경우 신속하게 Blue로 트래픽을 전환할 수 있다는 장점이 있는 반면, 단점으로는 배포시 두배의 리소스가 소요된다는 점과 Stateful한 애플리케이션의 경우는 핸들링하기가 어렵다는 단점이 있습니다.

우리는 앞서 Service 리소스를 살펴보면서 Service가 Pod를 찾는 과정은 Lavel Selector를 이용한다는 것을 알았습니다. Blue/green deployment의 트래픽 전환은 Lavel Selector에 기술된 스펙을 V1에서 V2로 변경함으로써 트래픽을 변경하는 효과를 가져오게 합니다.

그림으로 보면 그 구조가 아래와 같습니다. 신규버전을 Green에 배포하고 테스트를 완료한 후에 테스트결과가 이상 없으면 kubectl patch service 명령어로 트래픽을 Blue로 전환하게 됩니다.

그럼 이제 app-ve.yaml을 아래와 같이 수정한 후에 저장을 합니다.

root@master-VirtualBox:~/test/deploystrategy/recreate# vi app-v1.yaml
apiVersion: v1
kind: Service
metadata:
name: my-app
labels:
app: my-app
spec:
type: NodePort
ports:
- name: http
port: 80
targetPort: http
# Note here that we match both the app and the version
selector:
app: my-app
version: v1.0.0
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app-v1
labels:
app: my-app
spec:
replicas: 3
selector:
matchLabels:
app: my-app
version: v1.0.0
template:
metadata:
labels:
app: my-app
version: v1.0.0
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: "9101"
spec:
containers:
- name: my-app
image: containersol/k8s-deployment-strategies
ports:
- name: http
containerPort: 8080
- name: probe
containerPort: 8086
env:
- name: VERSION
value: v1.0.0
livenessProbe:
httpGet:
path: /live
port: probe
initialDelaySeconds: 5
periodSeconds: 5
readinessProbe:
httpGet:
path: /ready
port: probe
periodSeconds: 5

그럼 이제 app-v.yaml 파일을 배포를 하고 Pod와 SVC의 상태를 조회해 보겠습니다.

root@master-VirtualBox:~/test/deploystrategy/recreate# kubectl apply -f app-v1.yaml
root@master-VirtualBox:~/test/deploystrategy/recreate# kubectl get pod
NAME READY STATUS RESTARTS AGE
my-app-v1-9bb6fb8db-5ms25 1/1 Running 0 8s
my-app-v1-9bb6fb8db-hlqnm 1/1 Running 0 8s
my-app-v1-9bb6fb8db-szxkp 1/1 Running 0 8s
root@master-VirtualBox:~/test/deploystrategy/recreate# kubectl get service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 6d3h
my-app NodePort 10.111.157.220 <none> 80:30717/TCP 13s

그럼 이제 신규 버전인 app-v2.yaml파일을 생성하고 아래의 내용을 입력 후 저장을 합니다.

root@master-VirtualBox:~/test/deploystrategy/recreate# vi app-v2.yaml
apiVersion: v1
kind: Service
metadata:
name: my-app-v2
labels:
app: my-app
spec:
type: NodePort
ports:
- name: http
port: 80
targetPort: http
# Note here that we match both the app and the version
selector:
app: my-app
version: v2.0.0
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app-v2
labels:
app: my-app
spec:
replicas: 3
selector:
matchLabels:
app: my-app
version: v2.0.0
template:
metadata:
labels:
app: my-app
version: v2.0.0
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: "9101"
spec:
containers:
- name: my-app
image: containersol/k8s-deployment-strategies
ports:
- name: http
containerPort: 8080
- name: probe
containerPort: 8086
env:
- name: VERSION
value: v2.0.0
livenessProbe:
httpGet:
path: /live
port: probe
initialDelaySeconds: 5
periodSeconds: 5
readinessProbe:
httpGet:
path: /ready
port: probe
periodSeconds: 5

그럼 이제 app-v2.yaml을 배포하고 Pod가 어떻게 변하는지 확인해 보겠습니다.

root@master-VirtualBox:~/test/deploystrategy/recreate# kubectl apply -f app-v2.yaml
oot@master-VirtualBox:~/test/deploystrategy/recreate# kubectl get pod
NAME READY STATUS RESTARTS AGE
my-app-v1-9bb6fb8db-5ms25 1/1 Running 0 9m30s
my-app-v1-9bb6fb8db-hlqnm 1/1 Running 0 9m30s
my-app-v1-9bb6fb8db-szxkp 1/1 Running 0 9m30s
my-app-v2-69c46bcf4d-tsnr6 1/1 Running 0 12s
my-app-v2-69c46bcf4d-wvsm9 1/1 Running 0 12s
my-app-v2-69c46bcf4d-z8ndf 1/1 Running 0 12s
root@master-VirtualBox:~/test/deploystrategy/recreate# kubectl get service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 6d3h
my-app NodePort 10.111.157.220 <none> 80:30717/TCP 9m39s
my-app-v2 NodePort 10.111.8.220 <none> 80:30166/TCP 21s

위의 로그와 같이 Pod가 V1 3개, V2 3개가 생성이 되고 Service도 V1와 V2가 생성이 된것을 볼수 있습니다. 이 상황에서 어플리케이션을 v2에서 테스트를 하고 결과가 정상적이면 아래 명령으로 V2로 트래픽을 전환을 하면 됩니다.

root@master-VirtualBox:~/test/deploystrategy/recreate# kubectl patch service my-app -p '{"spec":{"selector":{"version":"v2.0.0"}}}'
service/my-app patched

그럼 이제 모든 트래픽이 VERSION 2.0.0값을 가지고 있는 Pod에게만 전달이 됩니다.

Canary Deployment

Canary deployment는 운영환경에서 V1로 배포된 애플리케이션을 V2로 점진적으로 트래픽을 이동시키는 방법입니다. 예를 들어 동일한 애플리케이션에 대한 사용자 요청을 90%는 V1로 나머지 10%를 새롭게 배포된 V2로 보내는 전략입니다. 이러한 배포방법은 배포할 애플리케이션에 대한 테스트가 부족하거나 안정성에 대한 확인이 없을 경우 사용되게 됩니다.

최초에는 V1.2.3 Pod 2개와 V1.3.0 Pod 1개로 운영을 하다가 아래 그림 처럼 2개 그리고 마지막으로 3개로 늘리는 구조 입니다.

그럼 이제 아래와 같이 app-v1.yaml을 생성후에 아래의 내용을 입력후 저장을 합니다.

root@master-VirtualBox:~/test/deploystrategy/recreate# vi app-v1.yaml
apiVersion: v1
kind: Service
metadata:
name: my-app
labels:
app: my-app
spec:
type: NodePort
ports:
- name: http
port: 80
targetPort: http
selector:
app: my-app
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app-v1
labels:
app: my-app
spec:
replicas: 4
selector:
matchLabels:
app: my-app
version: v1.0.0
template:
metadata:
labels:
app: my-app
version: v1.0.0
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: "9101"
spec:
containers:
- name: my-app
image: containersol/k8s-deployment-strategies
ports:
- name: http
containerPort: 8080
- name: probe
containerPort: 8086
env:
- name: VERSION
value: v1.0.0
livenessProbe:
httpGet:
path: /live
port: probe
initialDelaySeconds: 5
periodSeconds: 5
readinessProbe:
httpGet:
path: /ready
port: probe
periodSeconds: 5

그럼 이제 app-v1.yaml을 배포를 하고 Pod와 Service의 정보를 확인해 보겠습니다.

root@master-VirtualBox:~/test/deploystrategy/recreate# kubectl apply -f app-v1.yaml
service/my-app created
deployment.apps/my-app-v1 created
root@master-VirtualBox:~/test/deploystrategy/recreate# kubectl get pod
NAME READY STATUS RESTARTS AGE
my-app-v1-9bb6fb8db-mv6xj 1/1 Running 0 9s
my-app-v1-9bb6fb8db-qfmpz 1/1 Running 0 9s
my-app-v1-9bb6fb8db-tb9fw 1/1 Running 0 9s
my-app-v1-9bb6fb8db-v746q 1/1 Running 0 9s
root@master-VirtualBox:~/test/deploystrategy/recreate# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 6d4h
my-app NodePort 10.96.124.3 <none> 80:31060/TCP 12s

그럼 이제 app-v2.yaml파일을 생성후 아래의 정보를 파일에 입력 후 저장을 합니다.

아래에서 보듯이 V2의 replicas의 값은 1개로 설정이 되어 있습니다. 즉 1개의 v2 Pod만 배포를 합니다.

root@master-VirtualBox:~/test/deploystrategy/recreate# vi app-v2.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app-v2
labels:
app: my-app
spec:
replicas: 1
selector:
matchLabels:
app: my-app
version: v2.0.0
template:
metadata:
labels:
app: my-app
version: v2.0.0
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: "9101"
spec:
containers:
- name: my-app
image: containersol/k8s-deployment-strategies
ports:
- name: http
containerPort: 8080
- name: probe
containerPort: 8086
env:
- name: VERSION
value: v2.0.0
livenessProbe:
httpGet:
path: /live
port: probe
initialDelaySeconds: 5
periodSeconds: 5
readinessProbe:
httpGet:
path: /ready
port: probe
periodSeconds: 5

그럼 이제 생성한 app-v2.yaml을 배포를 하고 Pod 상태를 확인해 보겠습니다.

root@master-VirtualBox:~/test/deploystrategy/recreate# kubectl apply -f app-v2.yaml
root@master-VirtualBox:~/test/deploystrategy/recreate# kubectl get pod
NAME READY STATUS RESTARTS AGE
my-app-v1-9bb6fb8db-mv6xj 1/1 Running 0 5m46s
my-app-v1-9bb6fb8db-qfmpz 1/1 Running 0 5m46s
my-app-v1-9bb6fb8db-tb9fw 1/1 Running 0 5m46s
my-app-v1-9bb6fb8db-v746q 1/1 Running 0 5m46s
my-app-v2-69c46bcf4d-7xc4k 1/1 Running 0 5s

신규로 배포한 V2 Pod가 이상이 없다고 가정을 하면 아래 명령을 사용해 신규 V2 Pod를 생성하고 V1 Pod를 삭제를 하면 됩니다.

root@master-VirtualBox:~/test/deploystrategy/recreate# kubectl scale --replicas=4 deploy my-app-v2
deployment.apps/my-app-v2 scaled
root@master-VirtualBox:~/test/deploystrategy/recreate# kubectl get pod
NAME READY STATUS RESTARTS AGE
my-app-v1-9bb6fb8db-mv6xj 1/1 Running 0 9m54s
my-app-v1-9bb6fb8db-qfmpz 1/1 Running 0 9m54s
my-app-v1-9bb6fb8db-tb9fw 1/1 Running 0 9m54s
my-app-v1-9bb6fb8db-v746q 1/1 Running 0 9m54s
my-app-v2-69c46bcf4d-5vlgk 1/1 Running 0 7s
my-app-v2-69c46bcf4d-7xc4k 1/1 Running 0 4m13s
my-app-v2-69c46bcf4d-d8nnh 1/1 Running 0 7s
my-app-v2-69c46bcf4d-zxk28 1/1 Running 0 7s
root@master-VirtualBox:~/test/deploystrategy/recreate#
root@master-VirtualBox:~/test/deploystrategy/recreate# kubectl delete deployments my-app-v1
deployment.apps "my-app-v1" deleted
root@master-VirtualBox:~/test/deploystrategy/recreate# kubectl get pod
NAME READY STATUS RESTARTS AGE
my-app-v2-69c46bcf4d-5vlgk 1/1 Running 0 41s
my-app-v2-69c46bcf4d-7xc4k 1/1 Running 0 4m47s
my-app-v2-69c46bcf4d-d8nnh 1/1 Running 0 41s
my-app-v2-69c46bcf4d-zxk28 1/1 Running 0 41s
root@master-VirtualBox:~/test/deploystrategy/recreate#

그럼 이제 Kubernetes에 지원하는 Deployment Strategy를 모두 살펴 보았습니다.

 

728x90
반응형