【问题标题】:ArgoCD GitOps where the image tag for each pod is always the git commit hashArgoCD GitOps,其中每个 pod 的图像标签始终是 git commit hash
【发布时间】:2021-11-07 08:38:38
【问题描述】:

我们正尝试在我的公司使用 ArgoCD 使用 GitOps,我们有一个主要问题:

Jenkins,我们的 CI 工具,目前在任何 PR 与当前使用的 git commit hash 相关的标签合并时推送到我们的 docker repo。

编辑:我们希望在选择 targetRevision 后,将其 git 哈希作为字符串用于覆盖我们 helm 图表中的 imageTag 的值。

现在选项 1 是我们只是让它同时更改任何相关 kubernetes 文件中的 imageTag。

但是我想知道是否有一种方法可以使用 ArgoCD 的 PreSync 挂钩来自动执行此操作。它已经知道 git 哈希,因为它已经提取了 git。让 Jenkins 提交 git 绝不是理想的选择。

感谢您的帮助!

【问题讨论】:

  • 让机器人向 Git 提交是 GitOps 的理想选择。是的,感觉很奇怪,但这不是源代码,而是它的配置。我们利用 SOPS 加密机密并让 GHA 机器人自动生成 PR 并将其标记为 automerge 以碰撞容器标签(如果 CI 发布新图像)

标签: git jenkins argocd gitops


【解决方案1】:

您可以使用 targetRevision: HEAD

https://github.com/argoproj/argocd-example-apps/blob/master/apps/values.yaml

所以 ArgoCD 中的应用程序配置是这样的

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: message-app-staging
  namespace: argocd
  environment: staging
  finalizers:
    - resources-finalizer.argocd.argoproj.io
spec:
  project: default

  # Source of the application manifests
  source:
    repoURL: https://github.com/akash-gautam/message-app-manifests.git
    targetRevision: HEAD
    path: manifests/staging

  # Destination cluster and namespace to deploy the application
  destination:
    server: https://kubernetes.default.svc
    namespace: staging

  syncPolicy:
    automated:
      prune: false
      selfHeal: false

如果指定了分支名称或符号引用(如 HEAD),Argo CD 将不断将实时状态与指定分支顶端定义的资源清单或符号引用的已解析提交进行比较。

上述情况最好与 helm 一起使用。

如果您在 YAML 中有静态清单,我建议您也检查一下:https://github.com/Alwinius/bowhttps://github.com/keel-hq/keel

Bow 从 Docker 镜像注册表中检测更新的镜像标签 在包含 Kubernetes 的 GitOps 部署存储库中定义 部署/StatefulSets 或 Helm 模板。

额外:https://www.padok.fr/en/blog/argocd-image-updater

【讨论】:

  • 这不会帮助我们在拉取 GitHub 时覆盖 helm 图表中 docker 镜像 repo url 的镜像标签。这将确保我们从 HEAD 中提取掌舵图。我真正需要的是告诉 ArgoCD 用它用 targetRevision 提取的 git sha 的值覆盖 helm 图表中的值。我只需要那个环境变量来使它工作。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-01-13
  • 2017-03-19
  • 1970-01-01
  • 2021-06-20
  • 2017-04-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多