Infra & DevOps/CICD

[ArgoCD] ArgoCD 설치 및 실습

용감한 개복치 2024. 4. 20. 20:35

Argo

개념

ArgoCD란?

- gitops를 구현하기 위해 쿠버네티스 어플리케이션 자동배포를 위한 오픈소스

- ci/cd 중 cd 를 담당

- 선언적 어플리케이션 관리를 사용 : 명시적으로 원하는 상태를 선언, argoCD가 클러스터 상태와 비교하여 선언된 상태로 유지

- 활용 ci/cd 아키텍처

출처 : 스터디 자료

  • api 서버 : Web UI, CLI 및 CI/CD 시스템에서 사용되는 API를 노출하는 gRPC/REST 서버
    • 애플리케이션 관리 및 상태 보고
    • 애플리케이션 작업 호출 (예: 동기화, 롤백, 사용자 정의 작업)
    • 리포지토리 및 클러스터 자격 증명 관리 (K8s 시크릿으로 저장)
    • 외부 식별 공급자로의 인증 및 인증 위임
    • RBAC 시행
    • Git 웹훅 이벤트를 수신 및 전달하는 리스너/포워더
       
       
       
  • Repository Server : Git 연결 및 배포할 yaml 생성
    • 애플리케이션 매니페스트를 보관하는 Git 저장소의 로컬 캐시를 유지하는 내부 서비스
    • 다음 입력이 제공될 때 Kubernetes 매니페스트를 생성하고 반환
  • Application Controller : k8s 리소스 모니터링, Git과 비교
    • 지속적으로 실행 중인 애플리케이션을 모니터링하고 현재 라이브 상태를 저장소에 지정된 목표 상태와 비교하는 Kubernetes 컨트롤러
    • OutOfSync 애플리케이션 상태를 감지하고 선택적으로 보정 조치
    • 라이프사이클 이벤트 (PreSync, Sync, PostSync)에 대한 사용자 정의 후크를 호출

- 동작방식

  1. Git에 push, k8s 배포 방식인 helm / kustomize 사용
  2. argoCD 가 git 저장소의 상태 변경 감지
  3. 변경 내용을 k8s에 배포, 반영

 

실습 : gui

helm을 이용한 설치

# helm 설치
cat <<EOT > argocd-values.yaml
global:
  domain: argocd.$MyDomain

configs:
  params:
    server.insecure: true

controller:
  metrics:
    enabled: true
    serviceMonitor:
      enabled: true

server:
  ingress:
    enabled: true
    controller: aws
    ingressClassName: alb
    hostname: "argocd.$MyDomain"
    annotations:
      alb.ingress.kubernetes.io/scheme: internet-facing
      alb.ingress.kubernetes.io/target-type: ip
      alb.ingress.kubernetes.io/backend-protocol: HTTP
      alb.ingress.kubernetes.io/listen-ports: '[{"HTTPS":80}, {"HTTPS":443}]'
      alb.ingress.kubernetes.io/certificate-arn: $CERT_ARN
      alb.ingress.kubernetes.io/ssl-redirect: '443'
    aws:
      serviceType: ClusterIP
      backendProtocolVersion: GRPC
  metrics:
    enabled: true
    serviceMonitor:
      enabled: true

repoServer:
  metrics:
    enabled: true
    serviceMonitor:
      enabled: true

applicationSet:
  metrics:
    enabled: true
    serviceMonitor:
      enabled: true

notifications:
  metrics:
    enabled: true
    serviceMonitor:
      enabled: true
EOT

kubectl create ns argocd
helm repo add argo https://argoproj.github.io/argo-helm
helm install argocd argo/argo-cd --version 6.7.11 -f argocd-values.yaml --namespace argocd

# 확인
kubectl get ingress,pod,svc -n argocd
kubectl get crd | grep argo

# 최초 접속 암호 확인
kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d ;echo
#Zhl8OmU3sRGl9eEk

 

최초 접속

https://argocd.peachengineer.click/

 

Argo CD

 

argocd.peachengineer.click

 

