GitOps ์‹œ์Šคํ…œ

Sparkยท2023๋…„ 3์›” 25์ผ
0

PKOS

๋ชฉ๋ก ๋ณด๊ธฐ
3/6

๐Ÿ“Œ ๋ชฉํ‘œ

์ด๋ฒˆ์ฃผ๋Š” CI/CD ๋ฅผ ๋ชฉํ‘œ๋กœ ํ•˜๋ฉฐ gitlab, argoCD, harbor ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ
k8s ํ™˜๊ฒฝ์—์„œ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๋ฐฐํฌํ•˜๋Š” ํ…Œ์ŠคํŠธ๊นŒ์ง€ ํ•ด๋ณด๊ธฐ๋กœ ํ•˜์ž.


(์ฐธ๊ณ : https://picluster.ricsanfre.com/docs/argocd/)

์ฐธ๊ณ  ๊ทธ๋ฆผ์ด๋ฉฐ, image registry ๋กœ๋Š” harbor๋ฅผ ์ง์ ‘ ๊ตฌ์ถ•ํ•ด์„œ ์‚ฌ์šฉํ•ด๋ณด๋„๋ก ํ•˜์ž.

์‹ค์Šตํ™˜๊ฒฝ

๋น„๊ต : t3a.xlarge 4/16 $0.1872 , t3a.2xlarge 8/32 $0.3744 , *c5a.2xlarge 8/16 $0.344 , c5.2xlarge $0.384

# YAML ํŒŒ์ผ ๋‹ค์šด๋กœ๋“œ
curl -O https://s3.ap-northeast-2.amazonaws.com/cloudformation.cloudneta.net/K8S/kops-oneclick-f1.yaml

# CloudFormation ์Šคํƒ ๋ฐฐํฌ : ๋…ธ๋“œ ์ธ์Šคํ„ด์Šค ํƒ€์ž… ๋ณ€๊ฒฝ - MasterNodeInstanceType=t3.medium WorkerNodeInstanceType=c5d.large
aws cloudformation deploy --template-file kops-oneclick-f1.yaml --stack-name mykops --parameter-overrides KeyName=kp-gasida SgIngressSshCidr=$(curl -s ipinfo.io/ip)/32  MyIamUserAccessKeyID=AKIA5... MyIamUserSecretAccessKey='CVNa2...' ClusterBaseName='gasida.link' S3StateStore='gasida-k8s-s3' MasterNodeInstanceType=c5a.2xlarge WorkerNodeInstanceType=c5a.2xlarge --region ap-northeast-2

# CloudFormation ์Šคํƒ ๋ฐฐํฌ ์™„๋ฃŒ ํ›„ kOps EC2 IP ์ถœ๋ ฅ
aws cloudformation describe-stacks --stack-name mykops --query 'Stacks[*].Outputs[0].OutputValue' --output text

# 13๋ถ„ ํ›„ ์ž‘์—… SSH ์ ‘์†
ssh -i ~/.ssh/kp-gasida.pem ec2-user@$(aws cloudformation describe-stacks --stack-name mykops --query 'Stacks[*].Outputs[0].OutputValue' --output text)

# EC2 instance profiles ์— IAM Policy ์ถ”๊ฐ€(attach) : ์ฒ˜์Œ ์ž…๋ ฅ ์‹œ ์ ์šฉ์ด ์ž˜ ์•ˆ๋  ๊ฒฝ์šฐ ๋‹ค์‹œ ํ•œ๋ฒˆ ๋” ์ž…๋ ฅ ํ•˜์ž! - IAM Role์—์„œ ์ƒˆ๋กœ๊ณ ์นจ ๋จผ์ € ํ™•์ธ!
aws iam attach-role-policy --policy-arn arn:aws:iam::$ACCOUNT_ID:policy/AWSLoadBalancerControllerIAMPolicy --role-name masters.$KOPS_CLUSTER_NAME
aws iam attach-role-policy --policy-arn arn:aws:iam::$ACCOUNT_ID:policy/AWSLoadBalancerControllerIAMPolicy --role-name nodes.$KOPS_CLUSTER_NAME

# ๋ฉ”ํŠธ๋ฆญ ์„œ๋ฒ„ ํ™•์ธ : ๋ฉ”ํŠธ๋ฆญ์€ 15์ดˆ ๊ฐ„๊ฒฉ์œผ๋กœ cAdvisor๋ฅผ ํ†ตํ•˜์—ฌ ๊ฐ€์ ธ์˜ด
kubectl top node

Harbor ๊ตฌ์„ฑ

harbor๋ฅผ ์ด์šฉํ•˜์—ฌ ์ปจํ…Œ์ด๋„ˆ ์ด๋ฏธ์ง€ ์ €์žฅ์†Œ ๊ตฌ์ถ•

# ์‚ฌ์šฉ ๋ฆฌ์ „์˜ ์ธ์ฆ์„œ ARN ํ™•์ธ
aws acm list-certificates --query 'CertificateSummaryList[].CertificateArn[]' --output text
CERT_ARN=`aws acm list-certificates --query 'CertificateSummaryList[].CertificateArn[]' --output text`
echo "alb.ingress.kubernetes.io/certificate-arn: $CERT_ARN"

# ํ•˜๋ฒ„ ์„ค์น˜
helm repo add harbor https://helm.goharbor.io
helm fetch harbor/harbor --untar --version 1.11.0
vim ~/harbor/values.yaml
----------------------
expose.tls.certSource=none                        # 19์ค„
expose.ingress.hosts.core=harbor.sparkandassociates.net    # 36์ค„
expose.ingress.hosts.notary=notary.sparkandassociates.net # 37์ค„

expose.ingress.controller=alb                      # 44์ค„
expose.ingress.className=alb                       # 47์ค„~
expose.ingress.annotations=alb.ingress.kubernetes.io/scheme: internet-facing
expose.ingress.annotations=alb.ingress.kubernetes.io/target-type: ip
expose.ingress.annotations=alb.ingress.kubernetes.io/listen-ports: '[{"HTTPS":443}, {"HTTP":80}]'
expose.ingress.annotations=alb.ingress.kubernetes.io/certificate-arn: ${CERT_ARN}   # ๊ฐ์ž ์ž์‹ ์˜ ๊ฐ’์œผ๋กœ ์ˆ˜์ •์ž…๋ ฅ
alb.ingress.kubernetes.io/scheme: internet-facing
alb.ingress.kubernetes.io/target-type: ip
alb.ingress.kubernetes.io/listen-ports: '[{"HTTPS":443}, {"HTTP":80}]'
alb.ingress.kubernetes.io/certificate-arn: ${CERT_ARN}   # ๊ฐ์ž ์ž์‹ ์˜ ๊ฐ’์œผ๋กœ ์ˆ˜์ •์ž…๋ ฅ
externalURL=https://harbor.sparkandassociates.net          # 131์ค„
         
----------------------

# ๋ชจ๋‹ˆํ„ฐ๋ง
kubectl create ns harbor
watch kubectl get pod,pvc,ingress -n harbor

# ์„ค์น˜
helm install harbor harbor/harbor -f ~/harbor/values.yaml --namespace harbor --version 1.11.0

# ํ™•์ธ
# registry : ์ปจํ…Œ์ด๋„ˆ ์ด๋ฏธ์ง€๋ฅผ ์ €์žฅ
# chartmuseum : ํ•˜๋ฒ„๋ฅผ ์ปจํ…Œ์ด๋„ˆ ์ด๋ฏธ์ง€๋ฟ ์•„๋‹ˆ๋ผ, ํ—ฌ๋ฆ„ ์ฐจํŠธ ๋ฆฌํฌ์ง€ํ† ๋ฆฌ๋กœ๋„ ์‚ฌ์šฉ
# notary : ์„œ๋ช…์ด ์™„๋ฃŒ๋œ ์ปจํ…Œ์ด๋„ˆ ์ด๋ฏธ์ง€๋งŒ ์šด์˜ ํ™˜๊ฒฝ์— ์‚ฌ์šฉํ•˜๋„๋ก ์„ค์ •. ์„œ๋ช…์ด ์™„๋ฃŒ๋œ ์ด๋ฏธ์ง€๋Š” ๋ณ„๋„๋กœ ๊ตฌ๋ถ„
# trivy : ์ปจํ…Œ์ด๋„ˆ ์ด๋ฏธ์ง€์˜ ๋ณด์•ˆ ์ทจ์•ฝ์ ์„ ์Šค์บ”, ์Šค์บ” ๊ธฐ๋Šฅ์€ ๋ณ„๋„ ์†”๋ฃจ์…˜์—์„œ ์ œ๊ณตํ•˜์—ฌ ๊ด€๋ฆฌ์ž๋Š” ๋ณด์•ˆ ์Šค์บ”์šฉ ๋„๊ตฌ๋ฅผ ์„ ํƒ ๊ฐ€๋Šฅ
helm list -n harbor
kubectl get-all -n harbor
kubectl get pod,pvc,ingress,deploy,sts -n harbor
kubectl get ingress -n harbor harbor-ingress -o json | jq
kubectl krew install df-pv && kubectl df-pv

# ์›น ์ ‘์† ์ฃผ์†Œ ํ™•์ธ ๋ฐ ์ ‘์†
echo -e "harbor URL = https://harbor.$KOPS_CLUSTER_NAME"
echo -e "notary URL = https://notary.$KOPS_CLUSTER_NAME"

์ ‘์† ํ™•์ธ

pkos project ์ƒ์„ฑ.

# ์ปจํ…Œ์ด๋„ˆ ์ด๋ฏธ์ง€ ๊ฐ€์ ธ์˜ค๊ธฐ
docker pull nginx && docker pull busybox && docker images

# ํƒœ๊ทธ ์„ค์ •
docker tag busybox harbor.$KOPS_CLUSTER_NAME/pkos/busybox:0.1
docker image ls

# ๋กœ๊ทธ์ธ - ๋ฐฉ์•ˆ2
echo 'Harbor12345' > harborpw.txt
cat harborpw.txt | docker login harbor.$KOPS_CLUSTER_NAME -u admin --password-stdin
cat /root/.docker/config.json | jq

# ์ด๋ฏธ์ง€ ์—…๋กœ๋“œ
docker push harbor.$KOPS_CLUSTER_NAME/pkos/busybox:0.1

๋กœ์ปฌ ์ €์žฅ์†Œ ์ด๋ฏธ์ง€ ์ ์šฉ.

# ํŒŒ๋“œ ๋ฐฐํฌ
curl -s -O https://raw.githubusercontent.com/junghoon2/kube-books/main/ch13/busybox-deploy.yml
sed -i "s|harbor.myweb.io/erp|harbor.$KOPS_CLUSTER_NAME/pkos|g" busybox-deploy.yml
kubectl apply -f busybox-deploy.yml

trivy ์ด์šฉํ•ด์„œ ์ด๋ฏธ์ง€ ์Šค์บ” ๊ธฐ๋Šฅ๋„ ์ œ๊ณตํ•œ๋‹ค.

harbor-trivy ํŒŒ๋“œ์— ์ง์ ‘ ์ ‘์†ํ•ด์„œ trivy client ๋ฅผ ์‚ฌ์šฉ๊ฐ€๋Šฅํ•˜๋‹ค.

์ด๋ฏธ์ง€ ๋ณด์•ˆ์ ๊ฒ€์„ ์ž๋™์œผ๋กœ ํ•  ์ˆ˜ ์žˆ์Œ.

GitLab ๊ตฌ์„ฑ

helm ์ฐจํŠธ๋กœ gitlab์„ ์„ค์น˜ํ•ด๋ณด์ž.

# ๋ชจ๋‹ˆํ„ฐ๋ง
kubectl create ns gitlab
watch kubectl get pod,pvc,ingress -n gitlab

# ์„ค์น˜
echo $CERT_ARN
helm repo add gitlab https://charts.gitlab.io/
helm repo update
helm fetch gitlab/gitlab --untar --version 6.8.1
vim ~/gitlab/values.yaml
----------------------
global:
  hosts:
    domain: sparkandassociates.net          # 52์ค„
    https: true

  ingress:                             # 66์ค„~
    configureCertmanager: false
    provider: aws
    class: alb
    annotations:
      alb.ingress.kubernetes.io/scheme: internet-facing
      alb.ingress.kubernetes.io/target-type: ip
      alb.ingress.kubernetes.io/listen-ports: '[{"HTTPS":443}, {"HTTP":80}]'
      alb.ingress.kubernetes.io/certificate-arn: ${CERT_ARN}   # ๊ฐ์ž ์ž์‹ ์˜ ๊ฐ’์œผ๋กœ ์ˆ˜์ •์ž…๋ ฅ
      alb.ingress.kubernetes.io/success-codes: 200-399
      alb.ingress.kubernetes.io/group.name: "gitlab"
    tls:                               # 79์ค„
      enabled: false
----------------------
helm install gitlab gitlab/gitlab -f ~/gitlab/values.yaml --set certmanager.install=false --set nginx-ingress.enabled=false --set prometheus.install=false --set gitlab-runner.install=false --namespace gitlab --version 6.8.4

# ํ™•์ธ - SubCharts
# gitlab-gitaly : ์›น์„œ๋น„์Šค ํ˜น์€ ssh ๋ฐฉ์‹์œผ๋กœ ์ง„ํ–‰๋˜๋Š” ๊นƒ ์ œ๋ชฉ, ๋ธŒ๋žœ์น˜, ํƒœ๊ทธ ๋“ฑ์˜ ๊นƒ ์š”์ฒญ ๋“ฑ์— ๋Œ€ํ•œ ์ž‘์—…์„ ๋‹ด๋‹น
# gitlab-gitlab-shell : https ๊ฐ€ ์•„๋‹Œ ssh ๋ฐฉ์‹์œผ๋กœ ๊นƒ ๋ช…๋ น์–ด ์‹คํ–‰ ์‹œ ํ•ด๋‹น ์š”์ฒญ์„ ์ฒ˜๋ฆฌ
# gitlab-kas : gitlab agent server
# gitlab-postgresql : ์œ ์ €, ๊ถŒํ•œ, ์ด์Šˆ ๋“ฑ ๊นƒ๋žฉ์˜ ๋ฉ”ํƒ€ ๋ฐ์ดํ„ฐ ์ •๋ณด๊ฐ€ ์ €์žฅ
# gitlab-redis-master : ๊นƒ๋žฉ ์ž‘์—… ์ •๋ณด๋Š” ๋ ˆ๋””์Šค ์บ์‹œ ์„œ๋ฒ„๋ฅผ ์ด์šฉํ•˜์—ฌ ์ฒ˜๋ฆฌ
# gitlab-sidekiq-all-in-1-v2 : ๋ ˆ๋””์Šค์™€ ์—ฐ๋™ํ•˜์—ฌ ์ž‘์—… ํ ์ฒ˜๋ฆฌ ์šฉ๋„๋กœ ์‚ฌ์šฉ
# gitlab-webservice-default : ๊นƒ๋žฉ ์›น ์„œ๋น„์Šค๋ฅผ ์ฒ˜๋ฆฌ
helm list -n gitlab
kubectl get pod,pvc,ingress,deploy,sts -n gitlab
kubectl df-pv -n gitlab
kubectl get-all -n gitlab

# 4๊ฐœ์˜ Ingress ๊ฐ€ 1๊ฐœ์˜ ALB๋ฅผ ๊ณต์œ ํ•ด์„œ ์‚ฌ์šฉ : ALB์˜ Rule ํ™•์ธํ•ด๋ณผ๊ฒƒ!
# alb.ingress.kubernetes.io/group.name: "gitlab"
kubectl get ingress -n gitlab
NAME                        CLASS   HOSTS                  ADDRESS                                                             PORTS   AGE
gitlab-kas                  alb     kas.gasida.link        k8s-gitlab-3fbf5c8cab-1066962252.ap-northeast-2.elb.amazonaws.com   80      93s
gitlab-minio                alb     minio.gasida.link      k8s-gitlab-3fbf5c8cab-1066962252.ap-northeast-2.elb.amazonaws.com   80      93s
gitlab-registry             alb     registry.gasida.link   k8s-gitlab-3fbf5c8cab-1066962252.ap-northeast-2.elb.amazonaws.com   80      93s
gitlab-webservice-default   alb     gitlab.gasida.link     k8s-gitlab-3fbf5c8cab-1066962252.ap-northeast-2.elb.amazonaws.com   80      93s

# ์›น root ๊ณ„์ • ์•”ํ˜ธ ํ™•์ธ
(sparkandassociates:harbor) [root@kops-ec2 ~]# kubectl get secrets -n gitlab gitlab-gitlab-initial-root-password --template={{.data.password}} | base64 -d ;echo
TSbqXj0ymmUzxBDTOG3WlX6HtmBQZcvmOGz10bIIGudyvmrCNYMkk4Yexh09TAek
(sparkandassociates:harbor) [root@kops-ec2 ~]#

# ์›น ์ ‘์† ์ฃผ์†Œ ํ™•์ธ ๋ฐ ์ ‘์†
echo -e "gitlab URL = https://gitlab.$KOPS_CLUSTER_NAME"

# ์›น ์ ‘์† https://gitlab.<๊ฐ์ž ์ž์‹ ์˜ ๋„๋ฉ”์ธ> (root / ์›น root ๊ณ„์ • ์•”ํ˜ธ)
  • ์ ‘์† ํ›„ ๋ณ„๋„์˜ ์‚ฌ์šฉ์ž ์ƒ์„ฑ : Admins โ†’ Users : ๊ฐ์ž ์ž์‹ ๋งŒ์˜ ํŽธํ•œ ๊ณ„์ • โ‡’ ํ•ด๋‹น ๊ณ„์ •์œผ๋กœ git ๋ช…๋ น์–ด ์‹คํ–‰

    • Impersonation Tokens : Name(test), Scopes(๋ชจ๋‘ Check) โ†’ Create impersonation token ํด๋ฆญ โ‡’ ํ† ํฐ ๊ฐ’ ํ™•์ธ glpat-cGRP-N....Zit
  • Users : ์œ ์ € ์„ ํƒ ํ›„ ์•”ํ˜ธ ์ž…๋ ฅ(Test1234), admin ๊ถŒํ•œ ์ฒดํฌ โ‡’ root ๊ณ„์ • ๋กœ๊ทธ์•„์›ƒ โ‡’ spark ๊ณ„์ • ๋กœ๊ทธ์ธ โ‡’ ์•”ํ˜ธ ๋ณ€๊ฒฝ(P@ssw0rd)

  • ๊นƒ๋žฉ ์‹ ๊ทœ ํ”„๋กœ์ ํŠธ ์ž‘์„ฑ : Project name (test-stg) , Project URL(<๊ฐ์ž๊ณ„์ •>, /test-stg) , Visibility Level (Intenal) , Initialize repository with a README (์ฒดํฌ)

์ƒ์„ฑํ•œ git project์— k8s yaml ์„ ์—…๋กœ๋“œ ํ•ด๋ณด์ž.

#
mkdir ~/gitlab-test && cd ~/gitlab-test

# git ๊ณ„์ • ์ดˆ๊ธฐํ™” : ํ† ํฐ ๋ฐ ๋กœ๊ทธ์ธ ์‹คํŒจ ์‹œ ๋งค๋ฒˆ ์‹คํ–‰ํ•ด์ฃผ์ž
git config --system --unset credential.helper
git config --global --unset credential.helper

# git ๊ณ„์ • ์ •๋ณด ํ™•์ธ ๋ฐ global ๊ณ„์ • ์ •๋ณด ์ž…๋ ฅ
git config --list
git config --global user.name spark
git config --global user.email spark@sparkandassociates.net


# git clone
git clone https://gitlab.$KOPS_CLUSTER_NAME/spark/test-stg.git
git clone https://gitlab.$KOPS_CLUSTER_NAME/spark/test-stg.git
Cloning into 'test-stg'...

# ํŒŒ์ผ ์ƒ์„ฑ ๋ฐ ๊นƒ ์—…๋กœ๋“œ(push) : ์›น์—์„œ ํ™•์ธ
echo "gitlab test memo" >> test.txt
git add . && git commit -m "initial commit - add test.txt"
git push

์ •์ƒ ํ™•์ธ๋จ.

ArgoCD ํ™œ์šฉํ•œ Gitops ์‹œ์Šคํ…œ ๊ตฌ์ถ•!

์ž, ์ด์ œ ๋Œ€๋ง์˜ ArgoCD๋ฅผ ์ด์šฉํ•ด์„œ gitops๋ผ๋Š”๊ฑธ ํ•ด๋ณด๋„๋ก ํ•˜์ž.
๋จผ์ € argoCD๋Š” ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค CRD ๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ๋™์ž‘ํ•œ๋‹ค๊ณ  ํ•œ๋‹ค.
์ฆ‰ k8s ํ™˜๊ฒฝ์—์„œ๋งŒ ์‚ฌ์šฉ๊ฐ€๋Šฅํ•˜๋‹ค๋Š” ๊ฒƒ.

# ๋ชจ๋‹ˆํ„ฐ๋ง
kubectl create ns argocd
watch kubectl get pod,pvc,svc -n argocd

# ์„ค์น˜
cd
helm repo add argo https://argoproj.github.io/argo-helm
helm repo update

helm install argocd argo/argo-cd --set server.service.type=LoadBalancer --namespace argocd --version 5.19.14

# ํ™•์ธ
# argocd-application-controller : ์‹คํ–‰ ์ค‘์ธ k8s ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ์„ค์ •๊ณผ ๊นƒ ์ €์žฅ์†Œ์˜ ์†Œ์Šค ํŒŒ์ผ์— ์„ ์–ธ๋œ ์ƒํƒœ๋ฅผ ์„œ๋กœ ๋น„๊ตํ•˜๋Š” ์ปจํŠธ๋กค๋Ÿฌ. ์ƒํƒœ์™€ ๋‹ค๋ฅด๋ฉด โ€˜OutOfSyncโ€™ ์—๋Ÿฌ๋ฅผ ์ถœ๋ ฅ.
# argocd-dex-server : ์™ธ๋ถ€ ์‚ฌ์šฉ์ž์˜ LDAP ์ธ์ฆ์— Dex ์„œ๋ฒ„๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Œ
# argocd-repo-server : ์›๊ฒฉ ๊นƒ ์ €์žฅ์†Œ์˜ ์†Œ์Šค ์ฝ”๋“œ๋ฅผ ์•„๋ฅด๊ณ ์‹œ๋”” ๋‚ด๋ถ€ ์บ์‹œ ์„œ๋ฒ„์— ์ €์žฅํ•ฉ๋‹ˆ๋‹ค. ๋””๋ ‰ํ† ๋ฆฌ ๊ฒฝ๋กœ, ์†Œ์Šค, ํ—ฌ๋ฆ„ ์ฐจํŠธ ๋“ฑ์ด ์ €์žฅ.
helm list -n argocd
kubectl get pod,pvc,svc,deploy,sts -n argocd
kubectl get-all -n argocd

kubectl get crd | grep argoproj
applications.argoproj.io              2023-03-19T11:39:26Z
applicationsets.argoproj.io           2023-03-19T11:39:26Z
appprojects.argoproj.io               2023-03-19T11:39:26Z

# CLB์— ExternanDNS ๋กœ ๋„๋ฉ”์ธ ์—ฐ๊ฒฐ
kubectl annotate service -n argocd argocd-server "external-dns.alpha.kubernetes.io/hostname=argocd.$KOPS_CLUSTER_NAME"

# admin ๊ณ„์ •์˜ ์•”ํ˜ธ ํ™•์ธ
ARGOPW=$(kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d)
echo $ARGOPW
mf8bOtNEq7iHMqq1

# ์›น ์ ‘์† ๋กœ๊ทธ์ธ (admin) CLB์˜ DNS ์ฃผ์†Œ๋กœ ์ ‘์†
echo -e "Argocd Web URL = https://argocd.$KOPS_CLUSTER_NAME"

ArgoCD CLI ์„ค์น˜

# ์ตœ์‹ ๋ฒ„์ „ ์„ค์น˜
curl -sSL -o argocd-linux-amd64 https://github.com/argoproj/argo-cd/releases/latest/download/argocd-linux-amd64
install -m 555 argocd-linux-amd64 /usr/local/bin/argocd
chmod +x /usr/local/bin/argocd

# ๋ฒ„์ „ ํ™•์ธ
argocd version --short

# Help
# argocd app : ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋™๊ธฐํ™” ์ƒํƒœ ํ™•์ธ
# argocd context : ๋ณต์ˆ˜์˜ ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ํด๋Ÿฌ์Šคํ„ฐ ๋“ฑ๋ก ๋ฐ ์„ ํƒ
# argocd login : ์•„๋ฅด๊ณ ์‹œ๋”” ์„œ๋ฒ„์— ๋กœ๊ทธ์ธ 
# argocd repo : ์›๊ฒฉ ๊นƒ ์ €์žฅ์†Œ๋ฅผ ๋“ฑ๋กํ•˜๊ณ  ํ˜„ํ™ฉ ํŒŒ์•…
argocd

# argocd ์„œ๋ฒ„ ๋กœ๊ทธ์ธ
argocd login argocd.$KOPS_CLUSTER_NAME --username admin --password $ARGOPW

# ๊ธฐ ์„ค์น˜ํ•œ ๊นƒ๋žฉ์˜ ํ”„๋กœ์ ํŠธ URL ์„ argocd ๊นƒ ๋ฆฌํฌ์ง€ํ† ๋ฆฌ(argocd repo)๋กœ ๋“ฑ๋ก. ๊นƒ๋žฉ์€ ํ”„๋กœ์ ํŠธ ๋‹จ์œ„๋กœ ์†Œ์Šค ์ฝ”๋“œ๋ฅผ ๋ณด๊ด€.
argocd repo add https://gitlab.$KOPS_CLUSTER_NAME/spark/test-stg.git --username spark --password <๊นƒ๋žฉ ๊ณ„์ • ์•”ํ˜ธ>
 
# ๋“ฑ๋ก ํ™•์ธ : ๊ธฐ๋ณธ์ ์œผ๋กœ ์•„๋ฅด๊ณ ์‹œ๋””๊ฐ€ ์„ค์น˜๋œ ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ํด๋Ÿฌ์Šคํ„ฐ๋Š” ํƒ€๊นƒ ํด๋Ÿฌ์Šคํ„ฐ๋กœ ๋“ฑ๋ก๋จ
(sparkandassociates:harbor) [root@kops-ec2 ~]# argocd repo list
TYPE  NAME  REPO                                                      INSECURE  OCI    LFS    CREDS  STATUS      MESSAGE  PROJECT
git         https://gitlab.sparkandassociates.net/spark/test-stg.git  false     false  false  true   Successful

# argocd ๊ฐ€ ์—ฐ๋™๋œ ํด๋Ÿฌ์Šคํ„ฐ๋ฆฌ์ŠคํŠธ๋ฅผ ๋ณผ ์ˆ˜ ์žˆ์œผ๋ฉฐ, ํ˜„์žฌ๋Š” argocd ๊ฐ€ ์„ค์น˜๋œ ํด๋Ÿฌ์Šคํ„ฐ๋งŒ ๋ณด์ธ๋‹ค.
argocd cluster list
SERVER                          NAME        VERSION  STATUS   MESSAGE                                                  PROJECT
https://kubernetes.default.svc  in-cluster           Unknown  Cluster has no applications and is not being monitored.

ArgoCD๋ฅผ ์ด์šฉํ•ด์„œ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋ฐฐํฌํ•˜๊ธฐ

์ž ์ด์ œ argoCD cli๋กœ rabbitmq helm ์„ ๋ฐฐํฌํ•ด๋ณด์ž.

# test-stg ๊นƒ ๋””๋ ‰ํ„ฐ๋ฆฌ์—์„œ ์•„๋ž˜ ์‹คํ–‰
cd ~/gitlab-test/test-stg

# ๊นƒ ์›๊ฒฉ ์˜ค๋ฆฌ์ง„ ์ฃผ์†Œ ํ™•์ธ
git config -l | grep remote.origin.url

(sparkandassociates:harbor) [root@kops-ec2 test-stg]# git config -l | grep remote.origin.url
remote.origin.url=https://gitlab.sparkandassociates.net/spark/test-stg.git

# RabbitMQ ํ—ฌ๋ฆ„ ์ฐจํŠธ ์„ค์น˜
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update
helm fetch bitnami/rabbitmq --untar --version 11.10.3
cd rabbitmq/
cp values.yaml my-values.yaml

# ํ—ฌ๋ฆ„ ์ฐจํŠธ๋ฅผ ๊นƒ๋žฉ ์ €์žฅ์†Œ์— ์—…๋กœ๋“œ
git add . && git commit -m "add rabbitmq helm"
git push

# argocd CRD ํ™•์ธ
kubectl get crd | grep argo
applications.argoproj.io                              2022-01-25T15:46:16Z   # ๋ฐฐํฌ ์•ฑ ํ˜„์žฌ ์‹คํ–‰ ์ƒํƒœ์™€ ๊นƒ ์ €์žฅ์†Œ์˜ ์˜๋„ํ•œ ์ƒํƒœ๋ฅผ ๊ณ„์† ๋น„๊ต
appprojects.argoproj.io                               2022-01-25T15:46:16Z   # ํ”„๋กœ์ ํŠธ ๋‹จ์œ„ ๊ตฌ๋ถ„
argocdextensions.argoproj.io                          2022-01-25T15:46:16Z

# ์ˆ˜์ •
curl -s -O https://raw.githubusercontent.com/wikibook/kubepractice/main/ch15/rabbitmq-helm-argo-application.yml
vim rabbitmq-helm-argo-application.yml
--------------------------------------
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: rabbitmq-helm
  namespace: argocd
  finalizers:
  - resources-finalizer.argocd.argoproj.io
spec:
  destination:
    namespace: rabbitmq
    server: https://kubernetes.default.svc
  project: default
  source:
    repoURL: https://gitlab.sparkandassociates.net/spark/test-stg.git
    path: rabbitmq
    targetRevision: HEAD
    helm:
      valueFiles:
      - my-values.yaml
  syncPolicy:
    syncOptions:
    - CreateNamespace=true
--------------------------------------

# ๋ชจ๋‹ˆํ„ฐ๋ง : argocd ์›น ํ™”๋ฉด ๋ณด๊ณ  ์žˆ๊ธฐ!
echo -e "Argocd Web URL = https://argocd.$KOPS_CLUSTER_NAME"

# ๋ฐฐํฌ
kubectl apply -f rabbitmq-helm-argo-application.yml

# YAML ํŒŒ์ผ์„ ์ ์šฉ(apply)ํ•˜์—ฌ ์•„๋ฅด๊ณ ์‹œ๋”” โ€˜Applicationโ€™ CRD๋ฅผ ์ƒ์„ฑ
kubectl get applications.argoproj.io -n argocd
NAME            SYNC STATUS   HEALTH STATUS
rabbitmq-helm   OutOfSync     Missing

"SYNC"๋ฅผ ํด๋ฆญํ•ด์„œ ์„ค์น˜.

ํŒŒ๋“œ ์ฆ๊ฐ€

# sts ํŒŒ๋“œ 1๊ฐœ์—์„œ 2๊ฐœ๋กœ ์ฆ๊ฐ€ ์„ค์ • ํ›„ argocd ์›น ํ™”๋ฉด ๋ชจ๋‹ˆํ„ฐ๋ง
kubectl scale statefulset -n rabbitmq rabbitmq-helm --replicas 2

argoCD ์›น์ƒ์—์„œ rabbitmq-helm statefulset์„ ์ง์ ‘ ์ˆ˜์ •ํ•ด๋„ ๋œ๋‹ค.

edit -> "save" ํ•˜๋ฉด ๋ฐ”๋กœ replica 2๋กœ ์ ์šฉ๋˜๋ฉฐ pod์ด ํ•˜๋‚˜๋” ์ƒ์„ฑ๋œ๋‹ค.

profile
Hello world

0๊ฐœ์˜ ๋Œ“๊ธ€