Skip to content

Commit

Permalink
[type:feat] complete h2 and mysql (#9)
Browse files Browse the repository at this point in the history
* ci: make release ci work

Signed-off-by: Bird <aflybird0@gmail.com>

* feat: update chart template to complete h2

Signed-off-by: Bird <aflybird0@gmail.com>

* feat: support mysql as data source

Signed-off-by: Bird <aflybird0@gmail.com>

* feat: remove pv and classStorage

Signed-off-by: Bird <aflybird0@gmail.com>

* fix: pvc name error

Signed-off-by: Bird <aflybird0@gmail.com>

* fix: configMap name error

Signed-off-by: Bird <aflybird0@gmail.com>

* fix: svc url error

Signed-off-by: Bird <aflybird0@gmail.com>

* fix: endpoints name error

Signed-off-by: Bird <aflybird0@gmail.com>

* feat: support separate installation of admin and bootstrap

Signed-off-by: Bird <aflybird0@gmail.com>

* doc: update README

Signed-off-by: Bird <aflybird0@gmail.com>

* feat: update datasource config

Signed-off-by: Bird <aflybird0@gmail.com>

* ci: switch into prod env

Signed-off-by: Bird <aflybird0@gmail.com>

* doc: update README

Signed-off-by: Bird <aflybird0@gmail.com>

* doc: update README

Signed-off-by: Bird <aflybird0@gmail.com>

* chore: reset chart version

Signed-off-by: Bird <aflybird0@gmail.com>

Signed-off-by: Bird <aflybird0@gmail.com>
  • Loading branch information
aFlyBird0 authored Aug 17, 2022
1 parent 4d81a0b commit 0dbc3e6
Show file tree
Hide file tree
Showing 19 changed files with 470 additions and 125 deletions.
1 change: 1 addition & 0 deletions .github/actions/chart-releaser-action
Submodule chart-releaser-action added at 6d70e8
3 changes: 0 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ name: Lint and Test Charts

on:
pull_request:
push:
branches:
- main

jobs:
lint-test:
Expand Down
13 changes: 7 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Release Charts
on:
push:
branches:
- "**-release"
- main

jobs:
release:
Expand All @@ -12,21 +12,22 @@ jobs:
- name: Checkout
uses: actions/checkout@v2
with:
submodules: recursive
# ct needs history to compare
fetch-depth: 0

- name: Configure Git
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
- name: Install Helm
uses: azure/setup-helm@v1
with:
version: v3.4.1
version: v3.8.1

- name: Run chart-releaser
uses: helm/chart-releaser-action@v1.1.0
with:
charts_dir: charts
uses: ./.github/actions/chart-releaser-action
env:
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
CR_SKIP_EXISTING: true
CR_SKIP_EXISTING: true
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule ".github/actions/kind-action"]
path = .github/actions/kind-action
url = https://github.com/helm/kind-action.git
[submodule ".github/actions/chart-releaser-action"]
path = .github/actions/chart-releaser-action
url = https://github.com/helm/chart-releaser-action.git
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# shenyu-helm-chart
# shenyu-helm-chart

See [here](./charts/shenyu/README.md) for more information.
6 changes: 4 additions & 2 deletions charts/shenyu/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ apiVersion: v2
name: shenyu
description: Helm Chart for deploying Apache ShenYu in Kubernetes
type: application
version: 2.4.3
appVersion: "1.16.0"
version: 0.1.0
appVersion: "2.4.3"
icon: https://shenyu.apache.org/img/logo.png
maintainers:
- name: erdengk
- name: aFlyBird0
email: aflybird0@gmail.com
138 changes: 137 additions & 1 deletion charts/shenyu/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,139 @@
# shenyu-helm-chart

Helm deployment documentation written for Apache/Shenyu
Helm deployment documentation written for Apache/Shenyu.

