[k8s] ArgoCD: Image Updater
๊ด๋ จ ํฌ์คํธ
https://blog.naver.com/sssang97/223122991133
ArgoCD๋ pull ๋ฐฉ์์ gitops ๋ฐฐํฌ๋ฅผ ๊ตฌํ๊ฐ๋ฅ์ผ ํด์ฃผ๋ ๋ณด์กฐ๋๊ตฌ๋ค.
์ค์

์ค์น
์๋ ๋ช ๋ น์ ์ฌ์ฉํด์ ๊ด๋ จ ์ค์ ๋ค์ ์ค์นํ๋ค.
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj-labs/argocd-image-updater/stable/manifests/install.yaml

๊ณ์ ๊ตฌ์ฑ
๊ทธ๋ฆฌ๊ณ edit์ผ๋ก configmap์ ๊ณ์ ์ ๋ณด๋ฅผ ์ถ๊ฐํด์ค๋ค.
kubectl edit configmap argocd-cm -n argocd

์ด๋ฆ์ apiKey๋ก ํ๋ค.
accounts.image-updater: apiKey

๊ทธ๋ฆฌ๊ณ account list๋ก ํ์ธํ๋ฉด ์ถ๊ฐ๋ ๊ฒ์ ํ์ธํ ์ ์์ ๊ฒ์ด๋ค.

๊ทธ๋ฆฌ๊ณ ๋ฐฉ๊ธ ๋ง๋ ๊ณ์ ์ ๊ถํ์ ์ถ๊ฐํด์ค๋ค.
kubectl edit configmap argocd-rbac-cm -n argocd

data:
policy.csv: |
p, role:image-updater, applications, get, */*, allow
p, role:image-updater, applications, update, */*, allow
g, image-updater, role:image-updater
policy.default: role.readonly

updater ๊ตฌ์ฑ
๋ ํ๋์ configmap์ ๋ค์ด๊ฐ์ ์ถ๊ฐ ํ๋๋ค์ ๋ฃ์ด์ค๋ค.
kubectl edit configmap argocd-image-updater-config -n argocd

์ด๋ ๊ฒ ๋ฃ์ด์ฃผ๋ฉด ๋๋ค.
data:
applications_api: argocd
argocd.server_addr: ์ฃผ์
argocd.grpc_web: "true"
argocd.insecure: "false"
argocd.plaintext: "true"


updater์ ๊ถํ ๋ถ์ฌ
image-updater์์ ์ฌ์ฉํ argocd ์ ๊ทผ์ฉ ํ ํฐ์ ๋ง๋ค๊ณ
argocd account generate-token --account image-updater --id image-updater

๊ทธ๊ฑธ ์ ์ ํ ์ ์ฉํด์ค๋ค.
YOUR_TOKEN์ ๋ฐฉ๊ธ ํ ํฐ์ ๋ฃ์ด์ฃผ๋ฉด ๋๋ค.
kubectl create secret generic argocd-image-updater-secret \
--from-literal argocd.token=$YOUR_TOKEN --dry-run -o yaml |
kubectl -n argocd apply -f -

๋ ์ง์คํธ๋ฆฌ ๋ฑ๋ก
์ฌ์ฉํ ๋์ปค ๋ ์ง์คํธ๋ฆฌ ์ ๋ณด๋ ์ฌ๊ธฐ์ ๋ฃ์ด์ค์ผ ํ๋ค.
Docker hub์ public ๋ ํฌ์งํ ๋ฆฌ๋ฅผ ๋ฑ๋กํ๋ค๊ณ ํ๋ฉด, ์ด๋ ๊ฒ ํ ์ ์๋ค.
kubectl edit configmap argocd-image-updater-config -n argocd registries.conf: |
registries:
- name: docker
api_url: https://registry-1.docker.io
prefix: docker.io
ping: yes
tagsortmode: latest-last

