kubernetes - 如何在 kubernetes yaml 文件中使用标签以便系统知道推送了新图像

标签 kubernetes azure-container-registry gitops

我正在尝试使用 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/

相关文章:

kubernetes - 使用 kubernetes 部署 Minio 无法按预期工作

go - Kubernetes 的 client-go 运行应用命令

nginx - 在哪里可以找到为nginx.ingress.kubernetes.io/affinity注释生成的配置

kubernetes - 如何使用Cloud Composer安排外部集群中的Kubernetes工作负载

Azure 服务主体从容器注册表中提取镜像

amazon-web-services - 使用 ECS 部署 GitOps?

Azure DevOps Pipeline - 构建 Docker 镜像并将其推送到具有受限网络访问权限的 Azure 容器注册表

azure - Powershell + Azure 应用服务 + Azure 容器注册表

kubernetes - argocd 应用程序在 CI 管道中创建(GitHub Actions、Tekton...)抛出 "PermissionDenied desc = permission denied: applications, create, default/myapp"

kubernetes - GitOps (Flex) 通过 HelmRelease 操作符在 Kubernetes 中安装标准 Jenkins Helm 图表