Skip to content

Commit

Permalink
๐Ÿ“ docs: Publish argocd canary deployment traffic load balancing analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
Han-Joon-Hyeok committed Nov 17, 2024
1 parent c7b55c4 commit 771e130
Showing 1 changed file with 215 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
---
title: "[ArgoCD] ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ canary ์ „๋žต์˜ ํŒŒ๋“œ ๊ฐœ์ˆ˜์— ๋”ฐ๋ฅธ ๋กœ๋“œ๋ฐธ๋Ÿฐ์‹ฑ"
date: 2024-11-17 21:10:00 +0900
categories: [argocd]
tags: []
---

# ๊ฐœ์š”

ArgoCD์—์„œ ์ง€์›ํ•˜๋Š” ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ ์ „๋žต ์ค‘ ํ•˜๋‚˜์ธ canary ์ „๋žต์„ ์‚ฌ์šฉํ•ด์„œ ์—…๋ฐ์ดํŠธ๋ฅผ ์ง„ํ–‰ํ•  ๋•Œ, ํŒŒ๋“œ์˜ ๊ฐœ์ˆ˜์— ๋”ฐ๋ผ ํŠธ๋ž˜ํ”ฝ์˜ ๋กœ๋“œ ๋ฐธ๋Ÿฐ์‹ฑ์ด ์–ด๋–ป๊ฒŒ ์ด๋ฃจ์–ด์ง€๋Š”์ง€ ์ •๋ฆฌํ–ˆ๋‹ค.

# canary

## ๊ฐœ๋…

์ƒˆ๋กญ๊ฒŒ ์—…๋ฐ์ดํŠธ ํ•˜๋Š” ๋ฒ„์ „์„ v2, ๊ธฐ์กด ์‹คํ–‰ํ•˜๊ณ  ์žˆ๋Š” ๋ฒ„์ „์„ v1์ด๋ผ๊ณ  ํ•ด๋ณด์ž. canary ๋ฐฐํฌ ์ „๋žต์—์„œ๋Š” v1์— ๋ณด๋‚ด๋˜ ํŠธ๋ž˜ํ”ฝ์„ v2๋กœ ์ ์ง„์ ์œผ๋กœ ์˜ฎ๊ธด๋‹ค. ์ฆ‰, ๋ฐฐํฌ๋ฅผ ํ•˜๋Š” ์ค‘์ด๋ผ๋ฉด ์ผ๋ถ€ ํŠธ๋ž˜ํ”ฝ์€ v2๋กœ ๊ฐ€๊ณ , ๋‚˜๋จธ์ง€ ํŠธ๋ž˜ํ”ฝ์€ v1์œผ๋กœ ๊ฐ„๋‹ค๋Š” ๊ฒƒ์ด๋‹ค. ์ด๋Ÿฌํ•œ ํŠน์ง• ๋•Œ๋ฌธ์— A/B ํ…Œ์ŠคํŠธ์— ์‚ฌ์šฉ๋˜๊ธฐ๋„ ํ•œ๋‹ค.

ArgoCD์˜ canary ๋ฐฐํฌ ์ „๋žต์€ v2์— ์ƒˆ๋กญ๊ฒŒ ์ƒ์„ฑํ•œ ํŒŒ๋“œ์˜ ๊ฐœ์ˆ˜์— ๋น„๋ก€ํ•ด์„œ ํŠธ๋ž˜ํ”ฝ์„ ๋ถ„์‚ฐํ•˜๋Š” ๋ฐฉ์‹์„ ์ฑ„ํƒํ•˜๊ณ  ์žˆ๋‹ค.

์˜ˆ๋ฅผ ๋“ค์–ด, 5๊ฐœ์˜ ํŒŒ๋“œ๊ฐ€ ์žˆ๊ณ , ํŠธ๋ž˜ํ”ฝ ๋ถ„์‚ฐ ๋น„์ค‘(weight)์„ 20%, 40%, 60%, 80% ์ ์ง„์ ์œผ๋กœ ์ฆ๊ฐ€์‹œํ‚จ๋‹ค๊ณ  ํ•ด๋ณด์ž. ์—ฌ๊ธฐ์„œ ํผ์„ผํŠธ๋Š” ์ƒˆ๋กœ์šด ๋ฒ„์ „์œผ๋กœ ๋ณด๋‚ผ ํŠธ๋ž˜ํ”ฝ์˜ ๋น„์ค‘์„ ์˜๋ฏธํ•œ๋‹ค.