admin / 위에 나온 비밀번호는 user info > UPDATE PASSWORD 변경

 

위 화면에서 + 로 app create

 

sync > synchronize 로 배포

 

모니터링 : 새로운 파드 생성 확인

watch -d kubectl get deploy -n first --show-labels

 

gui 에서 확인

 

리소스 클릭 후 확인 : 각각 LIVE MANIFEST(쿠버네티스 정보)

 

라벨에 추가됨

 

k8s에서 직접 수정 → argocd 싱크(반영) 확인

# 아래 추가
kubectl edit deploy -n first myweb
...
  labels:
    add: label-test
    add2: k8s-test
...

 

but, diff 에서는 확인 x

 

Git 레포에서 값 변경 > commit > diff 확인

 

현재 상태는, Git을 기준으로 보자면 LIVE MANIFEST(K8S)형상이 뒤떨어진것으로 볼 수 있다 → OutOfSync 상태니 Sync

 

실습 : cli

Argo CD cli 설치

#
curl -sSL -o argocd-linux-amd64 https://github.com/argoproj/argo-cd/releases/latest/download/argocd-linux-amd64
sudo install -m 555 argocd-linux-amd64 /usr/local/bin/argocd
rm -f argocd-linux-amd64

#
argocd version

#
argocd login argocd.$MyDomain
Username: admin
Password: ###
'admin:login' logged in successfully

#
kubectl config get-contexts -o name
argocd cluster add peach@myeks.ap-northeast-2.eksctl.io
y 입력

#
argocd app list

 

Application 생성 with CLi

#
kubectl config set-context --current --namespace=argocd
argocd app create guestbook --repo https://github.com/argoproj/argocd-example-apps.git --path guestbook --dest-server https://kubernetes.default.svc --dest-namespace default

#
argocd app list

 

sync 어플리케이션

#
argocd app get guestbook

# 모니터링
watch -d kubectl get pod,svc,ep

#
argocd app sync guestbook

 

삭제

argocd app delete guestbook
Are you sure you want to delete 'guestbook' and all its resources? [y/n] y

# ns default 로 변경
kubectl ns default

 

개념

Argo Rollouts 란?

- Kubernetes 위에 구축된 애플리케이션 배포를 관리하는 오픈 소스 롤링 업데이트 및 릴리스 관리 도구

- 기능

  1. 롤링 업데이트 및 롤백 관리: Argo Rollouts는 애플리케이션의 새로운 버전을 롤아웃하고 이전 버전으로 롤백하는 것과 같은 롤링 업데이트 및 롤백을 관리합니다. 이를 통해 애플리케이션의 신뢰성과 안정성을 유지하면서 업데이트를 수행할 수 있습니다.
  2. 블루-그린 배포: 블루-그린 배포는 새로운 버전의 애플리케이션을 기존 버전과 완전히 분리된 환경에서 테스트할 수 있는 기능을 제공합니다. Argo Rollouts는 블루-그린 배포를 지원하여 안정성을 향상시키고 사용자들에게 무중단 서비스를 제공합니다.
  3. 카나리아 배포: 카나리아 배포는 새로운 버전의 애플리케이션을 일부 사용자 또는 특정 환경에 먼저 릴리스하여 문제를 사전에 발견하고 안정성을 확보하는 방법입니다. Argo Rollouts는 카나리아 배포를 쉽게 설정하고 관리할 수 있습니다.
  4. 프로모션 전략: Argo Rollouts는 배포 전략을 정의하여 특정 조건에 따라 배포를 자동으로 진행하거나 일시 중단하는 등의 작업을 수행할 수 있습니다. 이를 통해 유연한 배포 전략을 구성할 수 있습니다.
  5. 프로모션 상태 모니터링: 롤링 업데이트 또는 롤백 중에도 Argo Rollouts는 애플리케이션의 상태를 모니터링하고 프로모션의 진행 상황을 실시간으로 추적할 수 있습니다. 이를 통해 배포 프로세스의 투명성을 확보할 수 있습니다.

- 동작방식

 

- 배포 전략

  • Blue-Green
  • Canary
    • 출처 : 스터디 자료

 

- 특징

  • 세밀한 가중치 기반 트래픽 이동
  • 자동 롤백 및 프로모션
  • 수동 판단
  • 사용자 정의 메트릭 쿼리 및 비즈니스 KPI 분석
  • 인그레스 컨트롤러 통합: NGINX, ALB, Apache APISIX
  • 서비스 메시 통합: Istio, Linkerd, SMI
  • 여러 공급자 동시 사용: SMI + NGINX, Istio + ALB 등
  • 메트릭 제공자 통합: Prometheus, Wavefront, Kayenta, Web, Kubernetes Jobs, Datadog, New Relic, Graphite, InfluxDB

 

실습

 

설치

#
cat <<EOT > argorollouts-values.yaml
dashboard:
  enabled: true
  ingress:
    enabled: true
    ingressClassName: alb
    hosts:
      - argorollouts.$MyDomain
    annotations:
      alb.ingress.kubernetes.io/scheme: internet-facing
      alb.ingress.kubernetes.io/target-type: ip
      alb.ingress.kubernetes.io/backend-protocol: HTTP
      alb.ingress.kubernetes.io/listen-ports: '[{"HTTPS":80}, {"HTTPS":443}]'
      alb.ingress.kubernetes.io/certificate-arn: $CERT_ARN
      alb.ingress.kubernetes.io/ssl-redirect: '443'
EOT

kubectl create ns argo-rollouts
helm install argo-rollouts argo/argo-rollouts --version 2.35.1 -f argorollouts-values.yaml --namespace argo-rollouts

# 확인
kubectl get all -n argo-rollouts
kubectl get crd | grep argo

 

 

rollout cli 설치

#
curl -LO https://github.com/argoproj/argo-rollouts/releases/download/v1.6.4/kubectl-argo-rollouts-linux-amd64
chmod +x ./kubectl-argo-rollouts-linux-amd64
mv ./kubectl-argo-rollouts-linux-amd64 /usr/local/bin/kubectl-argo-rollouts

# 설치 확인
kubectl argo rollouts version

 

deploy rollout : canary

spec:
  replicas: 5
  strategy:
    canary:
      steps:
      - setWeight: 20
      - pause: {}
      - setWeight: 40
      - pause: {duration: 10}
      - setWeight: 60
      - pause: {duration: 10}
      - setWeight: 80
      - pause: {duration: 10}

신규 20% > pause > 신규 40% > pause 10s > 신규 60% > pause 10 > 신규 80% > pause 10s

 

# Run the following command to deploy the initial Rollout and Service:
kubectl apply -f https://raw.githubusercontent.com/argoproj/argo-rollouts/master/docs/getting-started/basic/rollout.yaml
kubectl apply -f https://raw.githubusercontent.com/argoproj/argo-rollouts/master/docs/getting-started/basic/service.yaml

 

확인

kubectl argo rollouts get rollout rollouts-demo
kubectl argo rollouts get rollout rollouts-demo --watch

 

새 이미지로 디플로이 한 번 더해보기

# Run the following command to update the rollouts-demo Rollout with the "yellow" version of the container:
kubectl argo rollouts set image rollouts-demo rollouts-demo=argoproj/rollouts-demo:yellow

 

promoting a rollout

# 아래 입력 혹은 UI에서 Promote Yes 클릭
kubectl argo rollouts promote rollouts-demo

#
kubectl argo rollouts get rollout rollouts-demo --watch

 

Aborting a Rollout

# 
kubectl argo rollouts set image rollouts-demo rollouts-demo=argoproj/rollouts-demo:red

#
kubectl argo rollouts abort rollouts-demo

#
kubectl argo rollouts set image rollouts-demo rollouts-demo=argoproj/rollouts-demo:yellow

'Infra & DevOps > CICD' 카테고리의 다른 글

[Jenkins]Jenkins 설치 및 실습  (0) 2024.04.19