写点什么

使用 Helm 部署 GraphScope

作者:6979阿强
  • 2022 年 4 月 13 日
  • 本文字数:3609 字

    阅读完需:约 12 分钟

使用 Helm 部署 GraphScope

本文介绍如何通过 Helm 工具部署和使用 GraphScope 集群。


Helm[1] 作为 K8s 生态系统中的软件包管理工具,类似于 Ubuntu 的 apt 或 Python 的 pip,专门负责管理 K8s 的应用资源。使用 Helm 可以很容易地对 kubernetes 应用进行统一打包、分发、安装、升级以及回退等操作。GraphScope 也支持通过 Helm 进行部署和使用。

前置准备

在开始之前,请确保当前环境具备一个可操作的 K8s 集群,如果没有,则可以参考这篇文章进行安装;此外,为了完整运行本文中的示例,你还需要在本机上安装 GraphScope Python 客户端:


$ pip3 install graphscope
复制代码

安装 Helm

根据 Helm 官方文档[2],可通过如下命令安装 Helm。


$ curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
复制代码


如果服务器无法连接网络,则可以在有网的环境中预下载 Helm,然后拷贝到服务器上,这里以安装 Helmv3.8.1 为例:


$ wget https://get.helm.sh/helm-v3.8.1-linux-amd64.tar.gz$ tar zxvf helm-v3.8.1-linux-amd64.tar.gz
复制代码


解压之后,可自行将 helm 文件拷贝到服务器上,并将其放到 /usr/local/bin 目录下即可,然后执行 helm version,如果正常输出则表示 Helm 安装成功。


$ helm versionversion.BuildInfo{Version:"v3.8.1", GitCommit:"5cb9af4b1b271d11d7a97a71df3ac337dd94ad37", GitTreeState:"clean", GoVersion:"go1.17.5"}
复制代码

配置 Helm repo

GraphScope 的 Helm Charts[3] 托管在仓库 https://graphscope.oss-cn-beijing.aliyuncs.com/ 中,因此你可以通过如下命令添加该仓库:


$ helm repo add graphscope https://graphscope.oss-cn-beijing.aliyuncs.com/charts/"graphscope" has been added to your repositories
复制代码


添加完成后,可使用 helm search 搜索 GraphScope 提供的 Charts。


$ helm search repo graphscopeNAME                            CHART VERSION   APP VERSION     DESCRIPTIONgraphscope/graphscope           0.11.0          0.11.0          A One-Stop Large-Scale Graph Computing System f...
复制代码

Helm 常用操作

Helm 的常用操作有部署(helm install)、升级(helm upgrade)、销毁(helm uninstall)、查询(helm ls),同时往往某个 Helm Chart 有很多需要配置的参数,通过命名行方式配置比较繁琐,因此推荐使用 YAML 文件的形式来配置这些参数,本文接下来将用于配置 chart 的 YAML 文件称为 values.yaml,这也是 Helm 社区约定俗成的命名方式。

安装 GraphScope Chart

以 Helm 方式部署的 GraphScope 需要一些删除资源的权限,因此首先需要通过以下命令创建相应角色:


# example for `default` ServiceAccount with `default` namespace$ wget https://raw.githubusercontent.com/alibaba/GraphScope/main/charts/role_and_binding.yaml
$ kubectl create -f ./role_and_binding.yamlrole.rbac.authorization.k8s.io/grole createdrolebinding.rbac.authorization.k8s.io/grole-binding created
复制代码


角色创建完成后,我们便可以安装 GraphScope Chart,需要注意的是,Chart 的安装和升级操作必须指定 Chart 的名字(chart_name)和部署后的实例名字(release_name),还可以指定一个或多个values.yaml文件来配置 Chart,同时如果对 Chart 的版本有特定要求,则可以通过 --version 参数指定相应版本(chart_version,默认为最新版本),最终命令如下:


$ helm install graphscope graphscope/graphscope --namespace=default --version=0.11.0
复制代码


在上述命令中,我们在 default 命名空间下安装了 0.11.0 版本的 GraphScope 实例,且实例名字为 graphscope。

获取 GraphScope 服务的地址

由于第一次安装 Chart 的过程中会拉取镜像,因此需要等待几分钟时间,这期间你可以通过多次执行 helm test 命令来观察状态:


$ helm test graphscopeNAME: graphscopeLAST DEPLOYED: Wed Mar 30 21:02:51 2022NAMESPACE: defaultSTATUS: deployedREVISION: 1TEST SUITE:     graphscope-test-rpc-serviceLast Started:   Thu Mar 17 13:10:39 2022Last Completed: Thu Mar 17 13:10:46 2022Phase:          SucceededNOTES:The GraphScope has been deployed.
复制代码


如果状态输出如上述所示,代表本地 GraphScope 实例已经安装成功,接下来以 default 命令空间为例,此时我们可以获取当前实例的服务地址:


