ArgoCD Image Updater
Vibe Prompt
「幫我設定 ArgoCD Image Updater:當 ghcr.io 有新 Image 時自動更新 deployment。」
安裝 Image Updater
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj-labs/argocd-image-updater/stable/manifests/install.yaml
Application 註解
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
annotations:
argocd-image-updater.argoproj.io/image-list: myapp=ghcr.io/myorg/myapp
argocd-image-updater.argoproj.io/myapp.update-strategy: latest
argocd-image-updater.argoproj.io/myapp.allow-tags: regex:^v[0-9]+\.[0-9]+$
spec:
...
更新策略
| 策略 | 說明 | |------|------| | latest | 使用最新版本 | | semver | 遵循語義化版本 | | digest | 使用 digest 精確鎖定 | | name | 按標籤名稱排序 |
完整流程
1. CI 建置新 Image 推送到 ghcr.io
2. Image Updater 偵測到新版本
3. 自動更新 Git Repo 中的 Image Tag
4. ArgoCD 偵測到 Git 變更
5. 自動同步到 K8s 叢集
6. 完成部署
關鍵要點
- ✅ 請根據本章主題補充具體的學習重點
- ✅ 建議加入比較表格、程式碼範例或流程圖
- ✅ 確保內容扎實且有價值
映像檔更新策略
ArgoCD Image Updater
自動偵測容器映像檔新版本並更新 Git 儲存庫:
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
annotations:
argocd-image-updater.argoproj.io/image-list: my-app=ghcr.io/username/my-app
argocd-image-updater.argoproj.io/my-app.update-strategy: latest
argocd-image-updater.argoproj.io/my-app.allow-tags: regex:^v[0-9]+\.[0-9]+$
argocd-image-updater.argoproj.io/write-back-method: git:secret:devops-creds
| 策略 | 行為 | 使用時機 |
|:----:|------|---------|
| latest | 使用最新標籤 | 開發環境 |
| semver | 使用最新的語意版本 | 正式環境 |
| digest | 使用映像檔摘要 | 最高安全性要求 |
| name | 使用字母排序的最新名稱 | 特殊命名規則 |
CI/CD 整合
# GitHub Actions 自動更新
- name: Update image tag
run: |
kustomize edit set image my-app=ghcr.io/username/my-app:${{ github.sha }}
- name: Commit and push
run: |
git config user.name "CI Bot"
git add .
git commit -m "Update image tag to ${{ github.sha }}"
git push
ArgoCD Image Updater:自動更新 Image
Image Updater 是 ArgoCD 的外掛——它監控 Container Registry 中是否有新的 Image 版本,自動更新 Git Repo 中的 Kustomize 或 Helm 的 image tag。
為什麼需要 Image Updater?
沒有 Image Updater 時,CI Pipeline 建置完新 Image 後,還要再 commit 一次 Manifests Repo 來更新 tag。Image Updater 讓這個步驟自動化——CI 只需要 push Image 到 Registry,Image Updater 會自動偵測並更新。
工作流程
CI Pipeline 建置新 Image → Push 到 Registry
↓
Image Updater 偵測到新 Tag
↓
自動建立 PR 更新 Manifests
↓
ArgoCD 偵測到 Git 變更 → 自動部署
課程總結
這堂 GitOps 課從 GitOps 核心思想、ArgoCD、Kustomize、Image Updater 到完整流水線——你現在可以建立從開發者 Commit 到 Production 部署的全自動 GitOps 流程。