使用 Operator #
什么是 DBPlusEngine-Operator #
Kubernetes 的 Operator 模式允许你在不修改 Kubernetes 自身代码的情况下,通过一个或多个自定义资源关联控制器来扩展集群的能力。 Operator 是 Kubernetes API 的客户端,充当自定义资源的控制器。
Operator 模式旨在捕获(正在管理一个或一组服务的)运维人员的关键目标。 负责特定应用和 service 的运维人员,在系统应该如何运行、如何部署以及出现问题时如何处理等方面有深入的了解。
DBPlusEngine-Operator 帮助用户在 Kubernetes 环境中快速部署一套 DBPlusEngine-Proxy 集群,并且负责部署和维护这个集群周边的相关资源,监控集群状态。
名词解释 #
CRD (CustomResourceDefinition) 用户自定义资源定义,代表 DBPlusEngine-Operator 将利用由 CRD 定义的 CR (CustomResource) ,在 Kubenrnetes 集群中部署一套完整的 DBPlusEngine-Proxy 集群。
产品优势 #
配置简化 #
只需要编写简单的 yaml 即可在集群中部署一套完整的 DBPlusEngine-Proxy 集群。
易扩展 #
通过对 CR yaml 的修改,即可做到水平扩缩容等一系列功能。
易运维 #
使用 DBPlusEngine-Operator 将不用人为干预 DBPlusEngine-Proxy 在集群中的状态,DBPlusEngine-Operator 会自动检测集群状态并纠正。
逻辑架构 #
安装 DBPlusEngine-Operator #
配置[如下](#DBPlusEngine-Operator Parameters)配置内容,配置文件位置 dbplusengine-operator/values.yaml。
执行
kubectl create ns dbplusengine-operator
helm install dbplusengine-operator dbplusengine-operator -n dbplusengine-operator
安装 DBPlusEngine-Operator-Cluster cluster #
配置[如下](#DBPlusEngine-Operator-Cluster Parameters)配置内容,配置文件位置 dbplusengine-proxy/values.yaml。
将 sphere-ex.license 移动至 dbplusengine-proxy/license ,并保持命名 sphere-ex.license。
kubectl create ns dbplusengine
helm install dbplusengine-operator-cluster dbplusengine-operator-cluster -n dbplusengine
DBPlusEngine-Operator Parameters #
DBPlusEngine-Operator parameters #
Name | Description | Value |
---|---|---|
replicaCount | operator 副本数 | 2 |
image.repository | operator 镜像名 | sphereex/dbplusengine-operator |
image.pullPolicy | 镜像拉取策略 | IfNotPresent |
image.tag | 镜像tag | 0.0.1 |
imagePullSecrets | 私有仓库镜像拉取密钥 | [] |
resources | operator 需要的资源 | {} |
webhook.port | operator webhook启动端口 | 9443 |
health.healthProbePort | operator 健康检查端口 | 8081 |
DBPlusEngine-Operator-Cluster Parameters #
DBPlusEngine-Operator-Cluster parameters #
Name | Description | Value |
---|---|---|
replicaCount | DBPlusEngine-Operator-Cluster 集群启动副本数,注意:在开启 automaticScaling 后,这个参数将不再生效 | "1" |
automaticScaling.enable | DBPlusEngine-Operator-Cluster 集群是否开启自动扩缩容 | false |
automaticScaling.scaleUpWindows | DBPlusEngine-Operator-Cluster 自动扩容稳定窗口 | 30 |
automaticScaling.scaleDownWindows | DBPlusEngine-Operator-Cluster 自动缩容稳定窗口 | 30 |
automaticScaling.target | DBPlusEngine-Operator-Cluster 自动扩缩容阈值,数值为百分比,注意:现阶段暂时只支持 cpu 为指标进行扩缩容 | 70 |
automaticScaling.maxInstance | DBPlusEngine-Operator-Cluster 最大扩容副本数 | 4 |
automaticScaling.minInstance | DBPlusEngine-Operator-Cluster 最小启动副本数,缩容不会小于这个副本数 | 1 |
image.registry | DBPlusEngine-Operator-Cluster 镜像host | docker.io |
image.repository | DBPlusEngine-Operator-Cluster 镜像仓库名 | sphereex/dbplusengine-proxy |
image.tag | DBPlusEngine-Operator-Cluster 镜像tag | 5.1.2 |
resources | DBPlusEngine-Operator-Cluster 启动需求资源,在开启automaticScaling 后,以 request 的资源乘以 target 的百分比为触发扩缩容动作的实际使用率 | {} |
service.type | DBPlusEngine-Operator-Cluster 对外暴露方式 | ClusterIP |
service.port | DBPlusEngine-Operator-Cluster 对外暴露端口 | 3307 |
startPort | DBPlusEngine-Operator-Cluster 启动端口 | 3307 |
imagePullSecrets | DBPlusEngine-Operator-Cluster 私有镜像仓库密钥 | [] |
mySQLDriver.version | DBPlusEngine-Operator-Cluster mysql 驱动版本,如果为空,将不下载驱动 | "" |
GN.mode | DBPlusEngine-Operator-Cluster 治理中心模式,支持 sidecar / zookeeper | zookeeper |
GN.SidecarRegistry | DBPlusEngine-Operator-Cluster sidecar 模式镜像 host | <镜像仓库host> |
GN.SidecarRepository | DBPlusEngine-Operator-Cluster sidecar 模式镜像仓库名 | sphereex/dbplusengine-sidecar |
GN.SidecarTag | DBPlusEngine-Operator-Cluster sidecar 模式镜像 tag | 0.2.0 |
GN.sidecarServerAddr | DBPlusEngine-Operator-Cluster sidecar 模式镜像服务端地址 | 服务端地址 |
withAgent | DBPlusEngine-Operator-Cluster 是否启动agent参数 | false |
计算节点 DBPlusEngine-Operator-Cluster Server 配置 权限配置项 #
Name | Description | Value |
---|---|---|
serverConfig.authority.privilege.type | 存储节点数据授权的权限提供者类型,缺省值为 ALL_PERMITTED | ALL_PERMITTED |
serverConfig.authority.users[0].password | 用于登录计算节点的密码 | root |
serverConfig.authority.users[0].user | 用于登录计算节点的用户名,授权主机。格式: | root@% |
计算节点 DBPlusEngine-Operator-Cluster Server 配置 模式配置项 #
Name | Description | Value |
---|---|---|
serverConfig.mode.type | 运行模式类型。 现阶段仅支持 Cluster 模式 | Cluster |
serverConfig.mode.repository.props.namespace | 注册中心命名空间 | governance_ds |
serverConfig.mode.repository.props.server-lists | 注册中心连接地址 | {{ printf "%s-zookeeper.%s:2181" .Release.Name .Release.Namespace }} |
serverConfig.mode.repository.props.maxRetries | 客户端连接最大重试次数 | 3 |
serverConfig.mode.repository.props.operationTimeoutMilliseconds | 客户端操作超时的毫秒数 | 5000 |
serverConfig.mode.repository.props.retryIntervalMilliseconds | 重试间隔毫秒数 | 500 |
serverConfig.mode.repository.props.timeToLiveSeconds | 临时数据失效的秒数 | 60 |
serverConfig.mode.repository.type | 持久化仓库类型。 现阶段仅支持 ZooKeeper | ZooKeeper |
治理节点 ZooKeeper 配置项 #
配置项 | 描述 | 值 |
---|---|---|
zookeeper.enabled | 用来切换是否使用 ZooKeeper 的 chart | true |
zookeeper.replicaCount | ZooKeeper 节点数量 | 1 |
zookeeper.persistence.enabled | 标识 ZooKeeper 是否使用持久卷申领 (PersistentVolumeClaim) 用来申请持久卷(PersistentVolume) | false |
zookeeper.persistence.storageClass | 持久卷(PersistentVolume)的存储类 (StorageClass) | "" |
zookeeper.persistence.accessModes | 持久卷(PersistentVolume)的访问模式 | ["ReadWriteOnce"] |
zookeeper.persistence.size | 持久卷(PersistentVolume) 大小 | 8Gi |
配置示例 #
dbplusengine-operator/values.yaml #
## @section DBPlusEngine-Operator-Cluster operator parameters
## @param replicaCount operator 副本数
##
replicaCount: 2
image:
## @param image.repository operator 镜像名
##
repository: "sphere-ex/dbplusengine-operator"
## @param image.pullPolicy 镜像拉取策略
##
pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart appVersion.
## @param image.tag 镜像tag
##
tag: "0.1.0"
## @param imagePullSecrets 私有仓库镜像拉取密钥
## e.g:
## imagePullSecrets:
## - name: mysecret
##
imagePullSecrets: []
## @param resources operator 需要的资源
## e.g:
## resources:
## limits:
## cpu: 2
## limits:
## cpu: 2
##
resources: {}
## @param webhook.port operator webhook启动端口
##
webhook:
port: 9443
## @param health.healthProbePort operator 健康检查端口
##
health:
healthProbePort: 8081
dbplusengine-proxy/values.yaml #
## @section DBPlusEngine-Operator-Cluster cluster parameters
## @param replicaCount DBPlusEngine-Operator-Cluster 集群启动副本数,注意:在开启 automaticScaling 后,这个参数将不再生效
##
replicaCount: "1"
## @param automaticScaling.enable DBPlusEngine-Operator-Cluster 集群是否开启自动扩缩容
## @param automaticScaling.scaleUpWindows DBPlusEngine-Operator-Cluster 自动扩容稳定窗口
## @param automaticScaling.scaleDownWindows DBPlusEngine-Operator-Cluster 自动缩容稳定窗口
## @param automaticScaling.target DBPlusEngine-Operator-Cluster 自动扩缩容阈值,数值为百分比,注意:现阶段暂时只支持 cpu 为指标进行扩缩容
## @param automaticScaling.maxInstance DBPlusEngine-Operator-Cluster 最大扩容副本数
## @param automaticScaling.minInstance DBPlusEngine-Operator-Cluster 最小启动副本数,缩容不会小于这个副本数
##
automaticScaling:
enable: false
scaleUpWindows: 30
scaleDownWindows: 30
target: 20
maxInstance: 4
minInstance: 1
## @param image.registry DBPlusEngine-Operator-Cluster 镜像host
## @param image.repository DBPlusEngine-Operator-Cluster 镜像仓库名
## @param image.tag DBPlusEngine-Operator-Cluster 镜像tag
## @param withAgent DBPlusEngine-Operator-Cluster 是否开启agent
##
image:
registry: <镜像仓库host>
repository: sphere-ex/dbplusengine-proxy
tag: 1.1.0
withAgent: false
## @param resources DBPlusEngine-Operator-Cluster 启动需求资源,在开启automaticScaling 后,以 request 的资源乘以 target 的百分比为触发扩缩容动作的实际使用率
## e.g:
## resources:
## limits:
## cpu: 2
## requests:
## cpu: 2
##
resources: {}
## @param service.type DBPlusEngine-Operator-Cluster 对外暴露方式
## @param service.port DBPlusEngine-Operator-Cluster 对外暴露端口
##
service:
type: ClusterIP
port: 3307
## @param startPort DBPlusEngine-Operator-Cluster 启动端口
##
startPort: 3307
## @param imagePullSecrets DBPlusEngine-Operator-Cluster 私有镜像仓库密钥
## e.g:
## imagePullSecrets:
## - name: mysecret
##
imagePullSecrets: []
## @param mySQLDriver.version DBPlusEngine-Operator-Cluster mysql 驱动版本,如果为空,将不下载驱动
##
mySQLDriver:
version: ""
## @section DBPlusEngine-Operator-Cluster ServerConfiguration parameters
## NOTE: If you use the sub-charts to deploy Zookeeper, the server-lists field must be "{{ printf \"%s-zookeeper.%s:2181\" .Release.Name .Release.Namespace }}",
## otherwise please fill in the correct zookeeper address
## The server.yaml is auto-generated based on this parameter.
## If it is empty, the server.yaml is also empty.
## ref: https://shardingsphere.apache.org/document/current/en/user-manual/shardingsphere-jdbc/yaml-config/mode/
## ref: https://shardingsphere.apache.org/document/current/en/user-manual/common-config/builtin-algorithm/metadata-repository/
##
serverConfig:
## @section Compute-Node DBPlusEngine-Operator-Cluster ServerConfiguration authority parameters
## NOTE: It is used to set up initial user to login compute node, and authority data of storage node.
## @param serverConfig.authority.privilege.type authority provider for storage node, the default value is ALL_PERMITTED
## @param serverConfig.authority.users[0].password Password for compute node.
## @param serverConfig.authority.users[0].user Username,authorized host for compute node. Format: <username>@<hostname> hostname is % or empty string means do not care about authorized host
##
authority:
privilege:
type: ALL_PERMITTED
users:
- password: root
user: root@%
## @section Compute-Node DBPlusEngine-Operator-Cluster ServerConfiguration mode Configuration parameters
## @param serverConfig.mode.type Type of mode configuration. Now only support Cluster mode
## @param serverConfig.mode.repository.props.namespace Namespace of registry center
## @param serverConfig.mode.repository.props.server-lists Server lists of registry center
## @param serverConfig.mode.repository.props.maxRetries Max retries of client connection
## @param serverConfig.mode.repository.props.operationTimeoutMilliseconds Milliseconds of operation timeout
## @param serverConfig.mode.repository.props.retryIntervalMilliseconds Milliseconds of retry interval
## @param serverConfig.mode.repository.props.timeToLiveSeconds Seconds of ephemeral data live
## @param serverConfig.mode.repository.type Type of persist repository. Now only support ZooKeeper
##
##
## mode:
## repository:
## props:
## namespace: ssd1031test1
## server-lists: "127.0.0.1:21506"
## type: SphereEx:MATE
## type: Cluster
mode:
repository:
props:
maxRetries: 3
namespace: governance_ds
operationTimeoutMilliseconds: 5000
retryIntervalMilliseconds: 500
server-lists: "{{ printf \"%s-zookeeper.%s:2181\" .Release.Name .Release.Namespace }}"
timeToLiveSeconds: 600
type: ZooKeeper
type: Cluster
props:
proxy-frontend-database-protocol-type: PostgreSQL
## @section ZooKeeper chart parameters
## ZooKeeper chart configuration
## https://github.com/bitnami/charts/blob/master/bitnami/zookeeper/values.yaml
##
zookeeper:
## @param zookeeper.enabled Switch to enable or disable the ZooKeeper helm chart
##
enabled: true
## @param zookeeper.replicaCount Number of ZooKeeper nodes
##
replicaCount: 3
## ZooKeeper Persistence parameters
## ref: https://kubernetes.io/docs/user-guide/persistent-volumes/
## @param zookeeper.persistence.enabled Enable persistence on ZooKeeper using PVC(s)
## @param zookeeper.persistence.storageClass Persistent Volume storage class
## @param zookeeper.persistence.accessModes Persistent Volume access modes
## @param zookeeper.persistence.size Persistent Volume size
##
persistence:
enabled: false
storageClass: ""
accessModes:
- ReadWriteOnce
size: 8Gi
清理 #
helm uninstall dbplusengine-proxy -n dbplusengine
helm uninstall dbplusengine-operator -n dbplusengine-operator
kubectl delete crd clusters.dbplusengine.sphere-ex.com \
proxyconfigs.dbplusengine.sphere-ex.com \
plocks.dbplusengine.sphere-ex.com \
pmetadata.dbplusengine.sphere-ex.com \
pnodes.dbplusengine.sphere-ex.com \
ppipelines.dbplusengine.sphere-ex.com \
psys.dbplusengine.sphere-ex.com \
pworkids.dbplusengine.sphere-ex.com