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.

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:
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:


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

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
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


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




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

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

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

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.


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
| Strategy | Description |
|---|---|
semver | Update to the tag with the highest allowed semantic version |
latest | Update to the tag with the most recent creation date |
name | Update to the tag with the latest entry from an alphabetically sorted list |
digest | Update 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/amd64andlinux/arm64, as well as release binaries forlinux/amd64,linux/arm64,linux/ppc64le,darwin/amd64,darwin/arm64as well aswindows/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 (
latestanddigest), 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>.platformsannotation 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.