diff --git a/README.md b/README.md index 7c06276b..131625f6 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ qualified domain name) mode. ## Requirements * kubernetes 1.18+ -* golang 1.18+ +* golang 1.19+ ## Supported Features diff --git a/README_ZH-CN.md b/README_ZH-CN.md index b9e05a83..d968728e 100644 --- a/README_ZH-CN.md +++ b/README_ZH-CN.md @@ -9,7 +9,7 @@ ## 要求 * kubernetes 1.18+ -* golang 1.18+ +* golang 1.19+ ## 支持的功能 diff --git a/doc/cn/local_installation_how_to.md b/doc/cn/local_installation_how_to.md new file mode 100644 index 00000000..33f6028a --- /dev/null +++ b/doc/cn/local_installation_how_to.md @@ -0,0 +1,372 @@ +StarRocks 是一款高性能分析型数据仓库,使用向量化、MPP 架构、CBO、智能物化视图、可实时更新的列式存储引擎等技术实现多维、实时、高并发的数据分析。 + +本节将介绍: + +1. 如何在本地安装包含 1 个 FE、1 个 BE 和 1 个 FE Proxy 的 StarRocks。 +2. 如何将本地数据加载到 StarRocks。 + +> 我们假设你已经对 Kubernetes 有基本的了解。 + +下表列出了部署 StarRocks 的最小和推荐的硬件配置。 + +| 资源 | 最小值 | 推荐值 | +|-----|-------|-------| +| CPU | 4 CPU | 8 CPU | +| 内存 | 8 GB | 16 GB | +| 磁盘 | 40 GB | 80 GB | + +以下部分将涵盖: + +1. [前提条件](./local_installation_how_to.md#1-前提条件) - 安装 StarRocks 的前提条件。 +2. [手动从零开始安装](./local_installation_how_to.md#2-从零开始手动安装) - 从零开始使用 helm 安装 StarRocks。 +3. [通过脚本安装](./local_installation_how_to.md#3-通过脚本安装) - 使用脚本安装 StarRocks。 +4. [将数据加载到 StarRocks](./local_installation_how_to.md#4-将数据加载到-starrocks) - 将数据加载到 StarRocks。 +5. [卸载 StarRocks](./local_installation_how_to.md#5-卸载-starrocks) - 卸载 StarRocks。 + +## 1. 前提条件 + +为了安装 StarRocks,你需要满足以下前提条件: + +1. 安装 [docker](https://docs.docker.com/get-docker/) +2. 安装 [kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/) +3. 安装 [helm](https://helm.sh/) +4. 安装 [kind](https://kind.sigs.k8s.io/) + +> 你应该以具有 sudo 权限的用户身份登录,以安装上述工具。 + +### 1.1 安装 `docker` + +以下步骤将指导你安装 docker: + +以 **Ubuntu** 为例 + +```shell +# 查看 https://developer.aliyun.com/article/872508 了解如何安装 docker 的详细信息。 + +# 安装基本软件 +sudo apt-get update +sudo apt-get install apt-transport-https ca-certificates curl software-properties-common lrzsz -y + +# 使用阿里云的源 +sudo curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add - +sudo add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable" + +# 安装 docker +sudo apt-get update +sudo apt-get install docker-ce -y +``` + +> 更多信息请查看 https://docs.docker.com/desktop/install/linux-install/ . + +以**Mac**为例 + +下载并安装 [Docker Desktop for Mac](https://docs.docker.com/desktop/install/mac-install/)。 + +> 如果不允许安装 [Docker Desktop for Mac](https://docs.docker.com/desktop/install/mac-install/),你可以 +> 使用 [colima](https://github.com/abiosoft/colima) 作为另一个选项。 + +### 1.2 安装 `kubectl` + +以下步骤将指导你安装 kubectl: + +```shell +# 设置 URL +# 默认是官方的 URL 地址,如果你无法访问下面的 url,可以尝试使用下面的 url。 +# KUBECTL_URL="https://ydx-starrocks-public.oss-cn-hangzhou.aliyuncs.com" +KUBECTL_URL="https://dl.k8s.io/release/v1.28.3/bin" + +# 1. download kubectl +# Linux amd64 +curl -LO "$KUBECTL_URL/linux/amd64/kubectl" +# Linux arm64 +curl -LO "$KUBECTL_URL/linux/arm64/kubectl" +# MacOS amd64 +curl -LO "$KUBECTL_URL/darwin/amd64/kubectl" +# MacOS arm64 +curl -LO "$KUBECTL_URL/darwin/arm64/kubectl" + +# 2. install kubectl +chmod +x ./kubectl +sudo mv ./kubectl /usr/local/bin/kubectl + +# 3. check the version you installed +kubectl version --client +``` + +> 更多信息请查看:[install kubectl on linux](https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/) +> 或 [install kubectl on macos](https://kubernetes.io/docs/tasks/tools/install-kubectl-macos/)。 + +### 1.3 安装 `helm` + +以下步骤将指导你安装 helm: + +```shell +# 设置 URL +# 默认是官方的 URL 地址,如果你无法访问下面的 url,可以尝试使用下面的 url。 +# HELM_URL="https://ydx-starrocks-public.oss-cn-hangzhou.aliyuncs.com" +HELM_URL="https://get.helm.sh" + +# 1. download helm +# Linux amd64 +curl -LO $HELM_URL/helm-v3.12.3-linux-amd64.tar.gz +# Linux arm64 +curl -LO $HELM_URL/helm-v3.12.3-linux-arm64.tar.gz +# MacOS amd64 +curl -LO $HELM_URL/helm-v3.12.3-darwin-amd64.tar.gz +# MacOS arm64 +curl -LO $HELM_URL/helm-v3.12.3-darwin-arm64.tar.gz + +# 2. install helm +# e.g. Linux arm64 +tar -zxvf helm-v3.12.3-linux-amd64.tar.gz +sudo mv linux-amd64/helm /usr/local/bin/helm + +# 3. check the version you installed +helm version +``` + +### 1.4 安装 `kind` + +以下步骤将指导你安装 kind: + +```shell +# 设置 URL +# 默认是官方的 URL 地址,如果你无法访问下面的 url,可以尝试使用下面的 url。 +# KIND_URL="https://ydx-starrocks-public.oss-cn-hangzhou.aliyuncs.com" +KIND_URL="https://kind.sigs.k8s.io/dl/v0.20.0" + +# Linux AMD64 / x86_64 +curl -Lo ./kind $KIND_URL/kind-linux-amd64 +# Linux ARM64 +curl -Lo ./kind $KIND_URL/kind-linux-arm64 +# Linux Intel Macs +curl -Lo ./kind $KIND_URL/kind-darwin-amd64 +# Linux M1 / ARM Macs +curl -Lo ./kind $KIND_URL/kind-darwin-arm64 + +# install kind +chmod +x ./kind +sudo mv ./kind /usr/local/bin/kind + +# check the version you installed +kind version +``` + +## 2. 从零开始手动安装 + +### 2.1 通过 Kind 安装 Kubernetes 集群 + +在安装了上述工具后,你可以使用以下步骤手动安装 StarRocks。 + +```bash +# prepare a kind configuration file `kind.yaml`: +# 为 `kind` 集群设置端口映射,这样你就可以从 kubernetes 集群外部访问 `StarRocks` 集群了。 +cat < kind.yaml +kind: Cluster +apiVersion: kind.x-k8s.io/v1alpha4 +nodes: +- role: control-plane + extraPortMappings: + - containerPort: 30001 + hostPort: 30001 + listenAddress: "0.0.0.0" + protocol: TCP + - containerPort: 30002 + hostPort: 30002 + listenAddress: "0.0.0.0" + protocol: TCP +EOF + +# kubernetes installation +unset http_proxy +unset https_proxy +# 你可能需要 sudo 权限来执行 kind create cluster 命令 +sudo kind create cluster --image=kindest/node:v1.23.4 --name=starrocks --config=kind.yaml + +# 你可能需要 sudo 权限来执行kubectl命令 +# waiting for the new kubernetes cluster to be running healthily +sudo kubectl get pods -A +NAMESPACE NAME READY STATUS RESTARTS AGE +kube-system coredns-64897985d-brlj9 1/1 Running 0 4m26s +kube-system coredns-64897985d-m9kj6 1/1 Running 0 4m26s +kube-system etcd-starrocks-control-plane 1/1 Running 0 4m39s +kube-system kindnet-jsrg8 1/1 Running 0 4m26s +kube-system kube-apiserver-starrocks-control-plane 1/1 Running 0 4m39s +kube-system kube-controller-manager-starrocks-control-plane 1/1 Running 0 4m39s +kube-system kube-proxy-8h6b4 1/1 Running 0 4m26s +kube-system kube-scheduler-starrocks-control-plane 1/1 Running 0 4m39s +local-path-storage local-path-provisioner-5ddd94ff66-9l2km 1/1 Running 0 4m26s +``` + +### 2.2 通过 Helm 安装 StarRocks + +你可以在 https://github.com/StarRocks/starrocks-kubernetes-operator/releases 获取 StarRocks Helm Chart 的最新版本。 + +```shell +# Add the Helm Chart Repo +helm repo add starrocks-community https://starrocks.github.io/starrocks-kubernetes-operator + +# update the repo +helm repo update starrocks-community + +# View the Helm Chart Repo that you added. +# There are three charts in the repo, and kube-starrocks will be used to install StarRocks Operator and StarRocks cluster. +helm search repo starrocks-community +``` + +这里有 [kube-starrocks](../../helm-charts/charts/kube-starrocks/README.md) Helm Chart 的更多信息。 + +Prepare a `values.yaml` file to install, and you can refer +to [values.yaml](../../helm-charts/charts/kube-starrocks/values.yaml) to see the default values. + +```shell +cat <values.yaml +operator: + starrocksOperator: + image: + repository: starrocks/operator + tag: v1.8.6 + +starrocks: + starrocksFESpec: + image: + repository: starrocks/fe-ubuntu + tag: 3.1.2 + resources: + limits: + cpu: 2 + memory: 4Gi + requests: + cpu: 500m + memory: 1Gi + service: + type: NodePort + ports: + - containerPort: 9030 + name: query + nodePort: 30002 + port: 9030 + starrocksBeSpec: + image: + repository: starrocks/be-ubuntu + tag: 3.1.2 + resources: + limits: + cpu: 2 + memory: 4Gi + requests: + cpu: 500m + memory: 1Gi + starrocksFeProxySpec: + enabled: true + resources: + requests: + cpu: 100m + memory: 200Mi + service: + type: NodePort + ports: + - name: http-port + nodePort: 30001 + containerPort: 8080 + port: 8080 +EOF + +# install starrocks +# 如果你因为网络问题无法安装,可参见后面的操作 +helm install -n starrocks starrocks -f values.yaml starrocks-community/kube-starrocks --create-namespace + +############## 如果你因为网络问题无法直接安装(helm instal),可以先下载再安装 ############## +# 如果无法下载可以使用下面的 URL +# HELM_CHART_URL="https://ydx-starrocks-public.oss-cn-hangzhou.aliyuncs.com" +HELM_CHART_URL="https://github.com/StarRocks/starrocks-kubernetes-operator/releases/download/v1.8.6" +curl -LO "$HELM_CHART_URL/kube-starrocks-1.8.6.tgz" + +helm install -n starrocks starrocks -f values.yaml ./kube-starrocks-1.8.6.tgz --create-namespace +############################################################# + +# set alias for kubectl +alias k='kubectl -n starrocks' + +# waiting for the starrocks cluster to be running healthily +ubuntu@vm:~$ k get pods +NAME READY STATUS RESTARTS AGE +kube-starrocks-be-0 1/1 Running 0 2m +kube-starrocks-fe-0 1/1 Running 0 3m +kube-starrocks-fe-proxy-5c7c7fc7b-wwvs6 1/1 Running 0 3m +kube-starrocks-operator-7498c7fbd-qsbgb 1/1 Running 0 3m +``` + +## 3. 通过脚本安装 + +请确保 `docker` 已经安装,更多信息请查看 [install docker](./local_installation_how_to.md#11-安装-docker)。 + +默认情况下,[script](../../scripts/local-install.sh) 将会做以下事情: + +1. 在你的机器上安装 kubectl、helm、kind。 +2. 创建一个名为 `starrocks` 的 kind 集群。 +3. 通过 [kube-starrocks](../../helm-charts/charts/kube-starrocks/README.md) chart 安装 starrocks。 + +执行下面的命令: + +```shell +sudo bash local-install.sh --helm-url https://ydx-starrocks-public.oss-cn-hangzhou.aliyuncs.com --kind-url https://ydx-starrocks-public.oss-cn-hangzhou.aliyuncs.com --kubectl-url https://ydx-starrocks-public.oss-cn-hangzhou.aliyuncs.com --helm-chart-url https://ydx-starrocks-public.oss-cn-hangzhou.aliyuncs.com/kube-starrocks-1.8.6.tgz +``` + +## 4. 将数据加载到 StarRocks + +在 starrocks 集群运行正常后,你可以将数据加载到 starrocks。 + +```shell +# set alias for kubectl +alias k='kubectl -n starrocks' + +# get the pod ip of kube-starrocks-fe-0 +IP=$(k get pod kube-starrocks-fe-0 --template '{{.status.podIP}}') + +# login to kube-starrocks-fe-0 +k exec -it kube-starrocks-fe-0 -- env IP=$IP bash + +# create database and table +mysql -h $IP -P 9030 -uroot + +create database test_db; +use test_db; +CREATE TABLE `table1` +( + `id` int(11) NOT NULL COMMENT "用户 ID", + `name` varchar(65533) NULL COMMENT "用户姓名", + `score` int(11) NOT NULL COMMENT "用户得分" +) +ENGINE=OLAP +PRIMARY KEY(`id`) +DISTRIBUTED BY HASH(`id`) +PROPERTIES ("replication_num" = "1"); + +# Note: back to your host, not FE +# create csv file +cat < example1.csv +1,Lily,23 +2,Rose,23 +3,Alice,24 +4,Julia,25 +EOF + +# load data to starrocks +curl --location-trusted -u root:"" -H "label:123" \ + -H "Expect:100-continue" \ + -H "column_separator:," \ + -H "columns: id, name, score" \ + -T example1.csv -XPUT \ + http://localhost:30001/api/test_db/table1/_stream_load +``` + +## 5. 卸载 StarRocks + +```shell +# uninstall starrocks +helm uninstall starrocks -n starrocks + +# uninstall kubernetes cluster +kind delete cluster --name starrocks +``` diff --git a/doc/local_installation_how_to.md b/doc/local_installation_how_to.md index e36a0743..a8d88e6a 100644 --- a/doc/local_installation_how_to.md +++ b/doc/local_installation_how_to.md @@ -16,9 +16,9 @@ The following table lists the minimum and recommended hardware configurations fo The following section will cover: -1. [Prerequisites](#1-prerequisites) - The prerequisites for installing StarRocks. -2. [Installation from scratch manually](#2-installation-from-scratch-manually) - Install StarRocks with helm from - scratch. +1. [Prerequisites](./local_installation_how_to.md#1-prerequisites) - The prerequisites for installing StarRocks. +2. [Installation from scratch manually](./local_installation_how_to.md#2-installation-from-scratch-manually) - Install + StarRocks with helm from scratch. 3. [Installation by scripts](./local_installation_how_to.md#3-installation-by-script) - Install StarRocks with scripts. 4. [Load data to StarRocks](./local_installation_how_to.md#4-load-data-to-starrocks) - Load data to StarRocks. 5. [Uninstall StarRocks](./local_installation_how_to.md#5-uninstall-starrocks) - Uninstall StarRocks. @@ -27,14 +27,47 @@ The following section will cover: In order to install StarRocks, you need to have the following prerequisites: -1. Install [kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/) command-line tool. -2. Install [helm](https://helm.sh/) command-line tool. -3. Install [docker](https://docs.docker.com/get-docker/) command-line tool. +1. Install [docker](https://docs.docker.com/get-docker/) command-line tool. +2. Install [kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/) command-line tool. +3. Install [helm](https://helm.sh/) command-line tool. 4. Install [kind](https://kind.sigs.k8s.io/) command-line tool. > You should be logged in as a user with sudo privileges to install the above tools. +> The following steps will assume you are using a Linux or Mac machine with root privileges. -### 1.1 Install `kubectl` +### 1.1 Install `docker` + +The following steps will guide you to install docker: + +**Linux** + +```shell +# update your package manager +sudo apt-get update + +# you can use it to get the latest docker package +curl -fsSL https://get.docker.com/ | sh + +# Add your account to the docker group. +# NOTE: You will have to log out and log back in for the change to take effect. +sudo usermod -aG docker $USER + +# Verify that Docker is installed by running the hello-world container +docker run hello-world +``` + +> see https://docs.docker.com/desktop/install/linux-install/ for more details. + +**Mac** + +Download and install [Docker Desktop for Mac](https://docs.docker.com/desktop/install/mac-install/). After the +installation is complete, the Docker icon will be displayed in the menu bar. + +> If installing [Docker Desktop for Mac](https://docs.docker.com/desktop/install/mac-install/) is not allowed, you can +> use +[colima](https://github.com/abiosoft/colima) as another option. + +### 1.2 Install `kubectl` The following steps will guide you to install kubectl: @@ -52,7 +85,6 @@ curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stabl # 2. install kubectl chmod +x ./kubectl sudo mv ./kubectl /usr/local/bin/kubectl -sudo chown root: /usr/local/bin/kubectl # 3. check the version you installed kubectl version --client @@ -61,7 +93,7 @@ kubectl version --client > see [install kubectl on linux](https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/) > or [install kubectl on macos](https://kubernetes.io/docs/tasks/tools/install-kubectl-macos/) for more details. -### 1.2 Install `helm` +### 1.3 Install `helm` The following steps will guide you to install helm: @@ -78,8 +110,8 @@ curl -LO https://get.helm.sh/helm-v3.12.3-darwin-arm64.tar.gz # 2. install helm # e.g. Linux arm64 -tar -zxvf helm-v3.12.3-linux-arm64.tar.gz -sudo mv linux-arm64/helm /usr/local/bin/helm +tar -zxvf helm-v3.12.3-linux-amd64.tar.gz +sudo mv linux-amd64/helm /usr/local/bin/helm # 3. check the version you installed helm version @@ -87,38 +119,6 @@ helm version > see https://helm.sh/docs/intro/install/ for more details. -### 1.3 Install `docker` - -The following steps will guide you to install docker: - -**Linux** - -```shell -# update your package manager -sudo apt-get update - -# you can use it to get the latest docker package -curl -fsSL https://get.docker.com/ | sh - -# Add your account to the docker group. -# NOTE: You will have to log out and log back in for the change to take effect. -sudo usermod -aG docker $USER - -# Verify that Docker is installed by running the hello-world container -docker run hello-world -``` - -> see https://docs.docker.com/desktop/install/linux-install/ for more details. - -**Mac** - -Download and install [Docker Desktop for Mac](https://docs.docker.com/desktop/install/mac-install/). After the -installation is complete, the Docker icon will be displayed in the menu bar. - -> If installing [Docker Desktop for Mac](https://docs.docker.com/desktop/install/mac-install/) is not allowed, you can -> use -[colima](https://github.com/abiosoft/colima) as another option. - ### 1.4 Install `kind` The following steps will guide you to install `kind`: @@ -169,7 +169,7 @@ EOF # kubernetes installation unset http_proxy unset https_proxy -kind create cluster --image=kindest/node:v1.23.4 --name=starrocks --config=kind.yaml +sudo kind create cluster --image=kindest/node:v1.23.4 --name=starrocks --config=kind.yaml # waiting for the new kubernetes cluster to be running healthily ``` @@ -269,7 +269,7 @@ kube-starrocks-operator-7498c7fbd-qsbgb 1/1 Running 0 3m ## 3. Installation by script -Make sure `docker` is installed,See [install docker](#13-install-docker) for more details. +Make sure `docker` is installed,See [install docker](./local_installation_how_to.md#11-install-docker) for more details. By default, the [script](../scripts/local-install.sh) will do the following things: @@ -297,9 +297,9 @@ create database test_db; use test_db; CREATE TABLE `table1` ( - `id` int(11) NOT NULL COMMENT "用户 ID", - `name` varchar(65533) NULL COMMENT "用户姓名", - `score` int(11) NOT NULL COMMENT "用户得分" + `id` int(11) NOT NULL COMMENT "user id", + `name` varchar(65533) NULL COMMENT "user name", + `score` int(11) NOT NULL COMMENT "user score" ) ENGINE=OLAP PRIMARY KEY(`id`) diff --git a/scripts/local-install.sh b/scripts/local-install.sh index 47ec4c92..de735722 100644 --- a/scripts/local-install.sh +++ b/scripts/local-install.sh @@ -1,20 +1,30 @@ #!/usr/bin/env bash -VERSION= +# This script is used to install starrocks on local k8s cluster. +# Make sure `docker` is installed,See [install docker](https://github.com/StarRocks/starrocks-kubernetes-operator/blob/main/doc/local_installation_how_to.md#11-install-docker) for more details. +# +# It will do the following things: +# 1. install kubectl, helm, kind on your machine. +# 2. create a kind cluster named `starrocks`. +# 3. install [kube-starrocks](https://github.com/StarRocks/starrocks-kubernetes-operator/tree/main/helm-charts/charts/kube-starrocks) helm chart. + +# specify the k8s version installed by kind K8S_VERSION="v1.23.4" -UPGRADE=false -CLEAN=false -KIND=true - -# Pre-requisites: -# - kubectl -# - helm -# - docker -# - kind - -# Check if the binary is installed -# If not, return false, else return true +# helm, kind, kubectl download url +HELM_URL="https://get.helm.sh" +KIND_URL="https://kind.sigs.k8s.io/dl/v0.20.0" +KUBECTL_URL="https://dl.k8s.io/release/v1.28.3/bin" +HELM_CHART_URL="https://github.com/StarRocks/starrocks-kubernetes-operator/releases/download/v1.8.6/kube-starrocks-1.8.6.tgz" +# NOTE: +# if you can not access the following url, you can try to use the following url. +# And you can specify the url by command arguments. +# HELM_URL="https://ydx-starrocks-public.oss-cn-hangzhou.aliyuncs.com" +# KIND_URL="https://ydx-starrocks-public.oss-cn-hangzhou.aliyuncs.com" +# KUBECTL_URL="https://ydx-starrocks-public.oss-cn-hangzhou.aliyuncs.com" +# HELM_CHART_URL="https://ydx-starrocks-public.oss-cn-hangzhou.aliyuncs.com/kube-starrocks-1.8.6.tgz" + +# checkBinary checks if the binary is installed. If not, return 1, else return 0 function checkBinary() { if command -v "$1" &>/dev/null; then echo "The binary $1 is installed" @@ -25,6 +35,7 @@ function checkBinary() { fi } +# mustInstalled checks if the binary is installed. If not, exit function mustInstalled() { if ! command -v "$1" &>/dev/null; then echo "The binary $1 is not installed" @@ -34,77 +45,80 @@ function mustInstalled() { fi } +# installHelm installs helm function installHelm() { echo "installing helm" # Linux AMD64 / x86_64 [[ $(uname -m) = x86_64 && $(uname) = Linux ]] && - curl -LO https://get.helm.sh/helm-v3.12.3-linux-amd64.tar.gz && + curl -LO $HELM_URL/helm-v3.12.3-linux-amd64.tar.gz && tar -zxvf helm-v3.12.3-linux-amd64.tar.gz && sudo mv linux-amd64/helm /usr/local/bin/helm # Linux ARM64 [[ $(uname -m) = aarch64 && $(uname) = Linux ]] && - curl -LO https://get.helm.sh/helm-v3.12.3-linux-arm64.tar.gz && + curl -LO $HELM_URL/helm-v3.12.3-linux-arm64.tar.gz && tar -zxvf helm-v3.12.3-linux-arm64.tar.gz && sudo mv linux-arm64/helm /usr/local/bin/helm # MacOS Intel [[ $(uname -m) = x86_64 && $(uname) = Darwin ]] && - curl -LO https://get.helm.sh/helm-v3.12.3-darwin-amd64.tar.gz && + curl -LO $HELM_URL/helm-v3.12.3-darwin-amd64.tar.gz && tar -zxvf helm-v3.12.3-darwin-amd64.tar.gz && sudo mv darwin-amd64/helm /usr/local/bin/helm # MacOS M1 / ARM [[ $(uname -m) = arm64 && $(uname) = Darwin ]] && - curl -LO https://get.helm.sh/helm-v3.12.3-darwin-arm64.tar.gz && + curl -LO $HELM_URL/helm-v3.12.3-darwin-arm64.tar.gz && tar -zxvf helm-v3.12.3-darwin-arm64.tar.gz && sudo mv darwin-arm64/helm /usr/local/bin/helm } +# installKubectl installs kubectl function installKubectl() { echo "Installing kubectl" # Linux AMD64 / x86_64 [[ $(uname -m) = x86_64 && $(uname) = Linux ]] && - curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" + curl -LO "$KUBECTL_URL/linux/amd64/kubectl" # Linux ARM64 [[ $(uname -m) = aarch64 && $(uname) = Linux ]] && - curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/arm64/kubectl" + curl -LO "$KUBECTL_URL/linux/arm64/kubectl" # MacOS Intel Macs [[ $(uname -m) = x86_64 && $(uname) = Darwin ]] && - curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/amd64/kubectl" + curl -LO "$KUBECTL_URL/darwin/amd64/kubectl" # MacOS M1 / ARM [[ $(uname -m) = arm64 && $(uname) = Darwin ]] && - curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/arm64/kubectl" + curl -LO "$KUBECTL_URL/darwin/arm64/kubectl" chmod +x ./kubectl sudo mv ./kubectl /usr/local/bin/kubectl - sudo chown root: /usr/local/bin/kubectl } +# installKind installs kind function installKind() { echo "Installing kind" # Linux AMD64 / x86_64 [[ $(uname -m) = x86_64 && $(uname) = Linux ]] && - curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.20.0/kind-linux-amd64 + curl -Lo ./kind $KIND_URL/kind-linux-amd64 # Linux ARM64 [[ $(uname -m) = aarch64 && $(uname) = Linux ]] && - curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.20.0/kind-linux-arm64 + curl -Lo ./kind $KIND_URL/kind-linux-arm64 # MacOS Intel [[ $(uname -m) = x86_64 && $(uname) = Darwin ]] && - curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.20.0/kind-darwin-amd64 + curl -Lo ./kind $KIND_URL/kind-darwin-amd64 # MacOS M1 / ARM [[ $(uname -m) = arm64 && $(uname) = Darwin ]] && - curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.20.0/kind-darwin-arm64 + curl -Lo ./kind $KIND_URL/kind-darwin-arm64 # install kind chmod +x ./kind sudo mv ./kind /usr/local/bin/kind } +# checkPrerequisites checks if the prerequisites are installed. If not, install them function checkPrerequisites() { mustInstalled docker # If kind is not installed, install kind - if $KIND && ! checkBinary kind; then + if ! checkBinary kind; then installKind fi @@ -119,15 +133,15 @@ function checkPrerequisites() { fi } +# cmdHelp prints the help message function cmdHelp() { echo "Usage: $0 [options]" echo "Options:" - echo " --clean" echo " -h, --help" echo " -k, --k8s-version , specify the version of k8s to install, default is $K8S_VERSION" - echo " -u, --upgrade, equals to helm upgrade" } +# kindCreateCluster creates a kind cluster function kindCreateCluster() { echo "Creating kind cluster" @@ -148,38 +162,12 @@ nodes: kind create cluster --image=kindest/node:$K8S_VERSION --name=starrocks --config=/tmp/kind.yaml || exit 1 } +# install installs kube-starrocks helm chart function install() { + echo "Installing kube-starrocks helm chart" helm repo add starrocks-community https://starrocks.github.io/starrocks-kubernetes-operator - - echo "Update helm repo" helm repo update starrocks-community - cmd="helm" - - if $UPGRADE; then - cmd="$cmd upgrade" - else - cmd="$cmd install" - fi - - cmd="$cmd -n starrocks starrocks starrocks-community/kube-starrocks" - - if [ -n "$VERSION" ]; then - cmd="$cmd --version $VERSION" - fi - - if $UPGRADE; then - cmd="$cmd --timeout 30s" - else - cmd="$cmd --create-namespace --timeout 60s" - fi - - if $UPGRADE; then - echo "Upgrading starrocks" - else - echo "Installing starrocks" - fi - cat </tmp/local-install-values.yaml operator: starrocksOperator: @@ -197,8 +185,8 @@ starrocks: cpu: 2 memory: 4Gi requests: - cpu: 500m - memory: 1Gi + cpu: 100m + memory: 200Mi service: type: NodePort ports: @@ -215,8 +203,8 @@ starrocks: cpu: 2 memory: 4Gi requests: - cpu: 500m - memory: 1Gi + cpu: 100m + memory: 200Mi starrocksFeProxySpec: enabled: true resources: @@ -232,14 +220,11 @@ starrocks: port: 8080 EOF + cmd="helm install -n starrocks starrocks $HELM_CHART_URL --create-namespace --timeout 60s" eval "$cmd -f /tmp/local-install-values.yaml" 1>/dev/null } -function clean() { - echo "Cleaning kind cluster" - kind delete cluster --name starrocks -} - +# parseInput parses the input parameters function parseInput() { while [ $# -gt 0 ]; do case $1 in @@ -247,21 +232,25 @@ function parseInput() { cmdHelp exit ;; - -u | --upgrade) - UPGRADE=true - shift + -k | --k8s-version) + K8S_VERSION=$2 + shift 2 ;; - -v | --version) - VERSION=$2 + --helm-url) + HELM_URL=$2 shift 2 ;; - -k | --k8s-version) - K8S_VERSION=$2 + --kind-url) + KIND_URL=$2 shift 2 ;; - --clean) - CLEAN=true - shift + --kubectl-url) + KUBECTL_URL=$2 + shift 2 + ;; + --helm-chart-url) + HELM_CHART_URL=$2 + shift 2 ;; *) echo "Invalid option $1" @@ -271,18 +260,8 @@ function parseInput() { esac done - if $CLEAN; then - clean - exit - fi - - if $UPGRADE; then - install && echo 'StarRocks is installed successfully!' || echo 'StarRocks is installed failed!' - exit - fi - checkPrerequisites - (kind get clusters | grep starrocks) || kindCreateCluster + (sudo kind get clusters | grep starrocks) || kindCreateCluster install && echo 'StarRocks is installed successfully!' || echo 'StarRocks is installed failed!' }