ํผ๋ธ๋ฆญ ๋ ํฌ์งํ ๋ฆฌ๋ผ ์ ๊ฒฝ์ธ ๊ฒ์ด ์๋๋ฐ, ์ฌ์ค ํ๋ก๋์
์์๋ private์ ์ฌ์ฉํ ์ผ์ด ํจ์ฌ ๋ง์ ๊ฒ์ด๋ค.
private ๋ ์ง์คํธ๋ฆฌ๋ฅผ ์ฌ์ฉํ ๋๋ credentials ํ๋์ ์ ๊ทผ์ฉ ํค๋ฅผ ์ถ๊ฐ๋ก ์ ๋ฌํด์ค์ผ ํ๋ค.
updater ์์ ์ฌํญ ๋ฐ์
updater์ ์ค์ ์ ๋ณ๊ฒฝํ๋ค๊ณ ํ๋๋ผ๋, ๊ทธ๊ฒ ๋ฆฌ์ผํ์์ผ๋ก ๋ฐ์๋์ง๋ ์๋๋ค.
๊ทธ๋์ ์์ ํ๊ฑธ ๋ฐ์์ํค๋ ค๋ฉด pod๋ฅผ ์ฃฝ์ด๊ณ ์๋ก ๋์ฐ๋๋ก ํด์ผํ๋ค.
kubectl -n argocd rollout restart deployment argocd-image-updater

updater ์ฐ๊ฒฐ ์ํ ํ์ธ
๋ ์ง์คํธ๋ฆฌ๋ฅผ ๋ฑ๋กํ๊ฒ ์ ๋์๋์ง๋ ํ์ธํด๋ณด์.
pod ๋ชฉ๋ก์ ํ์ธํด์ updater ํ๋์ ๋ค์ด๊ฐ ๋ค์

argo-image-updater cli๋ก ํน์ ๋ ์ง์คํธ๋ฆฌ์ ์ ๊ทผ์ด ๊ฐ๋ฅํ์ง ํ์ธ์ ํด๋ณผ ์ ์๋ค.
argocd-image-updater test docker.io/myyrakle/node-server-for-test
์ฌ๊ธฐ์ ๋ญ๊ฐ ๋ฌธ์ ๊ฐ ๋ฐ์ํ๋ฉด ๊ทธ๊ฒ๋ถํฐ ํด๊ฒฐํ๋ฉด ๋๋ค.
๋ฐฐํฌ
๋ฐฐํฌ๋ ๊ทธ๋ฅ ์ง์ ํด๋ ๋ ์ง์คํธ๋ฆฌ์ pushํ๋ ๊ฒ๋ง์ผ๋ก ๋ค ๋๋ผ ์ ์๋ค.
์ ๋ฒ์ ์ ์ฌ๋ฆฌ๋ฉด image updater๊ฐ ๊ฐ์งํ๊ณ , ์ด๋ฏธ์ง๋ฅผ ๊ต์ฒดํ๋ ๊ฒ์ด๋ค.
์ด๋ฅผ ํตํด ์ด๋ฏธ์ง ๋น๋ ํ๋ก์ธ์ค์ ์ค์ ๋ฐฐํฌ ํ๋ก์ธ์ค์ ์ ์ด๊ถ์ ๋ถ๋ฆฌํ ์ ์๋ค.
image updater์ ํด๋ง ์ฃผ๊ธฐ๋ 2๋ถ ์ ๋๋ผ๊ณ ํ๋ค. ์์ฒญ ๋น ๋ฅด์ง๋ ์๋ค.
์ฐธ์กฐ
https://velog.io/@junsugi/Argo-CD-Image-Updater-%EC%82%AC%EC%9A%A9%ED%95%98%EA%B8%B0-with.-AWS-EKS
https://argocd-image-updater.readthedocs.io/en/stable/install/installation/
https://stackoverflow.com/questions/34198392/docker-official-registry-docker-hub-url