使用 OCM
Open Cluster Management (OCM) 是一个强大的多集群管理工具,它可以让你的托管集群连接到集群的控制平面,甚至这些托管的集群并不能被控制平面直接访问到。它特别能处理托管集群和控制平面处于不同VPC的情况。
这篇文章主要介绍在 KubeVela 的环境下如何使用 OCM。
安装 OCM
OCM的安装可以通过命令vela addon来完成。但在 KubeVela 的环境下使用 OCM,有两个插件必须要安装。
$ vela addon enable ocm-hub-control-plane
这个插件旨在提供 OCM 的基本功能。例如,你可以通过创建 OCM ManifestWorks 来直接分配资源。 但是目前 KubeVela 并不会使用 OCM 来管理应用。
$ vela addon enable ocm-gateway-manager-addon
安装第二个应用可以让 KubeVela 通过 cluster gateway 来使用 OCM的托管集群。
加入集群
你可以使用 vela cluster join -t ocm 命令来加入 OCM ManagedCluster。请注意, 相比较通过 vela cluster join 命令来加入集群,加入 OCM ManagedCluster 并不需要你的托管集群的 APIServer 可以直接被中心的控制平面访问到。 但是你必须保证你的托管集群可以访问中心控制平面的 KAS (kube-apiserver)。
# This command needs to use the kubeconfig of the control plane where KubeVela lives.$ vela cluster join managed-cluster.kubeconfig -t ocm --name ocm-clusterSuccessfully prepared registration config.Registration operator successfully deployed.Registration agent successfully deployed.Successfully found corresponding CSR from the agent.Approving the CSR for cluster "ocm-cluster".Successfully add cluster ocm-cluster, endpoint: https://127.0.0.1:6443.
检查集群状态
在运行命令后, 你可能需要几分钟时间来等待相关 OCM agents 就绪。
# Change ocm-cluster to your cluster name.$ kubectl get managedclusteraddons -n ocm-clusterNAME AVAILABLE DEGRADED PROGRESSINGcluster-proxy Truemanaged-serviceaccount Truecluster-gateway True
假如任何 ManagedClusterAddons 不可用, 你可能需要检查所有 OCM 相关的 pod 是否都正常运行。可以随时在 KubeVela Github Repo 提出 issues or discussions.
现在你可以通过命令 vela cluster probe 来验证插件的安装。
$ vela cluster probe ocm-clusterConnect to cluster ocm-cluster successfully.ok
应用 KubeVela Application
很好! 现在你可以在 KubeVela 环境下像使用普通集群一样使用已经加入的 OCM 托管集群。
$ cat <<EOF | vela up -f -apiVersion: core.oam.dev/v1beta1kind: Applicationmetadata:name: example-appnamespace: defaultspec:components:- name: hello-worldproperties:image: crccheck/hello-worldtype: webservicepolicies:- name: ocm-clusterproperties:clusters: ["ocm-cluster"]type: topologyEOF
$ vela status example-appAbout:Name: example-appNamespace: defaultCreated at: 2022-06-14 21:10:46 +0800 CSTStatus: runningWorkflow:mode: DAGfinished: trueSuspend: falseTerminated: falseSteps- id:vl17hfpjtvname:deploy-ocm-clustertype:deployphase:succeededmessage:Services:- Name: hello-worldCluster: ocm-cluster Namespace: defaultType: webserviceHealthy Ready:1/1No trait applied
参考
关于在 KubeVela 环境下使用 OCM 更多的信息,可以参与以下内容。
- Open Cluster Management OCM 项目
- ocm-hub-control-plane
ocm-hub-control-planeKubeVela 插件 - ocm-gateway-manager-addon
ocm-gateway-manager-addonKubeVela 插件 - KubeVela x OCM Demo. KubeVela 和 OCM 的演示