Skip to content

Commit 30022c9

Browse files
authored
unify the local k8s cluster setup tool with kind (#116)
* unify local k8s cluster setup with kind; MacOS can use prepare_env script * fix * fix * update * remove darwin code * update README and docs * update * update
1 parent 512a5b8 commit 30022c9

File tree

7 files changed

+103
-61
lines changed

7 files changed

+103
-61
lines changed

README-zh.md

+15-7
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,19 @@ GraphScope 整合了达摩院的多项学术研究成果,其中的核心技术
1919

2020
## 快速开始
2121

22-
GraphScope 设计在 [Kubernetes (k8s)](https://kubernetes.io/) 管理的群集上运行。为了快速上手,我们可以利用 [minikube](https://minikube.sigs.k8s.io/) 来创建一个本地的 Kubernetes 集群,并根据如下步骤利用我们预先构建的 GraphScope 镜像
22+
GraphScope 设计在 [Kubernetes (k8s)](https://kubernetes.io/) 管理的群集上运行。为了快速上手,我们可以按照本文档的以下步骤部署一个本地 Kubernetes 集群,并加载预编译好的镜像。
2323

24-
### 环境准备
24+
### 环境准备
2525

26-
为了在本地环境下使用 minikube 跑通我们的示例,以下软件需要您预先安装:
26+
本地运行 GraphScope 需要预先安装以下依赖:
2727

2828
- Docker
29-
- minikube
3029
- Python >= 3.6 (以及 pip)
30+
- Local Kubernetes cluster set-up tool (例如 [Kind](https://kind.sigs.k8s.io))
3131

32-
对于 Linux 环境,我们也提供了一个脚本来安装以上软件来准备环境。
32+
对于 Windows 和 MacOS 的用户,可通过官方文档来安装上述依赖, 并在Docker中开启Kubernetes功能。
33+
对于 Ubuntu/CentOS Linux 发行版用户,我们提供了脚本来准备运行时环境。
34+
您也可以在 Windows 上安装 `WSL2 <https://docs.microsoft.com/zh-cn/windows/wsl/install-win10>`_ 以使用脚本。
3335

3436
```bash
3537
# run the environment preparing script.
@@ -97,6 +99,12 @@ k8s_volumes = {
9799
sess = graphscope.session(k8s_volumes=k8s_volumes)
98100
```
99101

102+
对于 macOS,创建会话需要使用 LoadBalancer 服务类型(默认是 NodePort)。
103+
104+
```python
105+
sess = graphscope.session(k8s_volumes=k8s_volumes, k8s_service_type="LoadBalancer")
106+
```
107+
100108
会话的建立过程中,首选会在背后尝试拉起一个 `coordinator` 作为后端引擎的入口。
101109
`coordinator` 负责管理该次会话的所有资源(k8s pods),以及交互式查询、图分析、图学习引擎的生命周期。
102110
`coordinator` 后续拉起的其他每个 pod 中,都有一个 vineyard 实例作为内存管理层,分布式的管理图数据。
@@ -111,9 +119,9 @@ GraphScope 以属性图(property graph)建模图数据。属性图中,点
111119
</div>
112120

113121
该图具有四种顶点,分别标记为“论文”、“作者”、“机构”和“研究领域”。有四种连接它们的边,
114-
每种边都有一个标签,并且边的两端顶点的标签也是确定的。
122+
每种边都有一个标签,并且边的两端顶点的标签也是确定的。
115123
例如,“引用”这种标签的边连接两个“论文”顶点。另一个例子是标记为“撰写”的边,
116-
它要求该起始点的标记为“作者”,终止点的标记为“论文”。
124+
它要求该起始点的标记为“作者”,终止点的标记为“论文”。
117125
所有的顶点和边都可以具有属性。 例如,“论文”顶点具有诸如发布年份、主题标签等属性。
118126

119127
要将此图加载到 GraphScope,可以将以下代码与

README.md

+11-8
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ To run GraphScope on your local computer, the following dependencies or tools ar
2626

2727
- Docker
2828
- Python >= 3.6 (with pip)
29-
- Local Kubernetes cluster set-up tool (e.g. [Minikube](https://minikube.sigs.k8s.io) or [Kind](https://kind.sigs.k8s.io))
29+
- Local Kubernetes cluster set-up tool (e.g. [Kind](https://kind.sigs.k8s.io))
3030

31-
On macOS, you can follow the official guides to install them.
31+
On macOS, you can follow the official guides to install them and enable Kubernetes in Docker.
3232
For Ubuntu/CentOS Linux distributions, we provide a script to install the above
3333
dependencies and prepare the environment.
3434
On Windows, you may want to install [Ubuntu](https://ubuntu.com/blog/ubuntu-on-wsl-2-is-generally-available) on [WSL2](https://docs.microsoft.com/zh-cn/windows/wsl/install-win10) to use the script.
@@ -78,26 +78,29 @@ To use GraphScope, we need to establish a session in a python interpreter.
7878
import os
7979
import graphscope
8080

81-
# Setting an env for mounting test data from local disk,
82-
# hence we can access data inside the pods.
83-
8481
# assume we mount `~/test_data` to `/testingdata` in pods.
8582
k8s_volumes = {
8683
"data": {
8784
"type": "hostPath",
8885
"field": {
89-
"path": os.path.expanduser("~/test_data/"),
90-
"type": "Directory"
86+
"path": os.path.expanduser("~/test_data/"),
87+
"type": "Directory"
9188
},
9289
"mounts": {
93-
"mountPath": "/testingdata"
90+
"mountPath": "/testingdata"
9491
}
9592
}
9693
}
9794

9895
sess = graphscope.session(k8s_volumes=k8s_volumes)
9996
```
10097

98+
For macOS, the session needs to establish with the LoadBalancer service type (which is NodePort by default).
99+
100+
```python
101+
sess = graphscope.session(k8s_volumes=k8s_volumes, k8s_service_type="LoadBalancer")
102+
```
103+
101104
A session tries to launch a `coordinator`, which is the entry for the back-end engines.
102105
The coordinator manages a cluster of resources (k8s pods),
103106
and the interactive/analytical/learning engines ran on them.

docs/getting_started.rst

+31-1
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,30 @@ To use GraphScope, we need to establish a :ref:`Session` in a python interpreter
5353

5454
.. code:: python
5555
56+
import os
5657
import graphscope
57-
sess = graphscope.session()
58+
59+
# assume we mount `~/test_data` to `/testingdata` in pods.
60+
k8s_volumes = {
61+
"data": {
62+
"type": "hostPath",
63+
"field": {
64+
"path": os.path.expanduser("~/test_data/"),
65+
"type": "Directory"
66+
},
67+
"mounts": {
68+
"mountPath": "/testingdata"
69+
}
70+
}
71+
}
72+
73+
sess = graphscope.session(k8s_volumes=k8s_volumes)
74+
75+
For macOS, the session needs to establish with the LoadBalancer service type (which is NodePort by default).
76+
77+
.. code:: python
78+
79+
sess = graphscope.session(k8s_volumes=k8s_volumes, k8s_service_type="LoadBalancer")
5880
5981
A :ref:`Session` tries to launch a coordinator,
6082
which is the entry for the back-end engines.
@@ -125,6 +147,14 @@ To load this graph to GraphScope, one may use the code below.
125147
}
126148
)
127149
150+
Alternatively, we provide a function to load this graph for convenience.
151+
152+
.. code:: python
153+
154+
from graphscope.dataset.ogbn_mag import load_ogbn_mag
155+
156+
g = load_ogbn_mag(sess, "/testingdata/ogbn_mag_small/")
157+
128158
Here, the ``g`` is loaded in parallel via vineyard and stored
129159
in vineyard instances in the cluster managed by the session.
130160
See more details in :ref:`Loading Graphs`

docs/installation.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ To run GraphScope on your local computer, the following dependencies or tools ar
1111

1212
- Docker
1313
- Python 3.8 (with pip)
14-
- Local Kubernetes cluster set-up tool (e.g. [Minikube](https://minikube.sigs.k8s.io) or [Kind](https://kind.sigs.k8s.io))
14+
- Local Kubernetes cluster set-up tool (e.g. [Kind](https://kind.sigs.k8s.io))
1515

16-
On Windows and macOS, you can follow the official guides to install them.
16+
On Windows and macOS, you can follow the official guides to install them and enable Kubernetes in Docker.
1717
For Ubuntu/CentOS Linux distributions, we provide a script to install the above
1818
dependencies and prepare the environment.
1919
Alternatively, you may want to install `WSL2 <https://docs.microsoft.com/zh-cn/windows/wsl/install-win10>`_ on Windows to use the script.

docs/zh/getting_started.rst

+24-3
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,29 @@
4444

4545
.. code:: python
4646
47+
import os
4748
import graphscope
48-
sess = graphscope.session()
49+
50+
# assume we mount `~/test_data` to `/testingdata` in pods.
51+
k8s_volumes = {
52+
"data": {
53+
"type": "hostPath",
54+
"field": {
55+
"path": os.path.expanduser("~/test_data/"),
56+
"type": "Directory"
57+
},
58+
"mounts": {
59+
"mountPath": "/testingdata"
60+
}
61+
}
62+
}
63+
64+
sess = graphscope.session(k8s_volumes=k8s_volumes)
65+
66+
对于 macOS,创建会话需要使用 LoadBalancer 服务类型(默认是 NodePort)。
67+
68+
.. code:: python
69+
sess = graphscope.session(k8s_volumes=k8s_volumes, k8s_service_type="LoadBalancer")
4970
5071
5172
会话(:ref:`Session`)的建立过程中,首选会在背后尝试拉起一个 `coordinator` 作为后端引擎的入口。
@@ -65,9 +86,9 @@ GraphScope 以属性图(property graph)建模图数据。属性图中,点
6586
:alt: a sample property graph.
6687

6788
该图具有四种顶点,分别标记为“论文”、“作者”、“机构”和“研究领域”。有四种连接它们的边,
68-
每种边都有一个标签,并且边的两端顶点的标签也是确定的。
89+
每种边都有一个标签,并且边的两端顶点的标签也是确定的。
6990
例如,“引用”这种标签的边连接两个“论文”顶点。另一个例子是标记为“撰写”的边,
70-
它要求该起始点的标记为“作者”,终止点的标记为“论文”。
91+
它要求该起始点的标记为“作者”,终止点的标记为“论文”。
7192
所有的顶点和边都可以具有属性。 例如,“论文”顶点具有诸如发布年份、主题标签等属性。
7293

7394

docs/zh/installation.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ GraphScope 被设计为运行在 Kubernetes 管理的群集上。
99

1010
- Docker
1111
- Python 3.8 (with pip)
12-
- Local Kubernetes cluster set-up tool (e.g. [Minikube](https://minikube.sigs.k8s.io) or [Kind](https://kind.sigs.k8s.io))
12+
- Local Kubernetes cluster set-up tool (e.g. [Kind](https://kind.sigs.k8s.io))
1313

14-
对于 Windows 和 MacOS 的用户,可通过官方文档来安装上述依赖。
14+
对于 Windows 和 MacOS 的用户,可通过官方文档来安装上述依赖, 并在Docker中开启Kubernetes功能
1515
对于Ubuntu/CentOS Linux 发行版用户,我们提供了脚本来准备运行时环境。
1616
您也可以在 Windows 上安装 `WSL2 <https://docs.microsoft.com/zh-cn/windows/wsl/install-win10>`_ 以使用脚本。
1717

scripts/prepare_env.sh

+18-38
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ function get_os_version() {
4242
elif [ -f /etc/centos-release ]; then
4343
# Older Red Hat, CentOS, etc.
4444
platform=CentOS
45-
os_version=$(cat /etc/centos-release | sed 's/.* \([0-9]\).*/\1/'))
45+
os_version=$(cat /etc/centos-release | sed 's/.* \([0-9]\).*/\1/')
4646
else
47-
# Fall back to uname, e.g. "Linux <version>", also works for BSD, etc.
47+
# Fall back to uname, e.g. "Linux <version>", also works for BSD, Darwin, etc.
4848
platform=$(uname -s)
4949
os_version=$(uname -r)
5050
fi
@@ -57,7 +57,7 @@ function check_os_compatibility() {
5757
fi
5858

5959
if [[ "${platform}" != *"Ubuntu"* && "${platform}" != *"CentOS"* ]]; then
60-
echo "This script is only available on Ubuntu/CentOS."
60+
echo "This script is only available on Ubuntu/CentOS"
6161
exit 1
6262
fi
6363

@@ -116,15 +116,9 @@ function install_dependencies() {
116116
chmod +x kubectl && sudo mv kubectl /usr/local/bin/ && sudo ln /usr/local/bin/kubectl /usr/bin/kubectl || true
117117
echo "$(date '+%Y-%m-%d %H:%M:%S') kubectl ${K8S_VERSION} installed."
118118

119-
if [[ "${is_in_wsl}" = false ]]; then
120-
curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 && \
121-
chmod +x minikube && sudo mv minikube /usr/local/bin/ && sudo ln /usr/local/bin/minikube /usr/bin/minikube || true
122-
echo "$(date '+%Y-%m-%d %H:%M:%S') minikube ${K8S_VERSION} installed."
123-
else
124-
curl -Lo kind https://kind.sigs.k8s.io/dl/v0.9.0/kind-linux-amd64 && \
125-
chmod +x kind && sudo mv kind /usr/local/bin/ && sudo ln /usr/local/bin/kind /usr/bin/kind || true
126-
echo "$(date '+%Y-%m-%d %H:%M:%S') kind v0.9.0 installed."
127-
fi
119+
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.10.0/kind-linux-amd64
120+
chmod +x kind && sudo mv kind /usr/local/bin/ && sudo ln /usr/local/bin/kind /usr/bin/kind || true
121+
echo "$(date '+%Y-%m-%d %H:%M:%S') kind v0.10.0 installed."
128122
}
129123

130124
function start_docker() {
@@ -142,24 +136,11 @@ function start_docker() {
142136

143137
function launch_k8s_cluster() {
144138
echo "$(date '+%Y-%m-%d %H:%M:%S') launching k8s cluster"
145-
if [[ "${is_in_wsl}" = false ]]; then
146-
export CHANGE_MINIKUBE_NONE_USER=true
147-
sudo sysctl fs.protected_regular=0 || true
148-
sudo minikube start --vm-driver=none --kubernetes-version="${K8S_VERSION}"
149-
150-
sudo cp -r /root/.kube /root/.minikube "${HOME}" || true
151-
sudo chown -R "$(id -u)":"$(id -g)" "${HOME}"/.minikube || true
152-
sudo chown -R "$(id -u)":"$(id -g)" "${HOME}"/.kube || true
153-
sed -i 's@/root@'"${HOME}"'@g' "${HOME}"/.kube/config || true
154-
minikube update-context
155-
else
156-
curl -Lo config-with-mounts.yaml https://kind.sigs.k8s.io/examples/config-with-mounts.yaml
157-
# mount $HOME dir to cluster container, which is kind-control-plane
158-
sed -i 's@/path/to/my/files/@'"${HOME}"'@g; s@/files@'"${HOME}"'@g' ./config-with-mounts.yaml || true
159-
sudo kind create cluster --config config-with-mounts.yaml
160-
sudo cp -r /root/.kube ${HOME} || true
161-
sudo chown -R "$(id -u)":"$(id -g)" "${HOME}"/.kube || true
162-
fi
139+
curl -Lo config-with-mounts.yaml https://kind.sigs.k8s.io/examples/config-with-mounts.yaml
140+
# mount $HOME dir to cluster container, which is kind-control-plane
141+
sed -i 's@/path/to/my/files/@'"${HOME}"'@g; s@/files@'"${HOME}"'@g' ./config-with-mounts.yaml || true
142+
sudo kind create cluster --config config-with-mounts.yaml
143+
sudo chown -R "$(id -u)":"$(id -g)" "${HOME}"/.kube || true
163144
echo "$(date '+%Y-%m-%d %H:%M:%S') cluster is lauched successfully."
164145
}
165146

@@ -171,14 +152,13 @@ function pull_images() {
171152
sudo docker pull quay.io/coreos/etcd:v3.4.13 || true
172153
echo "$(date '+%Y-%m-%d %H:%M:%S') images pulled successfully."
173154

174-
if [[ "${is_in_wsl}" = true ]]; then
175-
echo "$(date '+%Y-%m-%d %H:%M:%S') loading images into kind cluster."
176-
sudo kind load registry.cn-hongkong.aliyuncs.com/graphscope/graphscope:${version} || true
177-
sudo kind load registry.cn-hongkong.aliyuncs.com/graphscope/maxgraph_standalone_manager:${version} || true
178-
sudo kind load zookeeper:3.4.14 || true
179-
sudo kind load quay.io/coreos/etcd:v3.4.13 || true
180-
echo "$(date '+%Y-%m-%d %H:%M:%S') images loaded."
181-
fi
155+
echo "$(date '+%Y-%m-%d %H:%M:%S') loading images into kind cluster."
156+
sudo kind load docker-image registry.cn-hongkong.aliyuncs.com/graphscope/graphscope:${version} || true
157+
sudo kind load docker-image registry.cn-hongkong.aliyuncs.com/graphscope/maxgraph_standalone_manager:${version} || true
158+
sudo kind load docker-image zookeeper:3.4.14 || true
159+
sudo kind load docker-image quay.io/coreos/etcd:v3.4.13 || true
160+
echo "$(date '+%Y-%m-%d %H:%M:%S') images loaded."
161+
182162
}
183163

184164
if [ -f "${HOME}/.kube/config" ];

0 commit comments

Comments
 (0)