๐น Argo CD์ CI/CD์ ์ฐ๊ณ ๊ฐ์
Argo CD๋ GitOps ๋ฐฉ์์ผ๋ก Kubernetes ์ ํ๋ฆฌ์ผ์ด์
์ ๊ด๋ฆฌํ๋ ๊ฐ๋ ฅํ ๋๊ตฌ์ด์ง๋ง,
CI/CD ํ์ดํ๋ผ์ธ๊ณผ ์ฐ๊ณํ๋ฉด ๋น๋, ๋ฐฐํฌ ์๋ํ๊ฐ ๋์ฑ ๊ฐ๋ ฅํด์ง๋๋ค.
โ Argo CD์ CI/CD ํ์ดํ๋ผ์ธ์ ๊ฒฐํฉํด์ผ ํ๋ ์ด์
โ CI(Continuous Integration) → ์ ํ๋ฆฌ์ผ์ด์
๋น๋ ๋ฐ ์ปจํ
์ด๋ ์ด๋ฏธ์ง ์์ฑ ์๋ํ
โ CD(Continuous Deployment) → Argo CD๊ฐ Git ๋ณ๊ฒฝ ์ฌํญ์ ๊ฐ์งํ์ฌ ์๋ ๋ฐฐํฌ
โ ์๋ํ๋ ๋กค๋ฐฑ(Rollback) → ๋ฐฐํฌ ์คํจ ์ Argo CD๊ฐ ์ด์ ๋ฒ์ ์ผ๋ก ๋ณต๊ตฌ ๊ฐ๋ฅ
โ ๋ฉํฐ ์คํ
์ด์ง ๋ฐฐํฌ ์ง์ → Dev → Staging → Production ํ๊ฒฝ์ผ๋ก ์ ์ง์ ๋ฐฐํฌ ๊ฐ๋ฅ
โ Argo CD์ CI/CD ์ฐ๋ ๋ฐฉ์
์ฐ๋ ๋ฐฉ์ | ์ค๋ช |
Git Webhook | GitHub/GitLab Webhook์ ํ์ฉํ์ฌ ๋ณ๊ฒฝ ์ฌํญ์ Argo CD์ ์๋ฆผ |
Argo CD API | CI/CD ํ์ดํ๋ผ์ธ์์ Argo CD API๋ฅผ ํธ์ถํ์ฌ ๋ฐฐํฌ ํธ๋ฆฌ๊ฑฐ |
GitOps ๋ฐฉ์ | CI์์ Kubernetes ๋งค๋ํ์คํธ ๋ณ๊ฒฝ ํ Git Push, Argo CD๊ฐ ๊ฐ์งํ์ฌ ๋ฐฐํฌ |
๐น 1. Argo CD์ GitHub Actions์ ํ์ฉํ CI/CD ์๋ํ
Argo CD๋ Git์ ์ ์ฅ๋ ๋งค๋ํ์คํธ๋ฅผ ์๋์ผ๋ก ๋ฐฐํฌํ๋ฏ๋ก,
GitHub Actions์ ํ์ฉํ์ฌ ์ปจํ
์ด๋ ์ด๋ฏธ์ง๋ฅผ ๋น๋ํ๊ณ Kubernetes ๋งค๋ํ์คํธ๋ฅผ ์
๋ฐ์ดํธํ ์ ์์ต๋๋ค.
โ 1๏ธโฃ GitHub Actions์ ํ์ฉํ CI/CD ํ์ดํ๋ผ์ธ ์์
name: Deploy with Argo CD
on:
push:
branches:
- main # main ๋ธ๋์น์ Push ๋ฐ์ ์ ์คํ
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2 # GitHub ์ ์ฅ์ ์ฝ๋ ๋ค์ด๋ก๋
- name: Build Docker image
run: |
docker build -t ghcr.io/example/app:${{ github.sha }} . # GitHub Container Registry์ ์ด๋ฏธ์ง ๋น๋
docker push ghcr.io/example/app:${{ github.sha }} # ๋น๋ํ ์ด๋ฏธ์ง ํธ์
- name: Update Kubernetes manifests
run: |
sed -i "s|image: ghcr.io/example/app:.*|image: ghcr.io/example/app:${{ github.sha }}|g" k8s/deployment.yaml
git config user.name "GitHub Actions"
git config user.email "actions@github.com"
git add k8s/deployment.yaml
git commit -m "Update deployment image to ${{ github.sha }}"
git push origin main # ๋งค๋ํ์คํธ ์
๋ฐ์ดํธ ํ Git์ Push
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- name: Trigger Argo CD Sync
run: |
argocd app sync example-app # Argo CD์์ ๋ฐฐํฌ ๋๊ธฐํ ์คํ
โ
์ค๋ช
:
โ build ๋จ๊ณ → Docker ์ด๋ฏธ์ง๋ฅผ ๋น๋ํ๊ณ GitHub Container Registry(GHCR)์ Push
โ Update Kubernetes manifests ๋จ๊ณ → ์ ์ด๋ฏธ์ง๋ฅผ Kubernetes ๋งค๋ํ์คํธ์ ๋ฐ์ ํ Git์ Push
โ deploy ๋จ๊ณ → argocd app sync๋ฅผ ์คํํ์ฌ Argo CD๊ฐ ๋ณ๊ฒฝ ์ฌํญ์ ๋๊ธฐํ
โ Argo CD Sync ๋ช ๋ น์ด
argocd app sync example-app
โ Argo CD์์ ํ์ฌ ๋ฐฐํฌ ์ํ ํ์ธ
argocd app get example-app
๐น 2. GitOps ๋ฐฉ์์ ํ์ฉํ ๋ฐฐํฌ ์๋ํ
Argo CD๋ GitOps ๋ฐฉ์์ ๊ธฐ๋ฐ์ผ๋ก ๋ฐฐํฌ๋ฅผ ์๋ํํ๋ฏ๋ก,
CI/CD ํ์ดํ๋ผ์ธ์์ Git์ Kubernetes ๋งค๋ํ์คํธ๋ฅผ ์
๋ฐ์ดํธํ๋ ๋ฐฉ์์ด ์ต์ ํ๋ ์ ๋ต์
๋๋ค.
โ GitOps ๋ฐฉ์์ผ๋ก ๋ฐฐํฌํ๋ Argo CD Application ์์
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: example-app
namespace: argocd
spec:
project: default
source:
repoURL: https://github.com/example/repo.git
targetRevision: main
path: k8s # Kubernetes ๋งค๋ํ์คํธ๊ฐ ์ ์ฅ๋ ๋๋ ํฐ๋ฆฌ
destination:
server: https://kubernetes.default.svc
namespace: example-app
syncPolicy:
automated:
prune: true # Git์์ ์ญ์ ๋ ๋ฆฌ์์ค๋ฅผ Kubernetes์์๋ ์๋ ์ญ์
selfHeal: true # Kubernetes ๋ฆฌ์์ค๊ฐ ๋ณ๊ฒฝ๋์์ ๊ฒฝ์ฐ ์๋ ์ํ๋ก ์๋ ๋ณต๊ตฌ
โ
์ค๋ช
:
โ source.repoURL → Kubernetes ๋งค๋ํ์คํธ๊ฐ ์ ์ฅ๋ Git ๋ฆฌํฌ์งํ ๋ฆฌ ์ง์
โ syncPolicy.automated → Git ๋ณ๊ฒฝ ์ฌํญ์ ์๋์ผ๋ก ๋ฐฐํฌ
โ
Git Push ์ Argo CD๊ฐ ์๋์ผ๋ก ๋ฐฐํฌ
1๏ธโฃ ๊ฐ๋ฐ์๊ฐ Kubernetes ๋งค๋ํ์คํธ ๋ณ๊ฒฝ ํ Git์ Push
2๏ธโฃ Argo CD๊ฐ ๋ณ๊ฒฝ ์ฌํญ์ ๊ฐ์งํ์ฌ ์๋์ผ๋ก ๋ฐฐํฌ
๐น 3. Argo CD์ Argo Workflows๋ฅผ ํ์ฉํ CI/CD ํ์ดํ๋ผ์ธ ๊ตฌ์ถ
Argo CD์ Argo Workflows๋ฅผ ํจ๊ป ํ์ฉํ๋ฉด ์ปจํ ์ด๋ ๊ธฐ๋ฐ์ ์ํฌํ๋ก์ฐ๋ฅผ ์คํํ๊ณ ์๋์ผ๋ก ์ ํ๋ฆฌ์ผ์ด์ ์ ๋ฐฐํฌํ ์ ์์ต๋๋ค.
โ Argo Workflows๋ฅผ ํ์ฉํ ๋ฐฐํฌ ํ์ดํ๋ผ์ธ ์์
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: deploy-workflow-
spec:
entrypoint: deploy
templates:
- name: deploy
steps:
- - name: build-image
template: build
- - name: update-manifest
template: update
- - name: sync-argo
template: sync
- name: build
container:
image: docker:latest
command: ["sh", "-c"]
args: ["docker build -t ghcr.io/example/app:latest . && docker push ghcr.io/example/app:latest"]
- name: update
container:
image: alpine/git
command: ["sh", "-c"]
args: ["git clone https://github.com/example/repo.git && cd repo && sed -i 's|image:.*|image: ghcr.io/example/app:latest|' k8s/deployment.yaml && git commit -am 'Update image' && git push"]
- name: sync
container:
image: argoproj/argocd-cli
command: ["sh", "-c"]
args: ["argocd app sync example-app"]
โ
์ค๋ช
:
โ build → ์ปจํ
์ด๋ ์ด๋ฏธ์ง๋ฅผ ๋น๋ํ๊ณ GHCR์ Push
โ update → Kubernetes ๋งค๋ํ์คํธ ์
๋ฐ์ดํธ ํ Git์ Push
โ sync → Argo CD์์ ๋ฐฐํฌ ๋๊ธฐํ ์คํ
โ Argo Workflows ์คํ ๋ช ๋ น์ด
argo submit deploy-workflow.yaml --watch
๐น 4. CI/CD ํ์ดํ๋ผ์ธ ์ต์ ํ ์ ๊ณ ๋ คํ ์
โ
1๏ธโฃ ์ด๋ฏธ์ง ํ๊ทธ ๊ด๋ฆฌ
โ CI/CD ํ์ดํ๋ผ์ธ์์ latest ํ๊ทธ ๋์ Git SHA ๋๋ ๋ฒ์ ํ๊ทธ๋ฅผ ํ์ฉํ์ฌ ๋กค๋ฐฑ ๊ฐ๋ฅํ๊ฒ ๊ด๋ฆฌ
โ
2๏ธโฃ ๋จ๊ณ๋ณ ๋ฐฐํฌ(Blue-Green, Canary) ์ ์ฉ
โ Argo Rollouts๋ฅผ ํ์ฉํ์ฌ ๋จ๊ณ๋ณ ๋ฐฐํฌ(Blue-Green, Canary ๋ฐฐํฌ)๋ฅผ ์ ์ฉํ์ฌ ์์ ์ฑ ๊ฐํ
โ
3๏ธโฃ GitOps ๊ธฐ๋ฐ์ผ๋ก ๋ชจ๋ ๋ณ๊ฒฝ ์ฌํญ์ Git์ ์ ์ฅ
โ CI/CD ํ์ดํ๋ผ์ธ์์ Kubernetes ๋งค๋ํ์คํธ๋ฅผ Git์ ๋ฐ์ ํ Argo CD๊ฐ ๋ฐฐํฌ
๐น ๊ฒฐ๋ก : ์ด๋ฒ ๊ธ์์ ๋ฐฐ์ด ํต์ฌ ๋ด์ฉ ์ ๋ฆฌ
๐ข GitHub Actions๊ณผ Argo CD๋ฅผ ์ฐ๊ณํ์ฌ CI/CD ์๋ํ ๊ฐ๋ฅ
๐ข Argo Workflows๋ฅผ ํ์ฉํ์ฌ ๋ณต์กํ ๋ฐฐํฌ ํ์ดํ๋ผ์ธ์ ์๋ํ ๊ฐ๋ฅ
๐ข GitOps ๋ฐฉ์์ผ๋ก ๋ฐฐํฌ ์๋ํํ๋ฉด ๋ณ๊ฒฝ ์ฌํญ ์ถ์ ๋ฐ ๋กค๋ฐฑ ์ฉ์ด
๐ข Argo CD์ CI/CD ์ฐ๊ณ๋ฅผ ํตํด ๋ฐฐํฌ ํจ์จ์ฑ์ ๊ทน๋ํ ๊ฐ๋ฅ