gpt4 book ai didi

kubernetes - Helm Subchart 伞图中的执行顺序

转载 作者:行者123 更新时间:2023-12-03 06:52:05 27 4
gpt4 key购买 nike

我有一个包含多个子图的伞图,我只是想确保 subchart1 在 subchart2 之前运行,等等。我们如何定义子图的执行顺序?

似乎钩子(Hook)权重仅适用于声明它们的图表。

最佳答案

这是 Helm 的一部分 documentation与图表执行顺序相关:

The above sections explain how to specify chart dependencies, but howdoes this affect chart installation using helm install and helmupgrade?

Suppose that a chart named "A" creates the following Kubernetesobjects

namespace "A-Namespace"
statefulset "A-StatefulSet"
service "A-Service"

Furthermore, A is dependent on chart B that createsobjects

namespace "B-Namespace"
replicaset "B-ReplicaSet"
service "B-Service"

After installation/upgrade of chart A a single Helm release iscreated/modified. The release will create/update all of the aboveKubernetes objects in the following order:

A-Namespace
B-Namespace
A-StatefulSet
B-ReplicaSet
A-Service
B-Service

This is because when Helm installs/upgrades charts, the Kubernetesobjects from the charts and all its dependencies are aggregrated into a single set; then sorted by type followed by name;and then created/updated in that order.
Hence a single release is created with all the objects for the chart and its dependencies.

The install order of Kubernetes types is given by the enumerationInstallOrder in kind_sorter.go (Helm v2 source file).

kind_sorter.go ( Helm v3 source ) 的一部分与安装图表相关:

var InstallOrder KindSortOrder = []string{
"Namespace",
"NetworkPolicy",
"ResourceQuota",
"LimitRange",
"PodSecurityPolicy",
"PodDisruptionBudget",
"Secret",
"ConfigMap",
"StorageClass",
"PersistentVolume",
"PersistentVolumeClaim",
"ServiceAccount",
"CustomResourceDefinition",
"ClusterRole",
"ClusterRoleList",
"ClusterRoleBinding",
"ClusterRoleBindingList",
"Role",
"RoleList",
"RoleBinding",
"RoleBindingList",
"Service",
"DaemonSet",
"Pod",
"ReplicationController",
"ReplicaSet",
"Deployment",
"HorizontalPodAutoscaler",
"StatefulSet",
"Job",
"CronJob",
"Ingress",
"APIService",
}

有一个解决方法可以更改默认行为,由 elementalvoid 在此 issue 中分享。 :

I've been setting my services, secrets, and configmaps as pre-installhooks to achieve this behavior.

Example:

apiVersion: v1
kind: Service
metadata:
name: foo
annotations:
"helm.sh/hook": "pre-install"

--

It is possible to define a weight for a hook which will help build adeterministic executing order. Weights are defined using the followingannotation:

  annotations:
"helm.sh/hook-weight": "5"

Hook weights can be positive or negative numbers but must berepresented as strings. When Tiller starts the execution cycle ofhooks of a particular Kind it will sort those hooks in ascendingorder.

有关 Hook 的更多详细信息可以在此处( v2 docv3 doc )和源文件( helm v2 sourcehelm v3 source )中找到

关于kubernetes - Helm Subchart 伞图中的执行顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50492389/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com