CI/CD 라인 구성 - EKS 웹어플리케이션기반 인프라 구축 - (2)
8. argo cd 구축
kubectl create ns argocd - 네임스페이스 argocd 생성
ebs 볼륨 mount 될 워커노드의 가용영역에 맞게 생성.
- argocd-pv.yaml -> kubectl apply -f argocd-pv.yaml -n argocd
apiVersion: v1
kind: PersistentVolume
metadata:
name: argo-pv
spec:
capacity:
storage: 30Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
storageClassName: ""
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: failure-domain.beta.kubernetes.io/zone
operator: In
values:
- ap-northeast-2b
awsElasticBlockStore:
volumeID: vol-097d5e387f8b3ede1
fsType: ext4
- argocd-pvc.yaml -> kubectl apply -f argocd-pvc.yaml -n argocd
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: argo-pvc
namespace: argocd
spec:
storageClassName: ""
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 30Gi
- argocd-values.yaml
global:
image:
tag: "v2.7.4"
server:
service:
type: LoadBalancer
insecure: true
basehref: /argocd
volumes:
- name: static-files
persistentVolumeClaim:
claimName: argo-pvc
configs:
credentialTemplates:
admin:
apiKey: enabled
- helm internal-lb 형식으로 argo 설치
helm repo add argo https://argoproj.github.io/argo-helm
helm repo update
helm install argocd argo/argo-cd --values argocd-values.yaml --namespace argocd
-argo alb 프록시 서버 ingress 생성
-> kubectl apply -f argocd-ingress.yaml -n argocd
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: argocd-ingress
namespace: argocd
annotations:
kubernetes.io/ingress.class: alb
alb.ingress.kubernetes.io/scheme: internet-facing
alb.ingress.kubernetes.io/listen-ports: '[{"HTTP": 80}, {"HTTPS":443}]'
alb.ingress.kubernetes.io/certificate-arn: arn:aws:acm:ap-northeast-2:553186839963:certificate/2d446ae3-dc43-49fe-9c41-8c39f8609c60
alb.ingress.kubernetes.io/actions.ssl-redirect: '{"Type": "redirect", "RedirectConfig": { "Protocol": "HTTPS", "Port": "443", "StatusCode": "HTTP_301"}}'
spec:
rules:
- host: argo.seunghobet.link
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: ssl-redirect
port:
name: use-annotation
- path: /argocd
pathType: Prefix
backend:
service:
name: argocd-server
port:
name: http
9. argocd 구동을 위한 편집
kubectl edit configmap argocd-cmd-params-cm -n argocd
-> 3 부분 수정
server.basehref: /argocd
server.insecure: "true"
server.rootpath: /argocd
kubectl rollout restart deployments --namespace argocd -> 재시작
kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d -> 비번 접속아이디는 : admin
- 토큰 값 생성을 위한 user 생성
●kubectl edit cm argocd-cm -n argocd
apiVersion: v1
data:
accounts.yourUserName: apiKey -> yourusername을 생성하고자 하는 id 변경
- 새로 생성한 user admin role 부과 : 이래야 젠킨슨에서 파이프라인으로 sync 명령을 내릴 수 있음
● kubectl get configmap argocd-rbac-cm -n argocd -o yaml > argocd-rbac.yml
● vi argocd-rbac.yaml
해당 내용을 추가합니다
data:
policy.csv: |
g, 새로운유저이름, role:admin
policy.default: role:''
변경 사항을 업데이트합니다.
kubectl apply -f argocd-rbac.yml
- argo 의 매니페스트파일이 배포 될 ns에 ecr 도커 이미지를 가져오기 위해 키 값 입력
여기서는 ns 가 kpop
●aws ecr get-authorization-token --region ap-northeast-2 --output text --query 'authorizationData[].authorizationToken'
● kubectl create secret docker-registry ecr-registry-secret --docker-server={my_ecr_url} --docker-username=AWS --docker-password={ecr_token} -n kpop
secret/ecr-registry-secret created
9. 매니페스트 파일 - git 리포지토리에 저장 후 argo 와 연결 (argo 용 새로운 리포지토리 생성) -> 도커 이미지를 alb 로 생성하게 될 yaml ns: kpop
deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: spring-boot-load
namespace: kpop
spec:
replicas: 3
selector:
matchLabels:
app: spring-boot-load
template:
metadata:
labels:
app: spring-boot-load
spec:
containers:
- name: spring-boot-load
image: 553186839963.dkr.ecr.ap-northeast-2.amazonaws.com/drogva:drogva
ports:
- containerPort: 8080
resources:
limits:
cpu: 1
memory: 512Mi
requests:
cpu: 500m
memory: 256Mi
env:
- name: SPRING_PROFILES_ACTIVE
value: "prod"
imagePullSecrets:
- name: ecr-registry-secret
svc.yaml
apiVersion: v1
kind: Service
metadata:
name: spring-boot-service
namespace: kpop
spec:
selector:
app: spring-boot-load
ports:
- port: 8080
targetPort: 8080
ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
namespace: kpop
name: mario-ingress
annotations:
alb.ingress.kubernetes.io/scheme: internet-facing
alb.ingress.kubernetes.io/load-balancer-name: yusa-mario
alb.ingress.kubernetes.io/target-type: ip
alb.ingress.kubernetes.io/listen-ports: '[{"HTTP": 80}, {"HTTPS": 443}]'
external-dns.alpha.kubernetes.io/hostname: www.seunghobet.link
alb.ingress.kubernetes.io/actions.redirect-to-https: '{"Type":"redirect","RedirectConfig":{"Port":"443","Protocol":"HTTPS","StatusCode":"HTTP_302"}}'
alb.ingress.kubernetes.io/certificate-arn: arn:aws:acm:ap-northeast-2:553186839963:certificate/fcb6b1e3-6202-4ac0-a954-1a323e3688b4
spec:
ingressClassName: alb
rules:
- http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: spring-boot-service
port:
number: 8080
10. ARGO 프로젝트 생성
- git 리포지토리와 연결 -매니페스트파일 저장된 곳
via https 선택 -> git 저장소 url -> git 아이디 -> git에서 발급받은 토큰 -> connect test
- 프로젝트 생성
매니패스트파일이 저장된 git hub 저장소 추가
목적지 eks 내부 편집 후 저장
11. 어플리케이션 생성 -> 젠킨슨 파이프라인에서 명령을 내릴 이름이므로 kpop 으로 통일
11. 젠킨슨에서 argo 에게 sync 명령을 내리는 파이프 라인 생성 (DEPLOY 파이프라인)
credentials -> secret text -> user argo 에 생성한 token -> secret 입력 -> user 는 argocd-auth-token
파이프라인 : git hub action 레포지토리 주소 및 hook 이 실행 되기 위한 jenkins token 입력은 동일
pipeline {
options {
timeout(time: 1, unit: 'HOURS')
}
agent any
environment {
ARGOCD_SERVER = 'argo.seunghobet.link/argocd'
APP_NAME = 'kpop'
}
stages {
stage('Sync ArgoCD Application') {
steps {
script {
withCredentials([string(credentialsId: 'argocd-auth-token', variable: 'ARGOCD_AUTH_TOKEN')]) {
echo "Syncing ArgoCD application..."
sh '''
curl -s -k -H 'Content-Type: application/json' -H "Authorization: Bearer ${ARGOCD_AUTH_TOKEN}" -X POST \
--data '{}' \
https://${ARGOCD_SERVER}/api/v1/applications/${APP_NAME}/sync
'''
}
}
}
}
}
}