본문 바로가기
DevOps 잡다구리/Kubernetes Stuff

[Kubernetes] ArgoCD Operator on Kubernetes with OLM

by WhiteGoblin 2022. 6. 17.
반응형
  1. ArgoCD Operator install
     CICD 가 대세가 된 요즘에 가장 많이 주목 받는 툴 중 하나가 바로 ArgoCD 이다 ArgoCD 의 경우 간단하게 설명 하면 github 에 repo 를 통해서 서비스를 지속적으로 원하는 상태로 유지시켜주는 툴이라고 보면 된다. 이 과정에서 yaml 파일을 이용한다. 이러한 ArgoCD 가 Operator 패턴이 있다고 하여서 ArgoCD 를 공부할겸 Operator 를 통해 ArgoCD 실습을 진행해보겠다.
  • Prerequisite 쿠버네티스가 설치된 클러스터가 있다는 것을 전제로 한다.
  • Operator Lifecycle Manager 필요 이러한 ArgoCD 를 배포하기 위해서 Operator 를 관리하는 Operator 인 OLM 을 설치하겠다. 실제로 이 OLM 을 통해서 다양한 Operator 를 손쉽게 설치 및 운영할 수 있다. 설치 또한 간단한데 아래 링크를 통해서 손쉽게 설치할 수 있다.
curl -L <https://github.com/operator-framework/operator-lifecycle-manager/releases/download/v0.21.2/install.sh> -o install.sh
chmod +x install.sh
./install.sh v0.21.2

참고로 해당 OLM 을 설치 하게 되면 UI 를 통해서 간편하게 Operator 들을 설치할 수 있다.

  • Operator install 그러면 이제 준비는 마무리 되었으니 ArgoCD Operator 를 설치 해보겠다.
kubectl create namespace argocd

git clone <https://github.com/argoproj-labs/argocd-operator>

cd argocd-operator

kubectl create -n olm -f deploy/catalog_source.yaml

kubectl create -n argocd -f deploy/operator_group.yaml

kubectl create -n argocd -f deploy/subscription.yaml

실제 위 과정을 통해서 설치할 경우 저 같은 경우 subscription 을 빼먹고 설치 않았던 경우가 있었는데 이러한 경우에는 namespace 에서 해당 resource 를 확인하지 못해서 실제 배포에 애를 먹은 경우가 있다.

https://github.com/argoproj/argo-cd/issues/5886

하지만 이렇게 OLM 을 통한 설치가 마음에 들지 않는다면 ArgoCD 에서 manual 하게 설치하는 방안에 대해서 아래 링크에서 제공해주고 있으니 참고하면 좋다.

2. basics
이제 설치를 완료 했으니 ArgoCD 를 만들고 앱까지 저장하는 과정을 거쳐보겠다.

  • Create argocd cluster
kubectl create -n argocd -f examples/argocd-basic.yaml
  • argocd-basic.yaml
apiVersion: argoproj.io/v1alpha1
kind: ArgoCD
metadata:
  name: example-argocd
  labels:
    example: basic
spec: {}
  • 확인 명령어
kubectl get cm,secret,deploy -n argocd
  • argocd login 을 위한 비밀번호 및 port forwarding
kubectl -n argocd get secret example-argocd-cluster -o jsonpath='{.data.admin\\.password}' | base64 -d
kubectl -n argocd port-forward service/example-argocd-server 8080:80
  • 브라우저를 통해서 localhost:8080 으로 접속
    • 기본 아이디 admin
    • 비번 위에 설정 된 것으로 접속

3. Argocd Repo 설정

  • argocd credential 생성 argocd 의 경우 명령어를 서버로 보낼때 AWS 같은 cli 와 비슷하게 credential 을 만들어 주어야하는데 아래 login 을 통해 만들어 줄 수 있다.
argocd login --insecure localhost:8080

혹은

ARGOCD_SERVER=${5:-localhost:8080}
ARGOCD_USERNAME=admin
ARGOCD_PASSWORD=$(kubectl get secret -n argocd argocd-initial-admin-secret -o jsonpath={.data.password}  | base64 -d)

argocd --insecure login ${ARGOCD_SERVER} --username ${ARGOCD_USERNAME} --password ${ARGOCD_PASSWORD}

~/.argocd/config 에 credential 생성됨.

  • argocd repo 설정
    • github repo 를 가지고 와야 함.
argocd repo add ${GITHUB_URL} --username ${USERNAME} --password ${PASSWORD}
  • github url, 사용자 이름, 비밀번호를 통해서 Repo로 부터 설정 파일을 가지고 올 수 있다.

4. Argocd App 설정

  • 간단하게 repository 아래에 있는 cert-manager 를 배포 해보겠다.
argocd app create ${SERVICE} \\
        --repo ${GITHUB_URL} \\
        --dest-server ${K8S_SERVER} \\
        --sync-policy automated \\
        --path ${PATH_TO_SERVICE}

ex) cert-manager

  • repo 아래에 services/cert-manager 아래에 kustomization.yaml 형태로 설정 파일이 존재한다는 전제하에 실행이 가능하다.
argocd app create cert-manager \\
        --repo <https://github.com/vtsw/vtflow.git> \\
        --dest-server <https://kubernetes.default.svc> \\
        --sync-policy automated \\
        --path services/cert-manager

위와 같이 Cert-manager 가 정상적으로 ArgoCD 를 통해 운영되는것을 확인할 수 있다. Repo 의 yaml 파일을 변경하여 Sync 를 누르게 되면 해당 변경된 설정으로 다시 rollout 하게 된다.

5. Clean up
아래 명령어를 통해서 위에서 만들었던 ArgoCD 를 다 정리 할 수 있다.

kubectl delete -n argocd -f deploy/subscription.yaml
kubectl delete -n argocd -f deploy/operator_group.yaml
kubectl delete -n olm -f deploy/catalog_source.yaml
kubectl delete namespace argocd


6. Rollout
 Operator Lifecycle Manager 를 통해서 ArgoCD 를 Operator 패턴으로 관리하는 방안에 대해서 알아 보았다. 실제 배포하는데 시간도 많이 걸리지 않고 좋았으나 서비스에 대한 정확한 이해가 수반 되지 않는다면 실제 배포에서 애를 많이 먹었던 기억이 있다. 고로 본인이 원하는 서비스에 대한 이해를 완벽하게 키운 경우에는 더욱 좋은 효율을 보일 수 있다고 생각한다.

반응형