๋น„์ค‘์— ๋”ฐ๋ฅธ v1, v2 ๋ฒ„์ „์˜ ํŒŒ๋“œ ๊ฐœ์ˆ˜์™€ ์ „์ฒด ํŠธ๋ž˜ํ”ฝ ๋ถ„์‚ฐ ๋น„์œจ์€ ๋‹ค์Œ์˜ ํ‘œ์™€ ๊ฐ™์ด ๋ณ€ํ™”ํ•œ๋‹ค.

| | v1 ํŒŒ๋“œ ๊ฐœ์ˆ˜ - ์ „์ฒด ํŠธ๋ž˜ํ”ฝ ๋น„์œจ | v2 ํŒŒ๋“œ ๊ฐœ์ˆ˜ - ์ „์ฒด ํŠธ๋ž˜ํ”ฝ ๋น„์œจ |
| ---- | ------------------------------- | ------------------------------- |
| 0% | 5 - 100% | 0 - 0% |
| 20% | 5 - 80% | 1 - 20% |
| 40% | 5 - 60% | 2 - 40% |
| 60% | 5 - 40% | 3 - 60% |
| 80% | 5 - 20% | 4 - 80% |
| 100% | 0 - 0% | 5 - 100% |

์ƒˆ๋กœ์šด ๋ฒ„์ „์œผ๋กœ ์—…๋ฐ์ดํŠธ๊ฐ€ ๋๋‚  ๋•Œ๊นŒ์ง€, ์ฆ‰ ํŠธ๋ž˜ํ”ฝ์„ 100% ์˜ฎ๊ธฐ๊ธฐ ์ „๊นŒ์ง€๋Š” v1 ๋ฒ„์ „ ํŒŒ๋“œ๋ฅผ ์œ ์ง€ํ•œ๋‹ค.

๊ทธ๋ ‡๊ธฐ ๋•Œ๋ฌธ์— canary ๋ฐฐํฌ ์ „๋žต์€ blue/green ๋ฐฐํฌ ์ „๋žต์ฒ˜๋Ÿผ ๋ฐฐํฌํ•˜๋Š” ๊ณผ์ •์—์„œ ๋ฆฌ์†Œ์Šค๋ฅผ ํ‰์†Œ๋ณด๋‹ค ์•ฝ 2๋ฐฐ ์ •๋„ ์‚ฌ์šฉํ•ด์•ผ ํ•œ๋‹ค.

## ํŠธ๋ž˜ํ”ฝ ๋ถ„์‚ฐ ํ…Œ์ŠคํŠธ

๊ฐœ๋…์ ์œผ๋กœ๋Š” ์ดํ•ดํ–ˆ์ง€๋งŒ, ์‹ค์ œ๋กœ ํŠธ๋ž˜ํ”ฝ์ด ํŠธ๋ž˜ํ”ฝ ๋ถ„์‚ฐ ๋น„์ค‘(weight)์— ๋”ฐ๋ผ ๋ถ„์‚ฐ๋˜๋Š”์ง€ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•ด ํ…Œ์ŠคํŠธ๋ฅผ ์ง„ํ–‰ํ–ˆ๋‹ค.

### ํ…Œ์ŠคํŠธ ํ™˜๊ฒฝ

ํŒŒ๋“œ๋Š” nginx์™€ tcpdump๋ฅผ ํ•จ๊ป˜ ์„ค์น˜๋œ ์ด๋ฏธ์ง€๋กœ ํŒŒ๋“œ๋ฅผ ์‹คํ–‰ํ–ˆ๋‹ค.

weight๋Š” 20, 40, 60, 80 ์ˆœ์œผ๋กœ ์ฆ๊ฐ€ํ•˜๋„๋ก ํ–ˆ์œผ๋ฉฐ, 30์ดˆ ๊ฐ„๊ฒฉ์œผ๋กœ ํŒŒ๋“œ๋ฅผ ์ƒˆ๋กญ๊ฒŒ ์ƒ์„ฑํ•˜๋„๋ก ํ–ˆ๋‹ค.

