Kubernetes Tools/ArgoCD

[Ep.20] [Argo CD ๋ฐฐํฌ & ์ž๋™ํ™” #5] Argo CD Notifications๋กœ Slack ๋ฐ ์ด๋ฉ”์ผ ์•Œ๋ฆผ ์„ค์ •

ygtoken 2025. 3. 17. 13:09
728x90

๐Ÿ”น Argo CD Notifications๋ž€?

Argo CD Notifications๋Š” Argo CD์—์„œ ๋ฐœ์ƒํ•˜๋Š” ์ด๋ฒคํŠธ(๋ฐฐํฌ ์„ฑ๊ณต, ์‹คํŒจ, ๋™๊ธฐํ™” ์˜ค๋ฅ˜ ๋“ฑ)๋ฅผ ์‹ค์‹œ๊ฐ„์œผ๋กœ ์•Œ๋ฆผํ•˜๋Š” ๊ธฐ๋Šฅ์ž…๋‹ˆ๋‹ค.
์ด๋ฅผ ํ™œ์šฉํ•˜๋ฉด ์šด์˜์ž๊ฐ€ ๋ฐฐํฌ ์ƒํƒœ๋ฅผ ๋น ๋ฅด๊ฒŒ ํŒŒ์•…ํ•˜๊ณ  ์ฆ‰์‹œ ๋Œ€์‘ํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ,
Slack, ์ด๋ฉ”์ผ, ์›นํ›…(Webhook) ๋“ฑ ๋‹ค์–‘ํ•œ ์ฑ„๋„๋กœ ์•Œ๋ฆผ์„ ๋ณด๋‚ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

โœ… Argo CD Notifications์˜ ์ฃผ์š” ๊ธฐ๋Šฅ
โœ” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋™๊ธฐํ™” ์ƒํƒœ ๋ณ€๊ฒฝ ๊ฐ์ง€ (Sync ์„ฑ๊ณต, ์‹คํŒจ, ์ถฉ๋Œ ๋“ฑ)
โœ” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ํ—ฌ์Šค ์ฒดํฌ ์‹คํŒจ ๊ฐ์ง€ (์˜ˆ: CrashLoopBackOff)
โœ” Slack, ์ด๋ฉ”์ผ, Webhook ๋“ฑ์˜ ์•Œ๋ฆผ ์ฑ„๋„ ์ง€์›
โœ” ์ปค์Šคํ…€ ์•Œ๋ฆผ ํ…œํ”Œ๋ฆฟ ๊ตฌ์„ฑ ๊ฐ€๋Šฅ


๐Ÿ”น Argo CD Notifications ์„ค์น˜ ๋ฐ ๊ตฌ์„ฑ

โœ… 1. Argo CD Notifications ์„ค์น˜

Argo CD Notifications๋Š” Argo CD์˜ ํ™•์žฅ ๊ธฐ๋Šฅ์ด๋ฏ€๋กœ Helm์„ ์‚ฌ์šฉํ•˜์—ฌ ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค.

helm repo add argo https://argoproj.github.io/argo-helm
helm repo update
helm upgrade --install argo-cd argo/argo-cd --namespace argocd --set notifications.enabled=true

 

โœ… ์„ค์น˜ ํ™•์ธ:

kubectl get pods -n argocd | grep notifications
argocd-notifications-controller-xxxxx   1/1   Running   0     1m

โœ… 2. Argo CD Notifications ๊ธฐ๋ณธ ์„ค์ •

Argo CD Notifications๋Š” ConfigMap๊ณผ Secret์„ ํ†ตํ•ด ์•Œ๋ฆผ ์„ค์ •์„ ๊ด€๋ฆฌํ•ฉ๋‹ˆ๋‹ค.

๐Ÿ“Œ ConfigMap ์ƒ์„ฑ (notifications-config)

apiVersion: v1
kind: ConfigMap
metadata:
  name: argocd-notifications-cm
  namespace: argocd
data:
  context: |
    appName: "ArgoCD"
  templates.app-sync-failed: |
    title: Application {{.app.metadata.name}} ๋™๊ธฐํ™” ์‹คํŒจ
    body: |
      โŒ {{.app.metadata.name}} ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ๋™๊ธฐํ™”์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค.
      - **ํ”„๋กœ์ ํŠธ**: {{.app.spec.project}}
      - **๋™๊ธฐํ™” ์ƒํƒœ**: {{.app.status.sync.status}}
      - **๊ฑด๊ฐ• ์ƒํƒœ**: {{.app.status.health.status}}
  subscriptions: |
    - recipients:
        - slack:#deploy-alerts
      triggers:
        - on-sync-failed

 

โœ… ์„ค๋ช…:
โœ” context → ์•Œ๋ฆผ์— ํฌํ•จ๋  ๊ธฐ๋ณธ ์ •๋ณด ์„ค์ •
โœ” templates.app-sync-failed → ๋™๊ธฐํ™” ์‹คํŒจ ์‹œ ์•Œ๋ฆผ ๋ฉ”์‹œ์ง€ ํ…œํ”Œ๋ฆฟ
โœ” subscriptions → ํŠน์ • ์ด๋ฒคํŠธ ๋ฐœ์ƒ ์‹œ Slack ์ฑ„๋„์— ์•Œ๋ฆผ


โœ… 3. Slack ์•Œ๋ฆผ ์„ค์ •

๐Ÿ“Œ Slack Webhook ์„ค์ •

Slack ์•Œ๋ฆผ์„ ๋ฐ›๊ธฐ ์œ„ํ•ด Webhook์„ ์„ค์ •ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

1๏ธโƒฃ Slack Webhook ์ƒ์„ฑ ํŽ˜์ด์ง€๋กœ ์ด๋™
2๏ธโƒฃ ์ƒˆ๋กœ์šด Slack App์„ ์ƒ์„ฑ ํ›„ Incoming Webhooks ํ™œ์„ฑํ™”
3๏ธโƒฃ Webhook URL์„ ๋ณต์‚ฌ


๐Ÿ“Œ Slack Webhook์„ Kubernetes Secret์— ์ €์žฅ

apiVersion: v1
kind: Secret
metadata:
  name: argocd-notifications-secret
  namespace: argocd
stringData:
  slack-webhook-url: "https://hooks.slack.com/services/XXXX/XXXX/XXXX"

 

โœ… Secret ์ ์šฉ:

kubectl apply -f argocd-notifications-secret.yaml

๐Ÿ“Œ ConfigMap์— Slack ์„ค์ • ์ถ”๊ฐ€

Slack Webhook์„ ์•Œ๋ฆผ ์ฑ„๋„๋กœ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

apiVersion: v1
kind: ConfigMap
metadata:
  name: argocd-notifications-cm
  namespace: argocd
data:
  service.slack: |
    webhook: $slack-webhook-url

 

โœ… ConfigMap ์ ์šฉ:

kubectl apply -f argocd-notifications-cm.yaml

 

โœ… Slack ์•Œ๋ฆผ ํ…Œ์ŠคํŠธ:

argocd notifications test-service slack

โœ… 4. ์ด๋ฉ”์ผ ์•Œ๋ฆผ ์„ค์ •

์ด๋ฉ”์ผ ์•Œ๋ฆผ์„ ๋ฐ›๊ธฐ ์œ„ํ•ด SMTP ์„œ๋ฒ„ ์ •๋ณด๋ฅผ Secret์œผ๋กœ ์ €์žฅํ•ฉ๋‹ˆ๋‹ค.

apiVersion: v1
kind: Secret
metadata:
  name: argocd-notifications-secret
  namespace: argocd
stringData:
  email-username: "example@gmail.com"
  email-password: "app-password"

 

โœ… Secret ์ ์šฉ:

kubectl apply -f argocd-notifications-secret.yaml

๐Ÿ“Œ ConfigMap์— ์ด๋ฉ”์ผ ์„ค์ • ์ถ”๊ฐ€

apiVersion: v1
kind: ConfigMap
metadata:
  name: argocd-notifications-cm
  namespace: argocd
data:
  service.email: |
    host: smtp.gmail.com
    port: 587
    username: $email-username
    password: $email-password
    from: "ArgoCD Notifications <example@gmail.com>"

 

โœ… ConfigMap ์ ์šฉ:

kubectl apply -f argocd-notifications-cm.yaml

 

โœ… ์ด๋ฉ”์ผ ์•Œ๋ฆผ ํ…Œ์ŠคํŠธ:

argocd notifications test-service email

โœ… 5. Argo CD ์•Œ๋ฆผ ํŠธ๋ฆฌ๊ฑฐ ์„ค์ •

๋‹ค์–‘ํ•œ ์ด๋ฒคํŠธ์— ๋Œ€ํ•œ ์•Œ๋ฆผ์„ ์„ค์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๐Ÿ“Œ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋™๊ธฐํ™” ์„ฑ๊ณต/์‹คํŒจ ํŠธ๋ฆฌ๊ฑฐ ์„ค์ •

apiVersion: v1
kind: ConfigMap
metadata:
  name: argocd-notifications-cm
  namespace: argocd
data:
  trigger.on-sync-failed: |
    - description: "์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋™๊ธฐํ™” ์‹คํŒจ ๊ฐ์ง€"
      when: "app.status.sync.status == 'OutOfSync'"
      send: [slack, email]
  trigger.on-sync-succeeded: |
    - description: "์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋™๊ธฐํ™” ์„ฑ๊ณต ๊ฐ์ง€"
      when: "app.status.sync.status == 'Synced'"
      send: [slack]

 

โœ… ConfigMap ์ ์šฉ:

kubectl apply -f argocd-notifications-cm.yaml

 

โœ… ํŠธ๋ฆฌ๊ฑฐ ์„ค์ • ํ™•์ธ:

argocd notifications trigger list

๐Ÿ”น Argo CD Notifications CLI ๋ช…๋ น์–ด ์ •๋ฆฌ

๋ช…๋ น์–ด  ์„ค๋ช…
argocd notifications test-service slack Slack ์•Œ๋ฆผ ํ…Œ์ŠคํŠธ
argocd notifications test-service email ์ด๋ฉ”์ผ ์•Œ๋ฆผ ํ…Œ์ŠคํŠธ
argocd notifications trigger list ์„ค์ •๋œ ํŠธ๋ฆฌ๊ฑฐ ๋ชฉ๋ก ํ™•์ธ
argocd notifications trigger enable <TRIGGER> ํŠน์ • ํŠธ๋ฆฌ๊ฑฐ ํ™œ์„ฑํ™”
argocd notifications trigger disable <TRIGGER> ํŠน์ • ํŠธ๋ฆฌ๊ฑฐ ๋น„ํ™œ์„ฑํ™”

๐Ÿ”น ๊ฒฐ๋ก : ์ด๋ฒˆ ๊ธ€์—์„œ ๋ฐฐ์šด ํ•ต์‹ฌ ๋‚ด์šฉ ์ •๋ฆฌ

๐ŸŸข Argo CD Notifications๋ฅผ ํ™œ์šฉํ•˜๋ฉด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋ฐฐํฌ ์ƒํƒœ๋ฅผ ์‹ค์‹œ๊ฐ„์œผ๋กœ ๋ชจ๋‹ˆํ„ฐ๋ง ๊ฐ€๋Šฅ
๐ŸŸข Slack, ์ด๋ฉ”์ผ, Webhook์„ ํ†ตํ•ด ๋ฐฐํฌ ์„ฑ๊ณต/์‹คํŒจ ์•Œ๋ฆผ์„ ๋ฐ›์„ ์ˆ˜ ์žˆ์Œ
๐ŸŸข ConfigMap๊ณผ Secret์„ ํ™œ์šฉํ•˜์—ฌ ์œ ์—ฐํ•œ ์•Œ๋ฆผ ์„ค์ •์ด ๊ฐ€๋Šฅํ•จ
๐ŸŸข ์ž๋™ํ™”๋œ ์•Œ๋ฆผ ์‹œ์Šคํ…œ์„ ๊ตฌ์ถ•ํ•˜์—ฌ GitOps ํ™˜๊ฒฝ์—์„œ ๋น ๋ฅด๊ฒŒ ์ด์Šˆ๋ฅผ ๊ฐ์ง€ํ•˜๊ณ  ๋Œ€์‘ ๊ฐ€๋Šฅ

728x90