$ export NODE_IP=$(kubectl --namespace default get pod -l graphscope.coordinator.name=graphscope-coordinator --no-headers=true | awk '/ /{print $1}' | xargs kubectl --namespace default get pod -o jsonpath="{.status.hostIP}")
$ export NODE_PORT=$(kubectl --namespace default get services -o jsonpath="{.spec.ports[0].nodePort}" graphscope-coordinator-service)
$ echo "GraphScope service listen on ${NODE_IP}:${NODE_PORT}"GraphScope service listen on 192.168.0.65:30262
复制代码


上述命令较为繁琐,不用担心,GraphScope Chart 安装成功后的控制台会显示服务获取所对应的命令,你只需要复制执行这些命令即可。

使用客户端连接服务

服务地址(在上述命令中是 192.168.0.65:30262)获取后,我们便可以使用 GraphScope Python 客户端连接到该服务:


>>> import graphscope>>> graphscope.set_option(show_log=True)>>> # sess = graphscope.session(addr='<ip>:<port>')>>> sess = graphscope.session(addr='192.168.0.65:30262')Connecting graphscope session with address: 192.168.0.65:30262GraphScope coordinator service connected.
复制代码


与通过 Python 客户端拉起 GraphScope 的方式不同,使用 Helm 工具部署的 GraphScope 实例不会和客户端的生命周期强绑定,因此我们可以多次的通过客户端连接到一个以 Helm 部署的 GraphScope 实例上,但同一时刻只能有一个客户端连接到该服务。


>>> import graphscope>>> sess1 = graphscope.session(addr='192.168.0.65:30262')>>> sess1.close() # 前一个 session 关闭后,才允许后续 session 连接>>> sess2 = graphscope.session(addr='192.168.0.65:30262')
复制代码

释放 GraphScope 实例

释放实例只需要对应的实例名字:


$ helm uninstall graphscope\release "graphscope" uninstalled
复制代码

参数配置

通过 Helm 部署 GraphScope 的方式同样可以配置定制集群的参数,如 CPU、内存,以及挂载卷等。目前支持的参数配置请参考 values.yaml[4] 文件。这里我们以挂载数据集为例,说明如何通过 values.yaml 来配置 GraphScope Chart,这也是使用过程中最常见的情况之一。


首先我们需要创建values.yaml文件,文件内容如下:


volumes:  enabled: true  items:    data:      type: hostPath      field:        type: Directory        path: /testingdata      mounts:      - mountPath: /tmp/testingdata
复制代码


上述描述 volumes 将使用 K8s Hostpath 类型卷,并将对应节点的 /testingdata 路径挂载到 GraphScope 实例中的 /tmp/testingdata 路径上,有关挂载卷的详细细节可参考 K8s 官方文档[5]。


接下来,我们便可以在安装 GraphScope Chart 的时候指定上述 values.yaml 文件:


$ helm install graphscope graphscope/graphscope -f values.yaml
复制代码


其它有关资源的配置,如 CPU 和内存,同样可参考 GraphScope 配置文件[6]进行配置。

离线使用 Helm charts

如果服务器没有外网,就无法通过配置 Helm repo 的方式安装 GraphScope。这时,需要在有外网的机器上下载集群安装需要用到的 chart 文件,再拷贝到服务器上,以 0.11.0 版本为例,下载命令如下:


$  wget https://graphscope.oss-cn-beijing.aliyuncs.com/charts/graphscope-0.11.0.tgz
复制代码


下载完成后,可自行拷贝到服务器对应的目录并解压,解压完成后,可以通过 helm install 命令使用这些 charts 安装 GraphScope 实例,命令如下。需要注意的是,安装实例的过程需要服务器预先下载好镜像,可参考这篇文章的离线部署章节进行预下载。


$ tar zxvf graphscope-0.11.0.tgz\$ helm install graphscope ./graphscope --namespace=default
复制代码

结语

本文重点介绍了如何使用 GraphScope 客户端连接到一个通过 Helm 工具部署的 GraphScope 集群。此外,GraphScope 后续也会通过 GraphScope Operator 的方式让用户在 Kubernetes 上对 GraphScope 的部署、运维和使用更加简单,欢迎持续关注 GraphScope。

参考资料

[1]Helm: https://helm.sh/


[2]Helm 官方文档: https://helm.sh/docs/intro/install/


[3]Helm Charts: https://artifacthub.io/packages/helm/graphscope/graphscope


[4]values.yaml: https://github.com/alibaba/GraphScope/blob/main/charts/graphscope/values.yaml


[5]K8s 官方文档: https://kubernetes.io/zh/docs/concepts/storage/volumes/


[6]GraphScope 配置文件: https://github.com/alibaba/GraphScope/blob/main/charts/graphscope/values.yaml

用户头像

6979阿强

关注

还未添加个人签名 2021.06.11 加入

还未添加个人简介

评论

发布
暂无评论
使用 Helm 部署 GraphScope_大数据_6979阿强_InfoQ写作平台