Skip to content

NimTechnology

Trình bày các công nghệ CLOUD một cách dễ hiểu.

  • Kubernetes & Container
    • Docker
    • Kubernetes
      • Ingress
      • Pod
    • Helm Chart
    • OAuth2 Proxy
    • Isito-EnvoyFilter
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Vault
    • Longhorn – Storage
    • VictoriaMetrics
    • MetalLB
    • Kong Gateway
  • CI/CD
    • ArgoCD
    • ArgoWorkflows
    • Argo Events
    • Spinnaker
    • Jenkins
    • Harbor
    • TeamCity
    • Git
      • Bitbucket
  • Coding
    • DevSecOps
    • Terraform
      • GCP – Google Cloud
      • AWS – Amazon Web Service
      • Azure Cloud
    • Golang
    • Laravel
    • Python
    • Jquery & JavaScript
    • Selenium
  • Log, Monitor & Tracing
    • DataDog
    • Prometheus
    • Grafana
    • ELK
      • Kibana
      • Logstash
  • BareMetal
    • NextCloud
  • Toggle search form

[ArgoCD Image Updater] How does Argocd trigger images on Dockerhub and deploy workload on k8s automatically?

Posted on October 5, 2022August 26, 2023 By nim No Comments on [ArgoCD Image Updater] How does Argocd trigger images on Dockerhub and deploy workload on k8s automatically?

Contents

Toggle
  • 1) Overview and Install ArgoCD Image Updater on K8s
  • 2) Adjusting the configuration of ArgoCD Image Updater
    • 2.1) Access ECR
      • 2.1.1) Using Access and Secret Key
      • 2.1.2) Access to Multiple ECRs on one Argocd-image-updater
  • 3) argocd-image-updater need to access github
    • 3.1) access git through Token
    • 3.2) access git through ssh-key
  • 4) Practicing argocd-image-updater in fact
    • 4.1) argocd-image-updater – kustomize – manifest(deployment, service,..)
    • 4.2) argocd-image-updater – kustomize – Helm chart
    • 4.3) argocd-image-updater integrate helm chart (folder on Git)
    • 4.4) argocd-image-updater integrate helm package.
  • 5) Invalid Semantic Version
  • Issues
    • Argocd Image Updater doesn’t update images for Your application.

1) Overview and Install ArgoCD Image Updater on K8s

Để hoàn thành flow Gitops chúng ta cần là ghi CI đã build image mới và push image lên Docker Hub thì Argocd sẽ tự động cập nhật image mới này.
và chúng ta có 1 project là ArgoCD Image Updater

Đây là link có manifest của ArgoCD Image Updater
https://raw.githubusercontent.com/argoproj-labs/argocd-image-updater/stable/manifests/install.yaml
Bạn nên cài nó chung với namespace: argocd.

Bạn sẽ chuẩn bị 1 file Application của Argocd

2) Adjusting the configuration of ArgoCD Image Updater

Đầu tiền thì ArgoCD Image Updater cần access được vào Docker Hub để monitor việc thay đổi image hay có image mới được push lên.

2.1) Access ECR

Để tương tác và lấy tocken của ECR thì bạn đọc bài này:

[AWS] Login and get secret/token/credential of ECR

Bạn có thể sài policy sau cho user:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "ecr:DescribeRepositories",
                "ecr:ListImages",
                "ecr:BatchGetImage",
                "ecr:GetDownloadUrlForLayer",
                "ecr:GetAuthorizationToken"
            ],
            "Resource": "*"
        }
    ]
}

Nếu không work thì bạn có thể tham khảo các permissions ở đây
https://pkg.go.dev/github.com/karlderkaefer/argocd-ecr-updater#section-readme

2.1.1) Using Access and Secret Key

Mình nghĩ đây là 1 cách dễ
bạn sẽ đưa cho ArgoCD Image Updater access key và secret key, Tiếp đến là nó sẽ gen ra token và tự access vào ECR.

Đâu tiên là file secret sẽ được mount thành environment của file.

