以受控且有序的方式部署 Kubernetes 資源

在集群中部署 Kubernetes 資源時,有時需要按照特定順序進行部署。例如,必須先存在自定義資源定義 (CRD),然後才能創建該類型的任何自定義資源。

Svelto 可以通過允許您指定 Kubernetes 資源的部署順序來幫助解決此問題。

ClusterProfile 順序

A ClusterProfile is a Kubernetes custom resource definition (CRD) that defines the resources that you want to deploy on a set of Kubernetes clusters.

ClusterProfile 允許客戶定義順序:

  • 使用 helmCharts 字段helmCharts 字段允許您指定需要部署的 Helm 圖表列表。Svelto 將按照該字段中列出的順序部署 Helm 圖表。
  • 使用 policyRefs 字段policyRefs 字段允許您引用需要部署的 ConfigMap 和 Secret 資源列表。Svelto 將按照該字段中列出的順序部署資源。

以下是一些示例:

  • 下面的 ClusterProfile 將首先部署 Prometheus Helm 圖表,然後部署 Grafana Helm 圖表:
YAML

 

apiVersion: config.projectsveltos.io/v1alpha1
kind: ClusterProfile
metadata:
  name: prometheus-grafana
spec:
  clusterSelector: env=fv
  syncMode: Continuous
  helmCharts:
  - repositoryURL:    https://prometheus-community.github.io/helm-charts
    repositoryName:   prometheus-community
    chartName:        prometheus-community/prometheus
    chartVersion:     23.4.0
    releaseName:      prometheus
    releaseNamespace: prometheus
    helmChartAction:  Install
  - repositoryURL:    https://grafana.github.io/helm-charts
    repositoryName:   grafana
    chartName:        grafana/grafana
    chartVersion:     6.58.9
    releaseName:      grafana
    releaseNamespace: grafana
    helmChartAction:  Install

資源部署順序與事件

在某些情況下,有必要在其他資源處於健康狀態後才部署 Kubernetes 資源。例如,在數據庫部署健康之前,不應部署在數據庫中創建表的作業。

Sveltos能助您解決此問題,方法是允許您使用事件來控制應用程式的部署。

事件是在特定條件達成時發出的通知。例如,您可以創建一個事件,當資料庫部署變得健康時發送。

接著,您可以利用此事件觸發在資料庫中創建表格的工作部署。

透過使用事件,您能確保應用程式的部署過程是可控且有序的。

在上例中,Sveltos已被告知執行以下步驟:

  1. 部署PostgreSQL部署及服務
  2. 等待PostgreSQL部署準備就緒
  3. 部署一個在資料庫中創建表格的工作
  4. 等待該工作完成
  5. 部署todo-app,該應用能夠存取PostgreSQL部署
  6. 等待todo-app健康運行
  7. 部署一個透過todo-app向資料庫添加條目的工作

此範例的所有YAML配置文件可在projectsveltos文檔中找到。

支持本項目

I hope you enjoyed this article! If you did, please check out the GitHub repo for the project. The repo contains the code, documentation, and examples, so it’s a great resource for getting started. 

若您覺得有用,亦可給項目加星

感謝閱讀!

Source:
https://dzone.com/articles/deploy-kubernetes-resources-in-a-controlled-and-or