在集群中部署Kubernetes资源时,有时需要按照特定顺序进行部署。例如,必须先存在自定义资源定义(CRD),然后才能创建该类型的任何自定义资源。
Sveltos通过允许您指定Kubernetes资源的部署顺序来帮助解决此问题。
集群配置顺序
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图表列表。Sveltos将按照该字段中列出的顺序部署Helm图表。 - 使用
policyRefs
字段:policyRefs
字段允许您引用需要部署内容的ConfigMap
和Secret资源列表。Sveltos将按照该字段中列出的顺序部署这些资源。
以下是一些示例:
- 下面的
ClusterProfile
将首先部署Prometheus Helm图表,然后是Grafana Helm图表:
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已按指令执行:
- 部署PostgreSQL部署和服务
- 等待PostgreSQL部署就绪
- 部署创建数据库表的任务
- 等待任务完成
- 部署可访问PostgreSQL部署的todo-app
- 等待todo-app健康运行
- 部署通过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