secret-aws-credential.yaml
>>>>>>>>>>
>>>>>>>>>>>>

apiVersion: v1
data:
  AWS_ACCESS_KEY_ID: XXXXXXXXXXXXXXX=
  AWS_DEFAULT_REGION: dXMtZWFzdC0x
  AWS_SECRET_ACCESS_KEY: Y3RSNEpTUDFyUVI3SnVUXXXXXXXXXXXXXXXX==
kind: Secret
metadata:
  name: aws-credential
  namespace: argocd
type: Opaque

Tiếp đến là mình merge “environment from secret” vào trong deployment của helm chart. mà không cần sửa helm chart.
nếu bạn chưa biết kĩ thuật này thì tham khảo bài sau:
https://nimtechnology.com/2022/05/22/kustomize-2/

env-from-secret.yaml
>>>>>>>>>>
>>>>>>

apiVersion: apps/v1
kind: Deployment
metadata:
  name: argocd-image-updater
spec:
  template:
    spec:
      containers:
      - name: argocd-image-updater
        envFrom:
        - secretRef:
            name: aws-credential

Tiếp đến là file Kustomization

kustomization.yaml
>>>>>>>
>>>>>>>>>>>>

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
  - secret-aws-credential.yaml

patchesStrategicMerge:
  - env-from-secret.yaml

helmGlobals:
  chartHome: argocd-image-updater_0.8.0/
helmCharts:
- name: argocd-image-updater
  includeCRDs: false
  releaseName: argocd-image-updater
  version: 0.8.0 #look at
  repo: https://argoproj.github.io/argo-helm
  valuesFile: values_helm.yaml
  namespace: argocd

và có file values của helm chart.

values_helm.yaml
>>>>>
>>>>>>>>>

config:
  registries:
    - name: ECR
      api_url: https://250887682577.dkr.ecr.us-east-1.amazonaws.com
      prefix: 250887682577.dkr.ecr.us-east-1.amazonaws.com
      ping: yes
      insecure: no
      credentials: ext:/scripts/ecr-login.sh
      credsexpire: 6h
authScripts:
  enabled: true
  scripts:
    ecr-login.sh: |
      #!/bin/sh
      aws ecr --region us-east-1 get-authorization-token --output text --query 'authorizationData[].authorizationToken' | base64 -d
      ###https://github.com/argoproj-labs/argocd-image-updater/issues/422

và mình đã tham khảo ý kiến ở đây:
https://github.com/argoproj-labs/argocd-image-updater/issues/422

Repo links:

mà mình thực hiện deploy bằng argocd:

OK giờ application đã lên
Chúng ta kiêm tra log của arogcd-image-updater

Bạn sẽ thấy là arogcd-image-updater run script OK và check được image latest trên ECR.

Như Anh tây mô ta thì arogcd-image-updater integrate với nhiều Docker Registry.


this configuration “argocd-image-updater.argoproj.io/image-list:” –> You can specify one or more image(s) for each application that should be considered for updates
Bạn có thể tham khảo các link bên dưới:
– https://argocd-image-updater.readthedocs.io/en/stable/configuration/applications/
– https://argocd-image-updater.readthedocs.io/en/stable/configuration/images/

2.1.2) Access to Multiple ECRs on one Argocd-image-updater

Ở đây chúng ta cần chit 1 chút:

config:
  registries:
    - name: ecr-nimtechnology-staging
      api_url: https://YYY363500TTT.dkr.ecr.us-west-2.amazonaws.com
      prefix: YYY363500TTT.dkr.ecr.us-west-2.amazonaws.com
      ping: yes
      insecure: no
      credentials: ext:/scripts/ecr-nimtechnology-staging-login.sh
      credsexpire: 6h
    - name: ecr-nimtechnology-dev
      api_url: https://YYY701111TTT.dkr.ecr.us-west-2.amazonaws.com
      prefix: YYY701111TTT.dkr.ecr.us-west-2.amazonaws.com
      ping: yes
      insecure: no
      credentials: ext:/scripts/ecr-nimtechnology-dev-login.sh
      credsexpire: 6h
