自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Helm Chart 多環(huán)境、多集群交付實(shí)踐,透視資源拓?fù)浜筒町?/h1>

開發(fā) 新聞
在本文中,我們將介紹如何通過 KubeVela 解決多集群環(huán)境下 Helm Chart 的部署問題。

Helm Charts[1] 如今已是一種非常流行的軟件打包方式,在其應(yīng)用市場(chǎng)中你可以找到接近一萬款適用于云原生環(huán)境的軟件。然后在如今的混合云多集群環(huán)境中,業(yè)務(wù)越來越依賴部署到不同的集群、不同的環(huán)境、同時(shí)指定不同的配置。再這樣的環(huán)境下,單純依賴 Helm 工具可能無法做到靈活的部署和交付。

在本文中,我們將介紹如何通過 KubeVela[2] 解決多集群環(huán)境下 Helm Chart 的部署問題。如果你手里沒有多集群也不要緊,我們將介紹一種僅依賴于 Docker 或者 Linux 系統(tǒng)的輕量級(jí)部署方式,可以讓你輕松的體驗(yàn)多集群功能。當(dāng)然,KubeVela 也完全具備單集群的 Helm Chart 交付[3]能力。

前提條件

  • 安裝 Docker v20.10.5+ (runc >= v1.0.0-rc93) 或者你的操作系統(tǒng)是 Linux。
  • VelaD[4],一個(gè)輕量級(jí)的部署 KubeVela 和 Kubernetes 的工具。

準(zhǔn)備集群

本節(jié)是做 KubeVela 以及多集群環(huán)境的準(zhǔn)備,我們將基于 Docker 或者 Linux 環(huán)境從頭開始。如果你已經(jīng)具備了 KubeVela 的環(huán)境并且完成了集群管理[5] ,則可以跳過本節(jié)。

安裝 KubeVela 控制平面

velad install

將新創(chuàng)建的集群導(dǎo)入到環(huán)境變量

export KUBECONFIG=$(velad kubeconfig --name default --host)

到這里,恭喜你!我們已經(jīng)完成了 KubeVela 控制平面的安裝。你可以通過下面這個(gè)方式加入你的 Kubernetes 集群:

vela cluster join <path-to-kubeconfig-of-cluster> --name foo

如果你沒有現(xiàn)成的 Kubernetes 集群,VelaD 也可以很方便的為你創(chuàng)建一個(gè):

用 velad 創(chuàng)建一個(gè)名為 foo 的集群,并加入到控制平面

velad install --name foo --cluster-only
vela cluster join $(velad kubeconfig --name foo --internal) --name foo

作為一個(gè)充分可擴(kuò)展的控制平面,KubeVela 的大多數(shù)能力都是作為插件提供的。接下來的幾步我們介紹安裝 Helm 多集群部署的必要插件。

啟用 velaux 插件,獲得 UI 控制臺(tái)

vela addon enable velaux

啟用 fluxcd 插件獲得 helm chart 交付能力

vela addon enable fluxcd

如果你在加入新集群之前已啟用過 fluxcd 插件,則應(yīng)該通過以下方式來為新加入的集群?jiǎn)⒂茫ú渴穑┎寮?/span>

vela addon enable fluxcd --clusters foo

至此,我們完成了所有的準(zhǔn)備工作,可以查看加入的集群了:

$ 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 交付的環(huán)境,指令如下:

cat <<EOF | vela up -f -
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: helm-hello
spec:
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 策略是一個(gè)切片(slice),此處可以指定多個(gè)集群的名稱。你還可以使用標(biāo)簽選擇器或指定命名空間,詳情見參考文檔[6] 。

部署后,你可以通過以下方式檢查已部署的應(yīng)用程序:

vela status helm-hello

部署成功的預(yù)期輸出應(yīng)該如下:

About:

Name: helm-hello
Namespace: default
Created at: 2022-06-09 19:14:57 +0800 CST
Status: running

Workflow:

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 --tree
CLUSTER NAMESPACE RESOURCE STATUS
foo ─── default ─┬─ HelmRelease/hello updated
└─ HelmRepository/hello updated

你也可以通過 VelaUX 檢查已部署的資源。

使用 UI 控制臺(tái)查看部署狀態(tài)

通過使用 velaux UI 控制臺(tái),則可以很方便的查看多集群信息,并獲得統(tǒng)一的體驗(yàn)。你可以參考文檔[7]了解 VelaUX 的訪問和使用細(xì)節(jié)。

通過 UI 界面,我們可以:

  • 檢查來自不同集群的實(shí)例狀態(tài)和事件:

  • 檢查來自不同集群的實(shí)例日志:

  • 檢查資源拓?fù)潢P(guān)系和狀態(tài):

使用 Override 配置進(jìn)行部署

在某些情況下,我們會(huì)為不同集群的 Helm Chart 設(shè)置不同的 Value ,這樣我們可以使用 Override 策略[8]

下面是一個(gè)復(fù)雜的示例,我們將把一個(gè) Helm Chart 部署到兩個(gè)集群中,并為每個(gè)集群指定不同的 Value 。讓我們部署它:

cat <<EOF | vela up -f -
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: helm-hello
spec:
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

注意:如果你覺得策略和工作流程有點(diǎn)復(fù)雜,你可以將它們作為一個(gè)外部對(duì)象并僅引用該對(duì)象,用法和容器交付[9]是一樣的。

部署過程分為三個(gè)步驟:

(1)部署到本地集群;

(2)等待人工審批;

(3)部署到 foo 集群。

你會(huì)發(fā)現(xiàn)它在第一步之后就被暫停了,就像下面這樣:

$ vela status helm-hello
About:

Name: helm-hello
Namespace: default
Created at: 2022-06-09 19:38:13 +0800 CST
Status: workflowSuspending

Workflow:

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

瀏覽器會(huì)自動(dòng)提示如下頁(yè)面:

發(fā)現(xiàn)部署成功,讓我們繼續(xù)。

vela workflow resume helm-hello

然后它會(huì)部署到 foo 集群,你可以查看這些資源的詳細(xì)信息。

$ 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: 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 再次使用端口轉(zhuǎn)發(fā):

vela port-forward helm-hello

然后它會(huì)彈出一些選項(xiàng):

? 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 集群的選項(xiàng),然后你會(huì)看到結(jié)果已經(jīng)被新消息覆蓋。

$ curl http://127.0.0.1:8080/
...snip...
<div id="message">
Welcome to Your New Foo Cluster!
</div>

為不同環(huán)境指定不同的 Value 文件

你可以為不同環(huán)境選擇 Helm Chart 中現(xiàn)有的不同 Value 文件。比如:

請(qǐng)確保你的本地集群有兩個(gè)命名空間 “test” 和 “prod”,它們代表我們示例中的兩個(gè)環(huán)境。

我們以 Chart hello-kubernetes-chart 為例。這個(gè) Chart 有兩個(gè) 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 這兩個(gè) Value 文件。

cat <<EOF | vela up -f -
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: hello-kubernetes
spec:
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 你會(huì)看到:

選擇 Cluster: local | Namespace: prod | Kind: HelmRelease | Name: hello-kubernetes 則會(huì)看到:

清理

如果你使用 velad 進(jìn)行此演示,則可以通過以下方式便捷地進(jìn)行清理:

  • 清理 foo 集群

velad uninstall -n foo

  • 清理默認(rèn)集群

velad uninstall

不僅如此

KubeVela 提供的能力遠(yuǎn)不止如此,通過安裝其他插件,你還可以獲得包括金絲雀發(fā)布[10] 在內(nèi)的更多能力,為你的 Helm Chart 交付保駕護(hù)航。

快使用 KubeVela 交付 Helm Chart ,讓現(xiàn)代化的應(yīng)用交付和管理更簡(jiǎn)單、輕松、可靠!

相關(guān)鏈接

[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] 金絲雀發(fā)布:

?https://kubevela.io/docs/tutorials/helm-rollout?

責(zé)任編輯:張燕妮 來源: 阿里云云棲號(hào)
相關(guān)推薦

2021-06-24 08:25:38

flux2GitOps 云原生

2014-02-21 15:21:29

集群共享運(yùn)維人員

2021-11-22 16:21:28

Kubernetes 運(yùn)維開源

2023-09-07 08:58:36

K8s多集群

2022-05-24 09:00:00

云計(jì)算Kubernetes安全

2024-01-08 07:29:57

多集群模型Istio網(wǎng)絡(luò)拓?fù)?/a>

2019-09-02 13:57:07

Helm Chart工具Kubernetes

2024-03-28 12:55:00

消息中間件RocketMQ

2024-09-19 14:02:16

2023-04-06 17:17:29

混合云Kubernetes多集群

2021-01-07 10:18:03

Redis數(shù)據(jù)庫(kù)環(huán)境搭建

2020-11-05 10:40:07

Spring Boot多模塊Java

2023-07-18 08:04:50

NAME搜索域代碼

2009-06-11 09:35:47

GlassFish配置多機(jī)集群

2021-12-24 10:47:49

Kubernetes容器化微服務(wù)

2021-02-07 08:00:00

Kubernetes集群云原生

2022-07-24 21:11:19

KubernetesLinux

2021-08-31 07:00:26

Kubernetes Clusternet開源

2023-08-29 15:45:20

單模光纖多模光纖

2019-06-12 09:29:53

PBElasticsear架構(gòu)
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)