在本文中,我们将先容如何通过 KubeVela[2] 办理多集议论况下 Helm Chart 的支配问题。如果你手里没有多集群也不要紧,我们将先容一种仅依赖于 Docker 或者 Linux 系统的轻量级支配办法,可以让你轻松的体验多集群功能。当然,KubeVela 也完备具备单集群的 Helm Chart 交付[3]能力。
条件条件安装 Docker v20.10.5+ (runc >= v1.0.0-rc93) 或者你的操作系统是 Linux。VelaD[4],一个轻量级的支配 KubeVela 和 Kubernetes 的工具。准备集群本节是做 KubeVela 以及多集议论况的准备,我们将基于 Docker 或者 Linux 环境从头开始。如果你已经具备了 KubeVela 的环境并且完成了集群管理[5] ,则可以跳过本节。
安装 KubeVela 掌握平面

velad install
将新创建的集群导入到环境变量
export KUBECONFIG=$(velad kubeconfig --name default --host)
到这里,恭喜你!
我们已经完成了 KubeVela 掌握平面的安装。你可以通过下面这个办法加入你的 Kubernetes 集群:
vela cluster join <path-to-kubeconfig-of-cluster> --name foo
如果你没有现成的 Kubernetes 集群,VelaD 也可以很方便的为你创建一个:
用 velad 创建一个名为 foo 的集群,并加入到掌握平面
velad install --name foo --cluster-onlyvela cluster join $(velad kubeconfig --name foo --internal) --name foo
作为一个充分可扩展的掌握平面,KubeVela 的大多数能力都是作为插件供应的。接下来的几步我们先容安装 Helm 多集群支配的必要插件。
启用 velaux 插件,得到 UI 掌握台
vela addon enable velaux
启用 fluxcd 插件得到 helm chart 交付能力
vela addon enable fluxcd
如果你在加入新集群之前已启用过 fluxcd 插件,则该当通过以下办法来为新加入的集群启用(支配)插件:
vela addon enable fluxcd --clusters foo
至此,我们完成了所有的准备事情,可以查看加入的集群了:
$ vela cluster lsCLUSTER ALIAS TYPE ENDPOINT ACCEPTED LABELSlocal Internal - truefoo X509Certificate https://172.20.0.6:6443 true
local 是 KubeVela 掌握平面的集群,foo 则是我们刚刚添加的集群。
多集群支配我们可以利用 topology 策略来指定 Helm Chart 交付的环境,指令如下:
cat <<EOF | vela up -f -apiVersion: core.oam.dev/v1beta1kind: Applicationmetadata: name: helm-hellospec: components: - name: hello type: helm properties: repoType: "helm" url: "https://jhidalgo3.github.io/helm-charts/" chart: "hello-kubernetes-chart" version: "3.0.0" policies: - name: foo-cluster-only type: topology properties: clusters: ["foo"]EOF
clusters 字段的 topology 策略是一个切片(slice),此处可以指定多个集群的名称。你还可以利用标签选择器或指定命名空间,详情见参考文档[6] 。
支配后,你可以通过以下办法检讨已支配的运用程序:
vela status helm-hello
支配成功的预期输出该当如下:
About: Name: helm-hello Namespace: default Created at: 2022-06-09 19:14:57 +0800 CST Status: runningWorkflow: mode: DAG finished: true Suspend: false Terminated: false Steps - id:vtahj5zrz4 name:deploy-foo-cluster-only type:deploy phase:succeeded message:Services: - Name: hello Cluster: foo Namespace: default Type: helm Healthy Fetch repository successfully, Create helm release successfully No trait applied
你可以通过以下办法检讨已支配的资源:
$ vela status helm-hello --treeCLUSTER NAMESPACE RESOURCE STATUSfoo ─── default ─┬─ HelmRelease/hello updated └─ HelmRepository/hello updated
你也可以通过 VelaUX 检讨已支配的资源。
利用 UI 掌握台查看支配状态通过利用 velaux UI 掌握台,则可以很方便的查看多集群信息,并得到统一的体验。你可以参考文档[7]理解 VelaUX 的访问和利用细节。
通过 UI 界面,我们可以:
检讨来自不同集群的实例状态和事宜:检讨来自不同集群的实例日志:检讨资源拓扑关系和状态:利用 Override 配置进行支配
在某些情形下,我们会为不同集群的 Helm Chart 设置不同的 Value ,这样我们可以利用 Override 策略[8]。
下面是一个繁芜的示例,我们将把一个 Helm Chart 支配到两个集群中,并为每个集群指定不同的 Value 。让我们支配它:
cat <<EOF | vela up -f -apiVersion: core.oam.dev/v1beta1kind: Applicationmetadata: name: helm-hellospec: components: - name: hello type: helm properties: repoType: "helm" url: "https://jhidalgo3.github.io/helm-charts/" chart: "hello-kubernetes-chart" version: "3.0.0" policies: - name: topology-local type: topology properties: clusters: ["local"] - name: topology-foo type: topology properties: clusters: ["foo"] - name: override-local type: override properties: components: - name: hello properties: values: configs: MESSAGE: Welcome to Control Plane Cluster! - name: override-foo type: override properties: components: - name: hello properties: values: configs: MESSAGE: Welcome to Your New Foo Cluster! workflow: steps: - name: deploy2local type: deploy properties: policies: ["topology-local", "override-local"] - name: manual-approval type: suspend - name: deploy2foo type: deploy properties: policies: ["topology-foo", "override-foo"]EOF
把稳:如果你以为策略和事情流程有点繁芜,你可以将它们作为一个外部工具并仅引用该工具,用法和容器交付[9]是一样的。
支配过程分为三个步骤:
(1)支配到本地集群;
(2)等待人工审批;
(3)支配到 foo 集群。
你会创造它在第一步之后就被停息了,就像下面这样:
$ vela status helm-helloAbout: Name: helm-hello Namespace: default Created at: 2022-06-09 19:38:13 +0800 CST Status: workflowSuspendingWorkflow: mode: StepByStep finished: false Suspend: true Terminated: false Steps - id:ww4cydlvee name:deploy2local type:deploy phase:succeeded message: - id:xj6hu97e1e name:manual-approval type:suspend phase:succeeded message:Services: - Name: hello Cluster: local Namespace: default Type: helm Healthy Fetch repository successfully, Create helm release successfully No trait applied
你可以查看并利用 Value 为 “Welcome to Control Plane Cluster!” 的支配在掌握平面的 Helm Chart 。
vela port-forward helm-hello
浏览器会自动提示如下页面:
创造支配成功,让我们连续。
vela workflow resume helm-hello
然后它会支配到 foo 集群,你可以查看这些资源的详细信息。
$ vela status helm-hello --tree --detailCLUSTER NAMESPACE RESOURCE STATUS APPLY_TIME DETAILfoo ─── default ─┬─ HelmRelease/hello updated 2022-06-09 19:38:13 Ready: True Status: Release reconciliation succeeded Age: 64s └─ HelmRepository/hello updated 2022-06-09 19:38:13 URL: https://jhidalgo3.github.io/helm-charts/ Age: 64s Ready: True Status: stored artifact for revision 'ab876069f02d779cb4b63587af1266464818ba3790c0ccd50337e3cdead44803'local ─── default ─┬─ HelmRelease/hello updated 2022-06-09 19:38:13 Ready: True Status: Release reconciliation succeeded Age: 7m34s └─ HelmRepository/hello updated 2022-06-09 19:38:13 URL: https://jhidalgo3.github.io/helm-charts/ Age: 7m34s Ready: True
Status: stored 再次利用端口转发:
vela port-forward helm-hello
然后它会弹出一些选项:
? You have 2 deployed resources in your app. Please choose one: [Use arrows to move, type to filter]> Cluster: foo | Namespace: default | Kind: HelmRelease | Name: hello Cluster: local | Namespace: default | Kind: HelmRelease | Name: hello
选择带有 foo 集群的选项,然后你会看到结果已经被新覆盖。
$ curl http://127.0.0.1:8080/...snip... <div id="message"> Welcome to Your New Foo Cluster!</div>...snip...
为不同环境指定不同的 Value 文件
你可以为不同环境选择 Helm Chart 中现有的不同 Value 文件。比如:
请确保你确当地集群有两个命名空间 “test” 和 “prod”,它们代表我们示例中的两个环境。
我们以 Chart hello-kubernetes-chart 为例。这个 Chart 有两个 Value 文件。你可以拉取此 Chart 并查看个中包含的所有文件:
$ tree ./hello-kubernetes-chart./hello-kubernetes-chart├── Chart.yaml├── templates│ ├── NOTES.txt│ ├── _helpers.tpl│ ├── config-map.yaml│ ├── deployment.yaml│ ├── hpa.yaml│ ├── ingress.yaml│ ├── service.yaml│ ├── serviceaccount.yaml│ └── tests│ └── test-connection.yaml├── values-production.yaml└── values.yaml
我们可以看到此 Chart 中有 values.yaml values-production.yaml 这两个 Value 文件。
cat <<EOF | vela up -f -apiVersion: core.oam.dev/v1beta1kind: Applicationmetadata: name: hello-kubernetesspec: components: - name: hello-kubernetes type: helm properties: repoType: "helm" url: "https://wangyikewxgm.github.io/my-charts/" chart: "hello-kubernetes-chart" version: "0.1.0" policies: - name: topology-test type: topology properties: clusters: ["local"] namespace: "test" - name: topology-prod type: topology properties: clusters: ["local"] namespace: "prod" - name: override-prod type: override properties: components: - name: hello-kubernetes properties: valuesFiles: - "values-production.yaml" workflow: steps: - name: deploy2test type: deploy properties: policies: ["topology-test"] - name: deploy2prod type: deploy properties: policies: ["topology-prod", "override-prod"] EOF
访问 Application 的 endpoint :
vela port-forward hello-kubernetes
如果你选择 Cluster: local | Namespace: test | Kind: HelmRelease | Name: hello-kubernetes 你会看到:
选择 Cluster: local | Namespace: prod | Kind: HelmRelease | Name: hello-kubernetes 则会看到:
清理
如果你利用 velad 进行此演示,则可以通过以下办法便捷地进行清理:
清理 foo 集群velad uninstall -n foo
清理默认集群velad uninstall
不仅如此KubeVela 供应的能力远不止如此,通过安装其他插件,你还可以得到包括金丝雀发布[10] 在内的更多能力,为你的 Helm Chart 交付保驾护航。
快利用 KubeVela 交付 Helm Chart ,让当代化的运用交付和管理更大略、轻松、可靠!
干系链接
[1] Helm Charts:
https://artifacthub.io/packages/search?kind=0
[2] KubeVela:
https://kubevela.io/
[3] 单集群的 Helm Charts 交付
https://kubevela.net/zh/docs/tutorials/helm
[4] velad:
https://github.com/kubevela/velad
[5] 集群管理:
https://kubevela.net/zh/docs/platform-engineers/system-operation/managing-clusters
[6] 参考文档:
https://kubevela.net/zh/docs/end-user/policies/references#topology
[7] 文档
https://kubevela.io/docs/install#2-install-velaux
[8] Override 策略
https://kubevela.io/docs/end-user/policies/references#override
[9] 容器交付
https://kubevela.io/docs/case-studies/multi-cluster#use-policies-and-workflow-outside-the-application
[10] 金丝雀发布:
https://kubevela.io/docs/tutorials/helm-rollout
原文链接:http://click.aliyun.com/m/1000351093/
本文为阿里云原创内容,未经许可不得转载。