authScripts:
  enabled: true
  scripts:
    ecr-nimtechnology-staging-login.sh: |
      #!/bin/sh
      aws ecr --profile nimtechnology-staging --region us-west-2 get-authorization-token --output text --query 'authorizationData[].authorizationToken' | base64 -d
      ###https://github.com/argoproj-labs/argocd-image-updater/issues/422
    ecr-nimtechnology-dev-login.sh: |
      #!/bin/sh
      aws ecr --profile nimtechnology-dev --region us-west-2 get-authorization-token --output text --query 'authorizationData[].authorizationToken' | base64 -d

# -- Additional volumeMounts to the image updater main container
volumeMounts:
  - mountPath: "/app/.aws"
    name: multi-aws-credentials-volume

# -- Additional volumes to the image updater pod
volumes:
  - secret:
      secretName: "multi-aws-credentials"
    name: multi-aws-credentials-volume

Tiếp đến là bạn sẽ secret của mình được thiết kế như thế nào.

format giống như file credentials trên máy tính của chúng ta

3) argocd-image-updater need to access github

Gitops thì tất các yaml liên quan đến application sẽ được để trên git (VCS)
chúng ta sẽ sử dụng link như sau:

argocd-image-updater.argoproj.io/write-back-method: git:secret:argocd/git-creds

3.1) access git through Token

Giờ bạn tạo 1 secret trên k8s
trên là username dưới là token của github

kubectl --namespace argocd \
    create secret generic git-creds \
    --from-literal=username=$GITHUB_USER \
    --from-literal=password=$GITHUB_TOKEN

3.2) access git through ssh-key

https://argocd-image-updater.readthedocs.io/en/stable/basics/update-methods/#specifying-git-credentials

Tạo 1 secret và dụng key sau sshPrivateKey

kubectl -n argocd create secret generic git-creds \
  --from-file=sshPrivateKey=~/.ssh/id_rsa

4) Practicing argocd-image-updater in fact

4.1) argocd-image-updater – kustomize – manifest(deployment, service,..)

Bạn tạo 1 file devops-toolkit.yaml

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: devops-toolkit
  namespace: argocd
  finalizers:
    - resources-finalizer.argocd.argoproj.io
  annotations:
    argocd-image-updater.argoproj.io/image-list: vfarcic/devops-toolkit
    argocd-image-updater.argoproj.io/write-back-method: git:secret:argocd/git-creds
    argocd-image-updater.argoproj.io/git-branch: main
spec:
  project: default
  source:
    repoURL: https://github.com/mrnim94/argo-cd-image-updater
    targetRevision: HEAD
    path: kustomize/overlays/production
  destination:
    server: https://kubernetes.default.svc
    namespace: production
  syncPolicy:
    automated:
      selfHeal: true
      prune: true
      allowEmpty: true

Để kubectl apply -f devops-toolkit.yaml thì cluster k8s đã cài trước argocd

Khi bạn mới tạo application thì deploy sẽ lấy image có trong deployment của git.

Giờ sem log của arocd-image-updater.

Nó đã nhận nhiện được image vfarcic/devops-toolkit và chuẩn bị update tag mới cho image.
argocd-image-updater sẽ commit lên repo github.
giờ workload đã được nâng revision lên 2 và image đã được cập nhật mơi

Ngoài chúng ta có nhiều cách filter image cho đúng.
https://github.com/Masterminds/semver

Multi-arch currently only is supported for update strategies which fetch image meta-data: latest and digest. Multi-arch will be ignored for the update strategies that do not fetch meta-data, semver and name.

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

Anh tây cũng có dặn là:
– repo code of the developer and repo DevOps (integrate with argocd-image-updater) don’t stay on same repository.
– ====> Nó sẽ tạo ra loop

4.2) argocd-image-updater – kustomize – Helm chart

Hiện tại nếu anh đang deploy các workload của developer thông qua helm chart mà team devops tự custom thì bạn có thể thao khảo cách bên dưới.

