반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- Kubeflow
- serving
- Pulumi
- Litmus
- keda
- opentelemetry
- Kubernetes 인증
- opensearch
- seldon core
- CANARY
- knative
- argo rollout
- CI/CD
- Kopf
- argocd
- mlops
- gitea
- MLflow
- tekton
- Continuous Deployment
- 카오스 엔지니어링
- Kubernetes
- Argo
- kubernetes operator
- nginx ingress
- Model Serving
- 오퍼레이터
- gitops
- blue/green
- operator
Archives
- Today
- Total
Kubernetes 이야기
tekton과 argocd를 이용한 GitOps 구축하기 본문
반응형
tekton과 argocd를 사용하여 GitOps 구축을 해보자.
전체적인 구성은 다음과 같다.
전체적인 과정을 보면
1) Tekton을 이용하여 소스를 빌드 후 Registry에 저장한다.
2) Manifest를 저장하는 Git 저장소에 빌드된 이미지 tag를 업데이트한다.
3) ArgoCD에서 Manifest 저장소의 갱신여부를 확인하여 Kubernetes에 apply한다.
각 과정별 진행과정을 살펴보자.
1) Tekton 및 Kaniko
먼저 Tekton 실행에 필요한 script들을 알아보자.
소스 Clone
kubectl apply -f https://raw.githubusercontent.com/tektoncd/catalog/main/task/git-clone/0.9/git-clone.yaml
build-kaniko-git
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: build-kaniko-git
namespace: test
spec:
params:
- name: app_repo
type: string
- name: container_image
type: string
- name: container_tag
type: string
steps:
- args:
- --context=./
- --destination=$(params.container_image):$(params.container_tag)
- --force
- --skip-tls-verify
command:
- /kaniko/executor
image: gcr.io/kaniko-project/executor:debug
name: build
resources: {}
volumeMounts:
- mountPath: /kaniko/.docker/
name: kaniko-secret
workingDir: /workspace/output/
volumes:
- name: kaniko-secret
secret:
items:
- key: .dockerconfigjson
path: config.json
secretName: github-regcred
workspaces:
- name: output
optional: true
Secret
kubectl create secret docker-registry github-regcred --docker-username=user --docker-password=password --docker-email=email [--docker-server=string]
Pipeline
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: pipeline
spec:
params:
- name: giturl
description: |
THIS PARAMETER COMING FROM TRIGGER TEMPLATE
workspaces:
- name: shared-data
description: |
This workspace will receive the cloned git repo and be passed
to the next Task for the repo's README.md file to be read.
tasks:
- name: fetch-repo
taskRef:
name: git-clone
params:
- name: url
value: $(params.giturl)
workspaces:
- name: output
workspace: shared-data
- name: build-container-image
runAfter: ["fetch-repo"]
taskRef:
name: build-kaniko-git
params:
- name: app_repo
value: dir:///workspace/output/
- name: container_image
value: ghcr.io/kmaster8/myimage
- name: container_tag
value: $(tasks.fetch-repo.results.commit)
workspaces:
- name: output
workspace: shared-data
Pipeline Run
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
generateName: pipelinerun-
spec:
serviceAccountName: tekton-sa
pipelineRef:
name: pipeline
params:
- name: giturl
value: https://github.com/kmaster8/flask-helloworld.git
workspaces:
- name: shared-data
volumeClaimTemplate:
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
파이프라인을 실행하면 아래와 같이 Image가 Push 되는것을 확인할 수 있다.
Manifest 수정
Image Push까지 완료되는 CI ( continuous integration ) 과정은 끝났다. 이제 Kubernetes 배포용 Menifest를 생성(수정) 하여 ArgoCD를 이용하여 배포하는 CD ( continuous development ) 과정을 알아보자.
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: manifest-deploy
spec:
params:
- name: repositoryurl
description: ""
type: string
default: github.com/kmaster8/sample-manifest-repo.git
- name: imageurl
description: Image url
type: string
- name: imagetag
description: Image tag
type: string
steps:
- name: auto-deploy-to-devl
image: docker.io/alpine/git:v2.26.2@sha256:23618034b0be9205d9cc0846eb711b12ba4c9b468efdd8a59aac1d7b1a23363f #tag: v2.26.2
env:
- name: GIT_USERNAME
valueFrom:
secretKeyRef:
name: github-credentials
key: username
- name: GIT_PASSWORD
valueFrom:
secretKeyRef:
name: github-credentials
key: password
script: |
#!/usr/bin/env sh
wget https://github.com/mikefarah/yq/releases/download/v4.2.0/yq_linux_amd64.tar.gz -O - | tar xz && mv yq_linux_amd64 /usr/bin/yq
git config --global user.name "Tekton Bot"
git config --global user.email "kmaster8k@gmail.com"
git clone "https://${GIT_USERNAME}:${GIT_PASSWORD}@$(params.repositoryurl)" deploy-repo && cd "deploy-repo"
yq e '.hello.hello.image.repository = "$(params.imageurl)"' -i values.yaml
yq e '.hello.hello.image.tag = "$(params.imagetag)"' -i values.yaml
git add values.yaml
git commit -m "update"
git push
if [[ $? -eq 0 ]]
then
echo "Auto deployment triggered"
exit 0
else
echo "Auto deployment failed"
exit 1
fi
ArgoCD 설정
argocd설정은 다음을 참고한다.
https://kmaster.tistory.com/82
반응형
'Kubernetes > devops' 카테고리의 다른 글
Nexus에 Pypi 저장소 구축 (1) | 2023.12.29 |
---|---|
Kubernetes에 Nexus 설치 (0) | 2023.12.29 |
Giblab install on kubernetes (0) | 2022.10.09 |
Backstage (0) | 2022.10.02 |
dapr (0) | 2022.09.30 |
Comments