[English] [[简体中文]](#使用Helm安装ShenYu)

[Apache/ShenYu](https://shenyu.apache.org/docs/index/) is an asynchronous, high-performance, cross-language, responsive API gateway.

## Get Repo Info

```shell
helm repo add shenyu https://apache.github.io/shenyu-helm-chart
helm repo update
```

_See [helm repo](https://helm.sh/docs/helm/helm_repo/) for command documentation._

todo: complete English version

---

## 使用Helm安装ShenYu
[[English]](#shenyu-helm-chart) [简体中文]

[Apache/ShenYu](https://shenyu.apache.org/zh/docs/index) 是一个异步的,高性能的,跨语言的,响应式的 API 网关。

## 添加 Helm 仓库

```shell
helm repo add shenyu https://apache.github.io/shenyu-helm-chart
helm repo update
```

## 安装
* helm 安装方式目前支持 h2 与 MySQL 两种数据库。默认使用 h2。
* 默认同时安装 admin 与 bootstrap。
* 使用 NodePort 暴露服务,admin 默认端口为 31095, bootstrap 为 31195。

### h2 作为数据库

运行以下命令,会在 shenyu namespace 下安装 admin 与 bootstrap ,并创建命名空间。

```shell
helm install shenyu shenyu/shenyu -n=shenyu --create-namespace
```

### MySQL 作为数据库

MySQL 安装方式需要提前安装好 MySQ,并提前创建好 pv 以存放 connector。详见 [部署先决条件](https://shenyu.apache.org/zh/docs/deployment/deployment-before/)

#### 1. 提前创建 pv

可复制以下 yaml,至少**替换以下两处内容**

* `YOUR_K8S_NODE_NAME`:存放 MySQL connector 的 K8s 节点名称
* `YOUR_PATH_TO_STORE_MYSQL_CONNECTOR`:# 指定节点上的目录, 该目录下面需要包含 mysql-connector.jar

```shell
apiVersion: v1
kind: PersistentVolume
metadata:
name: shenyu-pv
spec:
capacity:
storage: 1Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Delete
storageClassName: shenyu-local-storage
local:
path: YOUR_PATH_TO_STORE_MYSQL_CONNECTOR
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- YOUR_K8S_NODE_NAME
---
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: shenyu-local-storage
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer
```

修改并保存为 `shenyu-store.yaml`, 然后执行:

```shell
kubectl apply -f shenyu-store.yaml -n=shenyu
```

#### 2. 安装

修改以下命令并复制,执行:

其中,storageClass 和上面的 yaml 创建的 StorageClass 的 name 对应。

```shell
helm install shenyu shenyu/shenyu -n=shenyu --create-namespace \
--set dataSource.active=mysql \
--set dataSource.mysql.ip=127.0.0.1 \
--set dataSource.mysql.port=3306 \
--set dataSource.mysql.password=123456 \
--set dataSource.mysql.storageClass=shenyu-local-storage
```

## Q&A

### 1. 如果只安装 admin 或 bootstrap

* 只安装 admin: 在 helm 安装命令末尾加上 `--set bootstrap.enabled=false`
* 只安装 bootstrap: 在 helm 安装命令末尾加上 `--set admin.enabled=false`

### 2. 如何安装旧版本 ShenYu

```shell
helm search repo shenyu -l
```

你会得到类似的输出:

```shell
NAME CHART VERSION APP VERSION DESCRIPTION
shenyu/shenyu 2.4.3 2.4.3 Helm Chart for deploying Apache ShenYu in Kuber...
...
...
```
其中 APP_VERSION 是 ShenYu 的版本,CHART_VERSION 是 helm chart 的版本。
根据要安装的 ShenYu 版本来选择对应的 Chart 版本,在命令末尾加上 `--version=CHART_VERSION` 参数即可。例如:
```shell
helm install shenyu shenyu/shenyu -n=shenyu --version=2.4.3 --create-namespace
```
118 changes: 76 additions & 42 deletions charts/shenyu/templates/ConfigMap.yaml
Original file line number Diff line number Diff line change
@@ -1,52 +1,86 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: shenyu-cm
namespace: default
namespace: {{.Release.Namespace}}
name: {{ template "shenyu.fullname" . }}-configmap
labels:
"app.kubernetes.io/name": '{{ template "shenyu.name" . }}'
"app.kubernetes.io/managed-by": "{{ .Release.Service }}"
"app.kubernetes.io/component": "shenyu-configmap"
"app.kubernetes.io/instance": "{{ .Release.Name }}"
data:
application-local.yml: |
server:
port: 9195
address: 0.0.0.0
port: 9195
address: 0.0.0.0
spring:
main:
allow-bean-definition-overriding: true
application:
name: shenyu-bootstrap
profiles:
active: {{ .Values.dataSource.active }}
main:
allow-bean-definition-overriding: true
application:
name: shenyu-bootstrap
management:
health:
defaults:
enabled: false
health:
defaults:
enabled: false
shenyu:
local:
enabled: true
file:
enabled: true
cross:
enabled: true
dubbo:
parameter: multi
sync:
websocket:
urls: ws://shenyu-admin-svc.shenyu.svc.cluster.local:9095/websocket
exclude:
enabled: false
paths:
- /favicon.ico
extPlugin:
enabled: true
threads: 1
scheduleTime: 300
scheduleDelay: 30
scheduler:
enabled: false
type: fixed
threads: 16
local:
enabled: true
file:
enabled: true
cross:
enabled: true
dubbo:
parameter: multi
sync:
websocket:
urls: ws://{{ template "shenyu.fullname" . }}-admin.shenyu.svc.cluster.local:9095/websocket
exclude:
enabled: false
paths:
- /favicon.ico
extPlugin:
enabled: true
threads: 1
scheduleTime: 300
scheduleDelay: 30
scheduler:
enabled: false
type: fixed
threads: 16
logging:
level:
root: info
org.springframework.boot: info
org.apache.ibatis: info
org.apache.shenyu.bonuspoint: info
org.apache.shenyu.lottery: info
org.apache.shenyu: info
level:
root: info
org.springframework.boot: info
org.apache.ibatis: info
org.apache.shenyu.bonuspoint: info
org.apache.shenyu.lottery: info
org.apache.shenyu: info
{{- if eq .Values.dataSource.active "h2" }}
application-h2.yml: |
shenyu:
database:
dialect: h2
init_script: "sql-script/h2/schema.sql"
init_enable: {{ .Values.dataSource.initEnabled }}
spring:
datasource:
url: jdbc:h2:mem:~/shenyu;DB_CLOSE_DELAY=-1;MODE=MySQL;
username: {{ .Values.dataSource.h2.username }}
password: {{ .Values.dataSource.h2.password }}
driver-class-name: org.h2.Driver
{{- end }}
{{- if eq .Values.dataSource.active "mysql" }}
application-mysql.yml: |
shenyu:
database:
dialect: mysql
init_enable: {{ .Values.dataSource.initEnabled }}
spring:
datasource:
url: jdbc:mysql://{{ template "shenyu.fullname" . }}-mysql.shenyu.svc.cluster.local:3306/shenyu?useUnicode=true&characterEncoding=utf-8&useSSL=false
username: {{ .Values.dataSource.mysql.username }}
password: {{ .Values.dataSource.mysql.password }}
driver-class-name: {{ .Values.dataSource.mysql.driverClass }}
{{- end }}
13 changes: 13 additions & 0 deletions charts/shenyu/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{- define "shenyu.name" -}}
{{- .Chart.Name | trunc 63 | trimSuffix "-" -}}
{{- end -}}


{{- define "shenyu.fullname" -}}
{{- $name := .Chart.Name -}}
{{- if contains $name .Release.Name -}}
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
28 changes: 0 additions & 28 deletions charts/shenyu/templates/deployment.yaml

This file was deleted.

Loading

0 comments on commit 0dbc3e6

Please sign in to comment.