Đầu tiên bạn có public helm repo và bạn có thể tham khảo repo này của Nim
https://github.com/mrnim94/kubernetes-manifest

Bạn nhớ là repo phải có index.yaml nhé

Tiếp theo bạn cần chuận bị 1 repo chứa kutomization của các workload.
https://github.com/mrnim94/meta-workloads/tree/begin

Bạn cũng nên nhờ là each workload have a individual folder
2 workload không thể chung 1 folder vì sẽ có nhiều tình huống sảy ra.
>>>>>>>>>>>
kustomization.yaml
>>>>>>>>>>>>>>>>>>>>>

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
helmCharts:
- name: nimtechnology
  includeCRDs: false
  releaseName: workload1
  version: 0.1.0 #look at
  repo: https://raw.githubusercontent.com/mrnim94/kubernetes-manifest/master/
  # valuesFile: values_helm.yaml
  namespace: default

Bạn tạo file dưới và kubectl apply -f production-3.yaml

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: workload1
  namespace: argocd
  finalizers:
    - resources-finalizer.argocd.argoproj.io
  annotations:
    argocd-image-updater.argoproj.io/image-list: nginx
    argocd-image-updater.argoproj.io/write-back-method: git:secret:argocd/git-creds
    argocd-image-updater.argoproj.io/git-branch: master
    argocd-image-updater.argoproj.io/write-back-target: kustomization
spec:
  project: default
  source:
    repoURL: https://github.com/mrnim94/meta-workloads
    targetRevision: HEAD
    path: project1/env1/workload1
    plugin:
      name: kustomize-build-with-helm
  destination:
    server: https://kubernetes.default.svc
    namespace: production
  syncPolicy:
    automated:
      selfHeal: true
      prune: false
      allowEmpty: true
Bạn để ý workload vẫn revision là 1

Mình thực hiện quan sat log của “argocd-image-updater”

Tiếp đến là bạn sẽ thấy “argocd-image-updater” sẽ commit lên branch master
và thêm thông số image.

Bạn thây là workload đã được cập nhật image mới.

4.3) argocd-image-updater integrate helm chart (folder on Git)

https://www.alibabacloud.com/blog/use-git-appcenter-and-container-registry-to-create-a-gitops-pipeline-to-automate-container-image-updates_599413
https://www.padok.fr/en/blog/argocd-image-updater
https://argocd-image-updater.readthedocs.io/en/v0.7.0/configuration/images/
https://garden.io/blog/argo-cd-helm-charts

Đầu tiên tạo 1 helm-chart và lưu trên 1 folder trên github:

Tiếp đến bạn tạo 1 file Application và apply cho argocd:





4.4) argocd-image-updater integrate helm package.

Đầu tiên mình có 1 build helm chart và package helm chart ở link này:
https://github.com/mrnim94/kubernetes-manifest

sau đó bạn tạo 1 file application và chúng ta sẽ có 1 số an

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  annotations:
    argocd-image-updater.argoproj.io/dockerhub.helm.image-name: image.repository
    argocd-image-updater.argoproj.io/dockerhub.helm.image-tag: image.tag
    argocd-image-updater.argoproj.io/dockerhub.update-strategy: latest
    argocd-image-updater.argoproj.io/image-list: dockerhub=mrnim94/node-demo-app
  name: node-demo-app
  namespace: argocd
spec:
  destination:
    name: in-cluster
    namespace: default
  project: default
  source:
    chart: nimtechnology
    helm:
      parameters:
        - forceString: true
          name: image.repository
          value: mrnim94/node-demo-app
        - forceString: true
          name: image.tag
          value: v3
      valueFiles:
        - values.yaml
      values: |-
        image:
          repository: mrnim94/node-demo-app
          tag: v2
    repoURL: https://raw.githubusercontent.com/mrnim94/kubernetes-manifest/master
    targetRevision: 0.1.2

Argocd Image Updater đọc annotations trong file application của argocd. và thực hiện watch image: mrnim94/node-demo-app

Lúc đó mình thực hiện build image mới. và push lên docker hub.

