-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
๐ docs: Publish argocd canary deployment traffic load balancing analysis
- Loading branch information
1 parent
c7b55c4
commit 771e130
Showing
1 changed file
with
215 additions
and
0 deletions.
There are no files selected for viewing
215 changes: 215 additions & 0 deletions
215
_posts/2024/2024-11-17-argocd-canary-deployment-traffic-load-balancing-analysis.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |