7주차 - EKS CI/CD - ArgoCD / ArgoRollouts

728x90

ArgoCD란

 

ArgoCD는 쿠버네티스를 위한 CD(Continuous Delivery)도구로

GitOps방식으로 관리되는 Mainfest(yaml)파일의 변경사항을 감시하여, 현재 배포되어 있는 환경의 상태와 / Git Manifest파일에 정의된 상태를 동일하게 유지 하는 역학을 수행

 

 

ArgoCD 아키텍처

 

 

 

 구성요소

  •  API Server: Web UI, API 서버
  • Repository Server: Git 연결 및 배포할 yaml 생성
  • Application Controller: k8s 리소스 모니터링, Git 비교 
  • redis: k8s와 git요청을 줄이기 위한 캐싱
  • Notification: 이벤트 알림, 트리거
  • Dex: 외부 인증 관리
  • ApplicationSet Controller: 멀티 클러스터를 위한 App 패키징 관리

 설치

# 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
applications.argoproj.io                     2024-04-14T08:12:16Z
applicationsets.argoproj.io                  2024-04-14T08:12:17Z
appprojects.argoproj.io                      2024-04-14T08:12:16Z

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

 

ArgoCD 실습 - Directory

1. Web Console 화면에서 Application 생성

 

2. APP생성 옵션

  • SYNC POLICY: Git 소스와 sync 시 자동 or 수동 설정

 

3. Source / Destination 설정

  • Source: k8s manifest(yaml) 파일 저장소 - Github
  • path: repository 내 yaml파일 경로  
  • Destination: 클러스터 svc 주소
  • namespace: 클러스터에서 사용할 namespace / 위 auto-create namespace 설정으로 인하여 없다면 자동으로 생성

 

4. Directory 설정

  • argoCD의 경우 manifest파일에 대하여 kustommize / helm / jsonnet files, Directory 등으로 지정 할 수 있음
  • 이번 실습에서는 기본적인 Directory모드로 진행

 

4. App 생성

  • 신규 APP 생성 시 EKS와 Git에 저장된 내용과 다르기 때문에 OutofSync 상태

 

5. 배포

  • App에서 Sync버튼을 눌러 배포
  • Sync 진행 시 git에 배포되어 있는 manifest파일을 통하여 eks 클러스터에 deploy 배포

 

6. 확인

  • LIVE MANIFEST: 현재 k8s에 배포되어 있는 resource에 대한 manifest 상태
  • DESIRED MANIFEST : GIT에 배포되어 있는 manifest 상태
  • DIFF: 위 LIVE MANIFEST와 DESIRED MANIFEST 비교

 

6-1. LIVE MANIFEST or EKS 내에서 label 추가

  • LIVE MANIFEST에서 lable추가 시 클러스터에는 정상적으로 반영 되지만 DIFF에서 DESIRED MANIFEST와 차이점에 대해서 확인 불가능

  • EKS 내에서 label 추가 시 클러스터에는 정상적으로 반영 되지만 DIFF에서 DESIRED MANIFEST와 차이점에 대해서 확인 불가능

※ ArgoCD 철학은 Git에서의 변경사항을 탐지하여 k8s에 반영 / 배포하는 것이기 때문에 Git을 통한 변경이 아닌 경우 확인 or 반영 X

 

  • git에서 yaml파일 수정 시 정상적으로 DIFF를 통해 변경된 부분을 확인 할 수 있으며 DESIRED MANIFEST에도 정상적으로 확인

 

 

ArgoCD 실습 - CLI

  • jenkins에서 사용(명령어) 위한 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

#Web Console 로그인과 동일하게 CLI에서 ArgoCD 로그인
argocd login argocd.$MyDomain
Username: admin
Password: ###
'admin:login' logged in successfully

#로그인 후 현재 사용 중인 context를 등록
kubectl config get-contexts -o name
admin@myeks.ap-northeast-2.eksctl.io
argocd cluster add admin@myeks.ap-northeast-2.eksctl.io
y 입력

#kubeclt 명령어와 비슷하게 get 명령어를 통하여 확인
argocd app list
NAME  CLUSTER  NAMESPACE  PROJECT  STATUS  HEALTH  SYNCPOLICY  CONDITIONS  REPO  PATH  TARGET

 

#
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

# app list 확인
argocd app list
NAME              CLUSTER                         NAMESPACE  PROJECT  STATUS     HEALTH   SYNCPOLICY  CONDITIONS  REPO                                                 PATH       TARGET
argocd/guestbook  https://kubernetes.default.svc  default    default  OutOfSync  Missing  <none>      <none>      https://github.com/argoproj/argocd-example-apps.git  guestbook

# app 정보 확인
argocd app get guestbook

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

#싱크
argocd app sync guestbook

 

  • argocd app create 명령어를 통하여 APP 생성

 

  • argocd app get 명령어를 통하여 APP 확인

 

  • argocd app sync 명령어를 통하여 sync 진행

 

 

ArgoRollouts이란

 

K8S에서는 다양한 방식으로 Application Update를 지원한다. Argo Rollouts은 K8S의 업데이트를 쉽고 직관적으로 확인 할 수 있게 하는 업데이트 도구이다.

  • BLUE/Green Update: 구 버전 Application과 신 버전 Application을 모두 동작한 상태에서 트래픽만 신 버전으로 전환하는 업데이트 방식 
  • Canary Update: 업데이트 시 기존 버전을 유지한 채로 일부 버전만 신규 버전으로 올려서 신규 버전에 버그나 이상이 없는지 확인하는 방법
  • Rolling update: 업데이트 시 설정된 replicas를 보장하면서 신규버전 배포 / 기존 버전 삭제를 순차적으로 진행하면서 업데이트 하는 방식

 

 

 Rollouts 설치

#
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

# argorolloutscli 설치
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

 

 실습 - canary 업데이트

spec:
  replicas: 5
  strategy:
    canary:
      steps:
      - setWeight: 20   // 신규 버전 비중 20프로
      - pause: {} // 대기
      - setWeight: 40 // 신규 버전 비중 40프로
      - pause: {duration: 10}
      - setWeight: 60 // 신규 버전 비중 60프로
      - pause: {duration: 10}
      - setWeight: 80 // 신규 버전 비중 80프로
      - pause: {duration: 10}
      
# 공싱 demo yaml파일 다운 및 설치
# 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

 

  • argo rollout cli를 통하여 상태 확인 / canary

 

 

  • rollout 진행 → rollout-demo에 이미지 변경
#
watch -d kubectl get pod -n argocd -l app=rollouts-demo -owide --show-labels

# 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

 

  • rollout 진행 시 정해진 Step에 의해서 순차적으로 신규 Pod가 생성되고 기존 Pod는 삭제

 

728x90