GCP Pub/Sub
GCP Pub/Sub
이 알림 서비스는 Google Cloud Pub/Sub 토픽으로 메시지를 보내요. GCP 프로젝트 ID와 토픽 이름을 지정하고, 서비스 계정 키 파일(또는 GKE의 Workload Identity)로 인증한 뒤, 템플릿에 커스텀 속성(attributes)을 넣어 메시지를 라우팅·필터링할 수 있어요.
출처: 문서
본문
파라미터 (Parameters)
이 알림 서비스는 Google Cloud Pub/Sub 토픽으로 메시지를 보낼 수 있어요.
project— Pub/Sub 토픽이 위치한 GCP 프로젝트 IDtopic— 메시지를 보내려는 Pub/Sub 토픽 이름. 대상(destination) 어노테이션으로 덮어쓸 수 있어요.keyFile— 선택 사항, GCP 서비스 계정 키 파일 경로. 제공하지 않으면 Application Default Credentials를 사용해요.
예시 (Example)
서비스 계정 키 파일 사용 (Using Service Account Key File)
리소스 어노테이션:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
annotations:
notifications.argoproj.io/subscribe.on-deployment-ready.gcppubsub: "override-topic"
ConfigMap:
apiVersion: v1
kind: ConfigMap
metadata:
name: argocd-notifications-cm
data:
service.gcppubsub: |
project: "my-gcp-project"
topic: "my-topic"
keyFile: "/var/secrets/gcp/key.json"
template.deployment-ready: |
message: |
Deployment {{.obj.metadata.name}} is ready!
gcppubsub:
attributes:
app: "{{.obj.metadata.name}}"
environment: "production"
trigger.on-deployment-ready: |
- when: any(obj.status.conditions, {.type == 'Available' && .status == 'True'})
send: [deployment-ready]
- oncePer: obj.metadata.annotations["generation"]
Workload Identity 사용 (GKE) (Using Workload Identity (GKE))
Workload Identity가 활성화된 GKE에서 실행하면 keyFile 파라미터를 생략할 수 있고, 서비스는 Kubernetes 서비스 계정에 바인딩된 서비스 계정의 기본 자격 증명(default credentials)을 사용해요.
리소스 어노테이션:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
annotations:
notifications.argoproj.io/subscribe.on-deployment-ready.gcppubsub: ""
ConfigMap:
apiVersion: v1
kind: ConfigMap
metadata:
name: argocd-notifications-cm
data:
service.gcppubsub: |
project: "my-gcp-project"
topic: "my-topic"
template.deployment-ready: |
message: |
Deployment {{.obj.metadata.name}} is ready!
gcppubsub:
attributes:
app: "{{.obj.metadata.name}}"
status: "{{.obj.status.conditions[0].type}}"
trigger.on-deployment-ready: |
- when: any(obj.status.conditions, {.type == 'Available' && .status == 'True'})
send: [deployment-ready]
- oncePer: obj.metadata.annotations["generation"]
메시지 속성 (Message Attributes)
Pub/Sub 메시지는 필터링·라우팅에 사용할 수 있는 커스텀 속성(key-value 쌍)을 지원해요. 템플릿에 속성을 포함할 수 있어요.
template.deployment-ready: |
message: |
Deployment {{.obj.metadata.name}} is ready!
gcppubsub:
attributes:
severity: "info"
app: "{{.obj.metadata.name}}"
namespace: "{{.obj.metadata.namespace}}"
timestamp: "{{(call .time.Now).Unix}}"
속성은 메시지 본문처럼 템플릿 변수를 지원해요. 그래서 모니터링 대상 객체의 메타데이터를 동적으로 채울 수 있어요.