电子商务网站费用预算,中国网络营销论坛,楚雄 公司 网站,苏州有什么好玩的游乐园Helm Charts[1] 如今已是一种非常流行的软件打包方式#xff0c;在其应用市场中你可以找到接近一万款适用于云原生环境的软件。然后在如今的混合云多集群环境中#xff0c;业务越来越依赖部署到不同的集群、不同的环境、同时指定不同的配置。再这样的环境下#xff0c;单纯依…Helm Charts[1] 如今已是一种非常流行的软件打包方式在其应用市场中你可以找到接近一万款适用于云原生环境的软件。然后在如今的混合云多集群环境中业务越来越依赖部署到不同的集群、不同的环境、同时指定不同的配置。再这样的环境下单纯依赖 Helm 工具可能无法做到灵活的部署和交付。
在本文中我们将介绍如何通过 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-only
vela 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 ls
CLUSTER ALIAS TYPE ENDPOINT ACCEPTED LABELS
local Internal - true
foo X509Certificate https://172.20.0.6:6443 true
local 是 KubeVela 控制平面的集群foo 则是我们刚刚添加的集群。
多集群部署
我们可以使用 topology 策略来指定 Helm Chart 交付的环境指令如下
cat EOF | vela up -f -
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:name: helm-hello
spec:components:- name: hellotype: helmproperties:repoType: helmurl: https://jhidalgo3.github.io/helm-charts/chart: hello-kubernetes-chartversion: 3.0.0policies:- name: foo-cluster-onlytype: topologyproperties:clusters: [foo]
EOF
clusters 字段的 topology 策略是一个切片slice此处可以指定多个集群的名称。你还可以使用标签选择器或指定命名空间详情见参考文档[6] 。
部署后你可以通过以下方式检查已部署的应用程序
vela status helm-hello
部署成功的预期输出应该如下
About:Name: helm-helloNamespace: defaultCreated at: 2022-06-09 19:14:57 0800 CSTStatus: runningWorkflow:mode: DAGfinished: trueSuspend: falseTerminated: falseSteps- id:vtahj5zrz4name:deploy-foo-cluster-onlytype:deployphase:succeededmessage:Services:- Name: helloCluster: foo Namespace: defaultType: helmHealthy Fetch repository successfully, Create helm release successfullyNo trait applied
你可以通过以下方式检查已部署的资源
$ vela status helm-hello --tree
CLUSTER NAMESPACE RESOURCE STATUS
foo ─── 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/v1beta1
kind: Application
metadata:name: helm-hello
spec:components:- name: hellotype: helmproperties:repoType: helmurl: https://jhidalgo3.github.io/helm-charts/chart: hello-kubernetes-chartversion: 3.0.0policies:- name: topology-localtype: topologyproperties:clusters: [local]- name: topology-footype: topologyproperties:clusters: [foo]- name: override-localtype: overrideproperties:components:- name: helloproperties:values:configs:MESSAGE: Welcome to Control Plane Cluster!- name: override-footype: overrideproperties:components:- name: helloproperties:values:configs:MESSAGE: Welcome to Your New Foo Cluster!workflow:steps:- name: deploy2localtype: deployproperties:policies: [topology-local, override-local]- name: manual-approvaltype: suspend- name: deploy2footype: deployproperties:policies: [topology-foo, override-foo]
EOF
注意如果你觉得策略和工作流程有点复杂你可以将它们作为一个外部对象并仅引用该对象用法和容器交付[9]是一样的。
部署过程分为三个步骤
1部署到本地集群
2等待人工审批
3部署到 foo 集群。
你会发现它在第一步之后就被暂停了就像下面这样
$ vela status helm-hello
About:Name: helm-helloNamespace: defaultCreated at: 2022-06-09 19:38:13 0800 CSTStatus: workflowSuspendingWorkflow:mode: StepByStepfinished: falseSuspend: trueTerminated: falseSteps- id:ww4cydlveename:deploy2localtype:deployphase:succeededmessage:- id:xj6hu97e1ename:manual-approvaltype:suspendphase:succeededmessage:Services:- Name: helloCluster: local Namespace: defaultType: helmHealthy Fetch repository successfully, Create helm release successfullyNo 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 --detail
CLUSTER NAMESPACE RESOURCE STATUS APPLY_TIME DETAIL
foo ─── 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: TrueStatus: 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: helloCluster: local | Namespace: default | Kind: HelmRelease | Name: hello
选择带有 foo 集群的选项然后你会看到结果已经被新消息覆盖。
$ curl http://127.0.0.1:8080/
...snip...div idmessageWelcome 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/v1beta1
kind: Application
metadata:name: hello-kubernetes
spec:components:- name: hello-kubernetestype: helmproperties:repoType: helmurl: https://wangyikewxgm.github.io/my-charts/chart: hello-kubernetes-chartversion: 0.1.0policies:- name: topology-testtype: topologyproperties:clusters: [local]namespace: test- name: topology-prodtype: topologyproperties:clusters: [local]namespace: prod- name: override-prodtype: overrideproperties:components:- name: hello-kubernetesproperties:valuesFiles:- values-production.yamlworkflow:steps:- name: deploy2testtype: deployproperties:policies: [topology-test]- name: deploy2prodtype: deployproperties: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?kind0
[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
原文链接
本文为阿里云原创内容未经允许不得转载。