Sau đó thì argocd-image-updater đã detected được image mới.

Ở phần chúng ta không khai báo owner github vậy argocd-image-updater sẽ commit vào đâu.
Mình thực hiện kiểm tra trên argocd.

Nó thực hiện edit trên k8s chăng.

Vì mình không để auto sync nên là chúng ta cần manual sync


5) Invalid Semantic Version

Argocd Image Updater mặc định nó sẽ đọc tag theo chuẩn “SemVer”
https://github.com/semver/semver

Nếu image của bạn không theo sematic version thì sẽ gặp lỗi sau:
time=”2022-10-25T02:43:01Z” level=debug msg=”could not parse input tag staging-ccd8f0b5-linux as semver: Invalid Semantic Version”

Tag của mình đắng rất là ngao ngơ. và mình nghĩ là nhiều bạn devops cũng đang đánh như ví dụ này:

313363500340.dkr.ecr.us-west-2.amazonaws.com/nim_engines_apiv4_result_producer:staging-ccd8f0b5-linux

Vậy bạn cần điều chỉnh anotation của Kind Application như sau:

annotations:
    ....
    argocd-image-updater.argoproj.io/image-list: >-
      myrepo=313363500340.dkr.ecr.us-west-2.amazonaws.com/nim_engines_apiv4_result_producer
    argocd-image-updater.argoproj.io/myrepo.update-strategy: latest
......

Đầu tiên là bạn đánh alias
https://argocd-image-updater.readthedocs.io/en/stable/configuration/images/#annotation-format

[<alias_name>=]<image_path>[:<version_constraint>]
>>>>
>>>>>>
myrepo=313363500340.dkr.ecr.us-west-2.amazonaws.com/nim_engines_apiv4_result_producer

Bạn configure strategy:
https://argocd-image-updater.readthedocs.io/en/stable/configuration/images/#update-strategies

StrategyDescription
semverUpdate to the tag with the highest allowed semantic version
latestUpdate to the tag with the most recent creation date
nameUpdate to the tag with the latest entry from an alphabetically sorted list
digestUpdate to the most recent pushed version of a mutable tag

Mình sẽ cung cấp thêm cho bạn các declarations để các bạn tham khảo thêm

annotations:
    argocd-image-updater.argoproj.io/git-branch: master
    argocd-image-updater.argoproj.io/image-list: >-
      myrepo=313363500340.dkr.ecr.us-west-2.amazonaws.com/nim_engines_apiv4_result_producer
    argocd-image-updater.argoproj.io/myrepo.allow-tags: regexp:^staging-.*-linux$
    argocd-image-updater.argoproj.io/myrepo.force-update: 'true'
    argocd-image-updater.argoproj.io/myrepo.helm.image-name: image.repository
    argocd-image-updater.argoproj.io/myrepo.helm.image-tag: image.tag
    argocd-image-updater.argoproj.io/myrepo.update-strategy: latest
    argocd-image-updater.argoproj.io/write-back-method: git:secret:argocd/git-creds
    argocd-image-updater.argoproj.io/write-back-target: kustomization

Reference Links:.
https://github.com/argoproj-labs/argocd-image-updater/issues/218

Issues

Multiple images update

https://github.com/argoproj-labs/argocd-image-updater/issues/365

Argocd Image Updater doesn’t update images for Your application.

you need to enable “debug mode” trong configmap

Lúc này bạn quan sát các logs có liên quan đến application mà ko được update image:

time="2023-08-25T17:17:11Z" level=debug msg="ignoring v2 manifest sha256:5f933f82cd16549036fd1b131f80614cdc2553533ce73d5137e34a6c1689c791. Manifest platform: windows/amd64, requested: linux/amd64" alias=windows application=xxx-xxx-windows-dev image_name=xxx_xxx_engine image_tag=dev-2905fda1-windows registry=XXXXXXXXXX.dkr.ecr.us-west-2.amazonaws.com