### yaml ํŒŒ์ผ ์ฝ”๋“œ

Helm Chart๋ฅผ ์ด์šฉํ•ด์„œ Application์„ ์ƒ์„ฑํ–ˆ๋‹ค.

๋””๋ ‰ํ† ๋ฆฌ ๊ตฌ์กฐ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.

```bash
.
โ”œโ”€โ”€ Chart.yaml
โ”œโ”€โ”€ templates
โ”‚ โ”œโ”€โ”€ rollout.yaml
โ”‚ โ””โ”€โ”€ service.yaml
โ””โ”€โ”€ values.yaml
```

`rollout.yaml` ํŒŒ์ผ์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.

```yaml
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
name: {{ .Values.app.name }}-rollout
labels:
app: {{ .Values.app.name }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
spec:
replicas: {{ .Values.app.replicas }}
revisionHistoryLimit: 3
selector:
matchLabels:
app: {{ .Values.app.name }}
release: {{ .Release.Name }}
strategy:
canary:
canaryService: {{ .Values.app.name }}-canary
stableService: {{ .Values.app.name }}-stable
steps:
- setWeight: 20
- pause: {duration: 30s}
- setWeight: 40
- pause: {duration: 30s}
- setWeight: 60
- pause: {duration: 30s}
- setWeight: 80
- pause: {duration: 30s}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml .Values.podAnnotations | nindent 8 }}
{{- end }}
labels:
app: {{ .Values.app.name }}
{{- with .Values.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
release: {{ .Release.Name }}
spec:
containers:
- name: {{ .Chart.Name }}
image: {{ .Values.app.image }}
{{- with .Values.app.resources }}
resources:
{{- toYaml . | nindent 10 }}
{{- end }}
ports:
- name: http
containerPort: {{ .Values.app.port }}
protocol: TCP
```
`service.yaml` ํŒŒ์ผ์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.

```yaml
{{- if .Values.service.enabled }}
apiVersion: v1
kind: Service
metadata:
labels:
app: {{ .Values.app.name }}
name: {{ .Values.app.name }}-canary
namespace: {{ .Release.Namespace | quote }}
spec:
ports:
- port: {{ .Values.service.port }}
protocol: TCP
name: http
targetPort: {{ .Values.app.port }}
selector:
app: {{ .Values.app.name }}
---
apiVersion: v1
kind: Service
metadata:
labels:
app: {{ .Values.app.name }}
name: {{ .Values.app.name }}-stable
namespace: {{ .Release.Namespace | quote }}
spec:
ports:
- port: {{ .Values.service.port }}
protocol: TCP
name: http
targetPort: {{ .Values.app.port }}
type: NodePort
selector:
app: {{ .Values.app.name }}
{{- end }}
```

์„œ๋น„์Šค๋Š” canary, stable 2๊ฐœ์ด๋ฉฐ, stable ์„œ๋น„์Šค๋Š” NodePort ๋ฅผ ์ด์šฉํ•ด์„œ `localhost:port` ๋กœ ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋„๋ก ํ–ˆ๋‹ค.

`values.yaml` ํŒŒ์ผ์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.

```yaml
app:
name: "demo-rollout"
replicas: 2
image: "giafar/nginx:1.25.1-tcpdump"
port: 80
resources:
requests:
cpu: "1m"
memory: "128Mi"
limits:
cpu: "1m"
memory: "128Mi"
podAnnotations: {}
podLabels:
tier: backend
service:
enabled: true
port: 80
```

ํŒจํ‚ท์ด ๋“ค์–ด์˜ค๋Š”์ง€ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•ด tcpdump๊ฐ€ ์„ค์น˜๋œ nginx ์ด๋ฏธ์ง€๋ฅผ ์‚ฌ์šฉํ–ˆ๋‹ค.

๊ฐ ํŒŒ๋“œ์—์„œ tcpdump ๋ฅผ ์‹คํ–‰ํ•˜๊ณ  `curl localhost:port` ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•ด์„œ ํŒจํ‚ท ์ˆ˜์‹ ์„ ํ™•์ธํ–ˆ๋‹ค.

