我正在尝试使用 Azure DevOps 为我的 AKS 集群设置 CI,并使用 GitOps 设置 CD。当 CI 完成时,图像被推送到 Azure 容器注册表。我的问题是我的 yaml 文件中的图像名称是:最新的。当我将图像推送到容器注册表时,Flux CD 无法确定图像是否有任何更改,因为图像的名称保持不变。我试图在 github 中查找问题并提出以下链接: https://github.com/GoogleCloudPlatform/cloud-builders/issues/22#issuecomment-316181326 但我不知道如何实现它。有人可以帮帮我吗?
最佳答案
来自 FluxCD 的文档 here
Note: that Flux only works with immutable image tags (:latest is not supported). Every image tag must be unique, for this you can use the Git commit SHA or semver when tagging images.
开启基于时间戳的自动化:
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
fluxcd.io/automated: "true"
spec:
template:
spec:
containers:
- name: app
image: docker.io/org/my-app:1.0.0
当你推送一个新的图像标签时,上面的配置将使 Flux 更新应用程序容器,无论是 my-app:1.0.1 还是 my-app:9e3bdaf。
使用 sem ver 限制图像更新:
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
fluxcd.io/automated: "true"
fluxcd.io/tag.app: semver:~1.0
spec:
template:
spec:
containers:
- name: app
image: docker.io/org/my-app:1.0.0
当您推送与语义版本表达式匹配的图像标签时,上述配置将使 Flux 更新图像,例如 my-app:1.0.1 但不是 my-app:1.2.0
在 azure DevOps 管道中标记图像时,您应该使用 Git commit SHA 或 semver docker task
steps:
- task: Docker@2
displayName: Build and Push
inputs:
command: buildAndPush
containerRegistry: dockerRegistryServiceConnection1
repository: contosoRepository
tags: |
tag1
tag2
关于kubernetes - 如何在 kubernetes yaml 文件中使用标签以便系统知道推送了新图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62788434/