ở đây thì bạn có thể thấy argocd image updater đang ignore image vì “Manifest platform: windows/amd64, requested: linux/amd64“
==> nghĩa là request default là linux/amd64 nhưng image của mình là windows/amd64
=====> Nó không match nhau về platform nên đã bị ignored.

Ở release https://github.com/argoproj-labs/argocd-image-updater/releases/tag/v0.12.0 thì họ cũng nói về vấn đề: Multi arch

  • Multi-arch deliverables are finally here! We now provide container images for linux/amd64 and linux/arm64, as well as release binaries for linux/amd64, linux/arm64, linux/ppc64le, darwin/amd64, darwin/arm64 as well as windows/amd64!
  • Multi-arch support for container images: Argo CD Image Updater now also considers the architecture of container images and provides full support for multi-arch images by being able to inspect manifest lists. By default, when using an update strategy that supports meta data inspection (latest and digest), Argo CD Image Updater will now only consider manifests for the same architecture it is running on. This can be fine tuned on a per image basis, so if you have clusters with nodes spanning multiple architectures (e.g. mix of amd64 and arm64 nodes), and you know that certain workloads are bound to run on a given architecture, you can use the new <alias>.platforms annotation to allow only updates to images that match a certain architecture.

===> chúng ta cần thêm
argocd-image-updater.argoproj.io/ecr_repo_win.platforms: 'windows/amd64' vào annotation.

ArgoCD

Post navigation

Previous Post: [Kafka] How many partitions are enough in a topic on Kafka?
Next Post: [Helm chart] Where will you save or push helm packages?

More Related Articles

[kubectl/Argocd] How to create a kubectl config file for serviceaccount or from the cluster secret of Argocd ArgoCD
[Argocd] Designing Gitops model is implemented by argocd ArgoCD
[Argocd – Azure] Login to ArgoCD using Microsoft or Azure Accounts. ArgoCD
[Argo-Notification] fix the problem: bad character U+005B ‘[‘  ArgoCD
[ArgoCD] Cài đặt argocd cli và connect với ArgoCD ArgoCD
[ArgoCD] Hướng dẫn tạo “local user” trên argocd ArgoCD

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Tham Gia Group DevOps nhé!
Để Nim có nhiều động lực ra nhiều bài viết.
Để nhận được những thông báo mới nhất.

Recent Posts

  • [Azure/Loadbalancer] Creating an internal load balancer on Azure Kubernetes Service (AKS). May 13, 2025
  • [Azure] The subscription is not registered to use namespace ‘Microsoft.ContainerService’ May 8, 2025
  • [Azure] Insufficient regional vcpu quota left May 8, 2025
  • [WordPress] How to add a Dynamic watermark on WordPress. May 6, 2025
  • [vnet/Azure] VNet provisioning via Terraform. April 28, 2025

Archives

  • May 2025
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • July 2024
  • June 2024
  • May 2024
  • April 2024
  • March 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • September 2023
  • August 2023
  • July 2023
  • June 2023
  • May 2023
  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021

Categories

  • BareMetal
    • NextCloud
  • CI/CD
    • Argo Events
    • ArgoCD
    • ArgoWorkflows
    • Git
      • Bitbucket
    • Harbor
    • Jenkins
    • Spinnaker
    • TeamCity
  • Coding
    • DevSecOps
    • Golang
    • Jquery & JavaScript
    • Laravel
    • NextJS 14 & ReactJS & Type Script
    • Python
    • Selenium
    • Terraform
      • AWS – Amazon Web Service
      • Azure Cloud
      • GCP – Google Cloud
  • Kubernetes & Container
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Docker
    • Helm Chart
    • Isito-EnvoyFilter
    • Kong Gateway
    • Kubernetes
      • Ingress
      • Pod
    • Longhorn – Storage
    • MetalLB
    • OAuth2 Proxy
    • Vault
    • VictoriaMetrics
  • Log, Monitor & Tracing
    • DataDog
    • ELK
      • Kibana
      • Logstash
    • Fluent
    • Grafana
    • Prometheus
  • Uncategorized
  • Admin

Copyright © 2025 NimTechnology.