ํŒŒ๋“œ ์ ‘์†์€ ์•„๋ž˜์˜ ๋ช…๋ น์–ด๋ฅผ ์ด์šฉํ–ˆ๋‹ค.

```bash
kubectl exec -it -n [namespace] [pod-name] -- /bin/sh
```

### ํŒŒ๋“œ๊ฐ€ 1๊ฐœ์ผ ๋•Œ

v2 ํŒŒ๋“œ์—์„œ tcpdump ๋ฅผ ์‹คํ–‰ํ•œ ์ƒํƒœ๋กœ `curl` ์„ ์‹คํ–‰ํ–ˆ์ง€๋งŒ, weight๊ฐ€ 100์ด ๋  ๋•Œ๊นŒ์ง€ v2 ํŒŒ๋“œ์—๋Š” ํŠธ๋ž˜ํ”ฝ์ด ๋ถ„์‚ฐ๋˜์ง€ ์•Š์•˜๋‹ค.

weight๊ฐ€ 20์ด๋ฉด ํŠธ๋ž˜ํ”ฝ์„ v1 ํŒŒ๋“œ์— 80%, v2 ํŒŒ๋“œ์— 20% ๋ถ„์‚ฐํ•ด์ค„ ๊ฒƒ์œผ๋กœ ์˜ˆ์ƒํ–ˆ๋Š”๋ฐ, ๊ทธ๋ ‡์ง€ ์•Š์•˜๋‹ค.

### ํŒŒ๋“œ๊ฐ€ 5๊ฐœ์ผ ๋•Œ

v1 ํŒŒ๋“œ์—์„œ tcpdump ์‹คํ–‰ํ•œ ์ƒํƒœ๋กœ `curl` ์„ ์‹คํ–‰ํ•˜๋‹ˆ weight ๊ฐ€ ์ฆ๊ฐ€ํ• ์ˆ˜๋ก ์ ์  ํŒจํ‚ท ์ˆ˜์‹ ์ด ์ค„์—ˆ๋‹ค.

์ด๋ฅผ ํ†ตํ•ด weight๋Š” ํŒŒ๋“œ์˜ ๊ฐœ์ˆ˜์— ๋น„๋ก€ํ•ด์„œ ๋ถ„๋ฐฐ ํ•ด์ฃผ๋Š” ๊ฒƒ ๊ฐ™๋‹ค.

## ๊ธฐํƒ€

- ํŒŒ๋“œ ๊ฐœ์ˆ˜๋ฅผ ์ค„์ด๋Š” ๊ฒƒ์€ revision์ด ์ฆ๊ฐ€ํ•˜์ง€ ์•Š๋Š”๋‹ค.
- ํŒŒ๋“œ๊ฐ€ 1๊ฐœ์˜€๋‹ค๊ฐ€ 5๊ฐœ๋กœ ๋ฐ”๋€Œ๊ณ  ์ด๋ฏธ์ง€๋„ ๊ฐ™์ด ๋ฐ”๋€Œ๋ฉด ํŒŒ๋“œ๋ฅผ ๋จผ์ € 5๊ฐœ๋กœ ๋Š˜๋ฆฐ ๋‹ค์Œ์— canary ๋กœ ํ•˜๋‚˜์”ฉ ์˜ฎ๊ธด๋‹ค.

# ์ฐธ๊ณ ์ž๋ฃŒ

- [Kubernetes ๋ฆฌ์†Œ์Šค Deployment์— ๋Œ€ํ•ด ์ดํ•ดํ•˜๊ณ  ์‹ค์Šตํ•ด๋ณด๊ธฐ](https://velog.io/@pinion7/Kubernetes-%EB%A6%AC%EC%86%8C%EC%8A%A4-Deployment%EC%97%90-%EB%8C%80%ED%95%B4-%EC%9D%B4%ED%95%B4%ED%95%98%EA%B3%A0-%EC%8B%A4%EC%8A%B5%ED%95%B4%EB%B3%B4%EA%B8%B0) [velog]

0 comments on commit 771e130

Please sign in to comment.