k8s中更優雅的持續發布ArgoCD


Argocd是一種更優雅的持續發布K8S服務的一種產品。
argocd是cncf畢業項目,前途不可估量。

Argocd介紹

前情介紹:
gitops哲學理念

GitOps可謂一個操作模型,提供了一組最佳實踐,對於容器集群和應用的統一部署,管理和監控。所有的變更都應該落地到git倉庫,所有的運行狀態與git倉庫配置一致。

比如你的yaml配置在git repo里面,但是k8s里面運行的實際情況,如果有不一致如何發現?

多個devops、SRE如何協同工作?

所以Gitops的核心思想:

“將應用系統的聲明性基礎架構和應用程序存放在Git的版本控制庫中”

gitops的優點:

安全的雲原生CI/CD管道模型
更快的平均部署時間和平均恢復時間
穩定且可重現的回滾(例如,根據Git恢復/回滾/ fork)
與監控和可視化工具相結合,對已經部署的應用進行全方位的監控

Argocd組成


1.argocd-server argocd的api服務,無狀態。
2.argocd-application應用服務控制器,通過和k8s api以及argocd-repo的聲明進行服務狀態對比,無狀態。
3.argocd-repo服務,負責管理gitops的倉庫、認證憑證等等,無狀態。
4.argo-dex-server和redis是argocd的基礎設施數據庫。

核心概念

Application:清單定義的一組Kubernetes資源。這是一個自定義資源定義(CRD)。

Application source type:使用哪個工具來構建應用程序

Target state:應用程序的期望狀態,由Git存儲庫中的文件表示。

Live state:該應用程序的實時狀態。部署了哪些Pod等。

Sync status:實時狀態是否與目標狀態匹配。部署的應用程序是否與Git所說的相同?

Sync:使應用程序移至其目標狀態的過程。例如。通過將更改應用於Kubernetes集群。

Refresh:將Git中的最新代碼與實時狀態進行比較。找出有什么不同。

Health:應用程序的運行狀況是否正常運行?它可以滿足請求嗎?

Tool:從文件目錄創建清單的工具。例如。Kustomize或Ksonnet。請參閱應用程序源類型。

英文版本:
Application A group of Kubernetes resources as defined by a manifest.
This is a Custom Resource Definition (CRD).
通俗理解:就是需要部署的服務

Application source type Which Tool is used to build the application.
Target state The desired state of an application, as represented by files in a Git repository.
通俗理解:應用部署服務的源類型,因為現在部署k8s的手段有點多,就是部署源文件可能來自helm、yaml、json、Kustomize等各種變態工具。

Live state The live state of that application. What pods etc are deployed.
通俗理解:實時狀態,服務在k8s集群中的實時狀態,到底是運行還是拉取,還是崩潰狀態。
Sync status Whether or not the live state matches the target state. Is the deployed application the same as Git says it should be?
Sync The process of making an application move to its target state. E.g. by applying changes to a Kubernetes cluster.
通俗理解:同步狀態,到底是同步還是不同步在狀態,可能倉庫比較新,而運行狀態比較老。或者哪個沙雕手工直接更改了k8s的部署,而沒有更新git狀態,也會導致不一致。
Sync operation status Whether or not a sync succeeded.
通俗理解:同步,就是說你實際運行與git倉庫里面的編排不一致,就需要同步操作。

Refresh Compare the latest code in Git with the live state. Figure out what is different.
通俗理解:刷新運行態與倉庫實際定義是否一致,手動擋刷新。
Health The health of the application, is it running correctly? Can it serve requests?
通俗理解:運行服務是否正常,是不是按預期運行。
Tool A tool to create manifests from a directory of files. E.g. Kustomize or Ksonnet. See Application Source Type.
通俗理解:編排工具選擇。
Configuration management tool See Tool.
Configuration management plugin A custom tool.

服務部署

kubectl create namespace argocd
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml

服務情況


通過argocd管理UI進行發布服務

kubectl port-forward svc/argocd-server 1800:80 -n argocd
就可以通過http://127.0.0.1:1800進行訪問argocd-ui

用戶名admin密碼是argocd-server的pod名稱

如何獲取argocd-server的pod名稱就不需要我說了吧:-)

手工部署好后的一個服務狀態

查看服務部署詳情

后面的就只需持續發布更新我們的gitops repo就可以實現Gitops了!!!

如何在CICD中無縫集成呢,先拋一段代碼

#Makefile
build: 
	$你的編譯流程
docker-build: build
	docker build -t $img:$(GIT_VERSION) .
push: docker-build
	docker push $img:$(GIT_VERSION)
gitops:
	kustomize edit set $img:$(GIT_VERSION)
	git pull && git commit -am "注釋" && git push
  #push完成后,如果你在argo上設置的是自動更新,就會自動發布,如果設置的手功更新就手工操作


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM