1 Star 0 Fork 21

zhangxubo / openGauss-operator

forked from openGauss / openGauss-operator 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MulanPSL-2.0

openGauss-operator

介绍

Operator介绍

openGauss operator 是一个基于Kubernetes管理的openGauss集群安装与维护的工具,其功能主要包括数据库集群的安装部署、维护、拓扑保持、资源升级、水平扩缩容、同城切换等全生命周期管理。

整体架构

  1. Init Container
    1. Image: openGauss
    2. 主要作用:初始化DB参数,修改配置
  2. openGauss Container
    1. Image: openGauss
    2. 主要作用:挂载Init Container的Data目录
  3. Sidecar
    1. Image:openGauss & Filebeat
    2. 主要作用:
      1. 配置DB数据目录和备份目录
      2. 执行gs_basebackup全量备份以及日志输出

读写分离设计

读写分离设计是基于servcie和pod 添加label实现的 operator会给openGauss集群下的主、备pod角色添加对应角色的label。其中角色为主的节点,Pod的label为primary;角色为备的节点,Pod的label为standby。然后通过读写servcie根据labels映射到不同的pod,其中读service会映射到所在k8s集群opengGauss集群下所有备节点所在的Pod,写service会映射到所在k8s集群opengGauss集群主节点所在的Pod,客户端通过访问k8s集群的任一Node的ip+service的Nodeport,从而实现读写分离。

功能列表

openGauss operator 支持以下功能

  • 集群部署 (支持单节点,多节点,及同城灾备部署)
  • 集群扩容
  • 集群缩容
  • 集群节点迁移
  • 集群资源升级(支持调整集群的CPU、内存、存储、带宽等,滚动升级)
  • 同城切换
  • 手工维护
  • 集群删除

支持环境

  • 机器架构
    • Linux version 3.10.0-957.el7.x86_64
  • CNI 支持类型
    • calico
  • CSI 支持类型
    • hostpath
    • topolvm
    • huawei分布式存储

安装

基础镜像

准备openEuler镜像

# 下载openEuler镜像
wget http://121.36.97.194/openEuler-20.03-LTS-SP3/docker_img/x86_64/openEuler-docker.x86_64.tar.xz
# 加载
docker image load -i openEuler-docker.x86_64.tar.xz

编写dockerfile,打包openGauss镜像

# 下载极简版openGauss安装介质
curl -LO https://opengauss.obs.cn-south-1.myhuaweicloud.com/3.0.0/x86_openEuler/openGauss-3.0.0-openEuler-64bit.tar.bz2
# 打包openGauss镜像
docker build -f og3.0.0-x86_64.dockerfile -t opengauss-3.0.0:latest .
# 保存openGauss镜像
docker save opengauss-3.0.0:latest -o opengauss-docker.x86_64.tar.xz

打包operator镜像

# 下载operator到本地
git clone https://gitee.com/opengauss/openGauss-operator.git
# 进入openGauss-operator路径
cd openGauss-operator
# 准备相关依赖
curl -LO https://opengauss.obs.cn-south-1.myhuaweicloud.com/3.0.0/x86_openEuler/openGauss-3.0.0-openEuler-64bit.tar.bz2
curl -L -O https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.11.1-linux-x86_64.tar.gz
curl -LO https://github.com/krallin/tini/releases/download/v0.19.0/tini-amd64
# 打包镜像
make docker-build IMG=opengauss-operator:v0.1.0

部署

部署operator

make deploy IMG=opengauss-operator:v0.1.0

编写openGauss集群的配置文件sample.yaml,并启动集群

kubectl apply -f sample.yaml 

关于部署operator的详细步骤,参考部署详情

使用手册

自定义资源CRD描述

CRD主要属性见下表

属性名称 属性类型 属性说明
ReadPort Int NodePort读端口
WritePort int NodePort写端口
DBPort int OpenGauss实例端口
Image string OpenGauss镜像地址
LocalRole string 集群角色 :primary /standby
CPU string OpenGauss实例CPU限额
Storage string OpenGauss实例存储限额
Memory string OpenGauss实例内存限额
BandWidth string 带宽
IpList IpNodeEntry Opengauss实例的IP和工作节点名称
RemoteIpList []string 同城集群的实例IP列表
BackupPath string 本地备份路径
ArchiveLogPath string 本地归档路径
HostpathRoot string 本地存储路径(使用本地存储时填写)
StorageClass string 存储插件类型
SidecarImage string Sidecar镜像地址
SidecarCPU string Sidecar CPU限额
SidecarMemory string Sidecar内存限额
SidecarStorage string Sidecar存储限额
Maintenance bool 集群维护模式
ScriptConfig string 执行脚本的配置
FilebeatConfig string Filebeat配置CM

配置configmap

openGauss operator部署集群时,支持2个可配置的configmap,对应的cr属性分别为scriptconfig和filebeatconfig

  • scriptconfig对应自定义任务执行脚本的configmap,默认配置名称opengauss-script-config,支持自定义配置脚本
  • filebeatconfig 对应执行脚本的configmap,默认配置名称:opengauss-filebeat-config,支持自定义配置,将日志通过filebeat转发到es或其他。默认配置转到es,设置如下,部署时需要根据实际情况修改

关于配置configmap的具体细节,详见配置configmap详情

创建集群

operator成功部署以后,就可以通过其部署OG应用。根据输入的配置文件不同,可以部署不同架构的OG应用,包括但不限于:

  • 单节点
  • 主从架构
  • 同城双集群部署

部署OG应用

kubectl apply -f cluster.yaml

查询应用的部署状态

kubectl get opengausscluster <name>

og部署验证通过后,通过容器内的client连接OG

kubectl exec -it -n <namespace> <pod name> -c og -- gsql -d <dbname> -p <port> -c "<command/sql>"

通过容器内的数据库服务控制工具gs_ctl查看og集群的详细信息:

kubectl exec -ti -n og <pod name> -c og  -- gs_ctl query -D <directory of gauss instance>

部署详情见openGauss集群部署详情

同城双集群部署

og集群部署在两个k8s上,每个k8s各有一个节点,组成HA集群,前提需要保证两个k8s集群网络的连通性,其中:

  1. 部署在本地集群的localrole应设置为primary,同城集群的localrole为standby
  2. 同城双集群部署与单集群部署的区别除了localrole的属性的值设置外,还包括remoteiplist属性
  3. 本地集群和同城集群CR的yaml文件中需要分别增加对方集群的Pod Ip.
  4. 先部署本地集群,在部署同城集群

分别在两个k8s上查询应用的部署状态,直到同城和本地集群STATE都为ready:

kubectl get opengaussclusters.opengauss.sig -n og

查询应用的部署Pod的主从角色:

kubectl get pod -n og --show-labels

验证部署,通过本地集群容器内的client去连接OG:

$  kubectl exec -ti -n <namespace> <pod name> -c og -- gsql -d <dbname> -p <port> -c "<command/sql>"

通过容器内的数据库服务控制工具gs_ctl查看og集群的详细信息:

$ kubectl exec -ti -n <namespace> <pod name> -c og -- gs_ctl query -D <directory of gauss instance>

同城部署详情请参考openGauss同城部署与切换详情

同城切换

同城切换功能,只需要分别修改本地集群和同城集群CR的localrole即可:

  1. 修改本地集群CR的localrole为standby
  2. 待本地集群原有primary的pod labels标记为standby后,修改同城集群CR的localrole为primary,防止出现双主
  3. 切换过程中,本地集群的cr状态由ready变为update,之后可能为变为recovering,待切换完成后,会变为ready
  4. 同样切换过程中,同城集群的cr状态由ready变为update,之后可能为变为recovering,待切换完成后,会变为ready,同城集群的会自动选择一个pod为主

验证灾备切换是否成功,通过容器内的数据库服务控制工具gs_ctl查看原同城集群的详细信息。
同城集群切换的详细信息请参考openGauss同城部署与切换详情

删除集群

删除openGauss集群,只需要执行k8s命令删除cr即可。需要注意的是,删除openGauss集群后,该CR的pvc仍然存在

执行k8s删除命令,删除cr

kubectl delete opengaussclusters.opengauss.sig -n <namespace name> <cr name> 

删除cr资源后,其PVC仍然保留,以防止需要恢复数据。当确定要删除PVC时,首先查看og集群的pvc

kubectl get pvc -n  <namespace name> |grep <cr name> 

确认数据不需要保存时,直接删除PVC资源即可,避免资源的浪费

kubectl delete pvc <pvc name> -n <namespace name>

删除集群的具体操作请参考删除openGauss集群详情

其他运维操作步骤(单机&同城)

扩容

opengauss 集群的扩容是通过修改CR的iplist属性来实现的,即:

...
iplist:
  - ip: 172.16.0.2
    nodename: node1
...

扩容即新增iplist的一个元素,通过调整openGauss的iplist,例如:

...
iplist:
  - ip: 172.16.0.2
    nodename: node1
  - ip: 172.16.0.5
    nodename: node1
...

更新配置文件后对集群重新进行部署

kubectl apply -f cluster.yaml

查询应用的部署状态,直到pod的STATE由初始的ready变为updating,最终变为为ready:

kubectl get opengaussclusters.opengauss.sig -n og

查询应用的部署Pod的主从角色:

kubectl get pod -n og --show-labels

openGauss集群扩容具体细节请参考operator常见运维操作

缩容

缩容的操作与扩容相似,不同的地方在于已经部署的openGauss集群,减少iplist的配置信息。

资源升级

opertor支持og集群的资源升级,即修改已有集群的内存,CPU,带宽,存储容量等大小。需要特别注意的是:

  • 存储容量仅支持扩容,不支持缩容
  • 如果资源调整涉及cpu和内存、带宽资源调整,会重启pod。同时如果为多节点部署,会发生主从切换

编辑CR的yaml文件,保存后重新部署

kubectl apply -f cluster.yaml

在CR重新部署后,等待pod的STATE恢复为ready,资源更新完成。 openGauss集群扩缩容详细信息请参考openGauss资源升级

手工维护

当存在operator不能恢复需要人工干预情况,或者需要手工进入到og集群的库中进行一些运维操作,且人为维护期间不希望operator继续处理对应集群时,可以修改集群对应CR的maintenance属性。

···
  readport: 30120
  writeport: 30121
  dbport: 26000 
  localrole: primary
  maintenance: true
···

maintenance属性默认值为fasle,支持修改,当maintenancetrue时,operator不会干预对应集群运行,无论此时集群状态正常/异常。

故障诊断

Operator 看状态查日志

operator默认采用Deployments方式部署,默认部署在opengauss-operator-system命名空间下

查看operator的Deployments状态及其对应pod的状态

# 查看operator的Deployments状态
kubectl get deployments.apps  -n <namaspacename>
# 查看operator的pod的状态
kubectl get pod  -n <namaspacename>

查看operator日志

kubectl logs -f -n <namespacename> <podname>

查看operator pod信息

kubectl get pod  -n opengauss-operator-system

查看operator的日志

kubectl logs -f -n opengauss-operator-system <operator pod name>

OG 看状态查日志

查看opengauss集群的状态

kubectl get opengaussclusters.opengauss.sig  -n <namespacename> <crName>

查看opengauss集群的状态的详情

kubectl describe opengaussclusters.opengauss.sig  -n <namespacename>  <crName>

查看 og集群下pod的日志

kubectl logs -f -n  <namespacename> <podName>

故障诊断详细信息请参考故障诊断手段

连接方式

用户可以通过service连接数据库,部署的og集群,会有对应的写servcie和读service 写service可读可写;读service仅可以进行读操作

NodePort(读写分离)

部署og集群时,会创建两个service:读service和写service service命名规则如下

  • 写service og-<cr名称/集群名称>-svc
  • 读service og-<cr名称/集群名称>-svc-read
kubectl get svc -n og |grep ogtest
og-ogtest-svc        NodePort   10.102.11.89    <none>        5432:30002/TCP   6d1h
og-ogtest-svc-read   NodePort   10.97.134.48    <none>        5432:30001/TCP   6d1h

Pod ip 直连(underlay)

示例:外部客户端配置方式-java

示例 og命名空间下存在一主一从的og集群ogtest

$ kubectl get opengaussclusters.opengauss.sig -n og 
NAME     ROLE      CPU    MEMORY   READ PORT   WRITE PORT   DB PORT   STATE   AGE
ogtest   primary   500m   2Gi      30001       30002        5432      ready   6d2h

# 对应的读写service
$ kubectl get svc -n og |grep ogtest                   
og-ogtest-svc        NodePort   10.102.11.89    <none>        5432:30002/TCP   6d2h
og-ogtest-svc-read   NodePort   10.97.134.48    <none>        5432:30001/TCP   6d2h

客户端连接db时,使用k8s集群下任一node的ip 和写service的noteport就可以连接数据库

故障案例

openGauss集群故障

operator会监控集群中 og集群的pod,当监测到pod故障后,会尝试将其重新拉起。案例包括但不限于:

  • 单点pod故障
  • 1主1从Primary pod故障
  • 1主1从Standby pod故障
  • 存储故障 - 可分配空间不足(vg)
  • 存储故障 - data pvc存储空间不足

详见openGauss集群故障恢复案例

operator故障

详见operator集群故障恢复案例

木兰宽松许可证, 第2版 木兰宽松许可证, 第2版 2020年1月 http://license.coscl.org.cn/MulanPSL2 您对“软件”的复制、使用、修改及分发受木兰宽松许可证,第2版(“本许可证”)的如下条款的约束: 0. 定义 “软件”是指由“贡献”构成的许可在“本许可证”下的程序和相关文档的集合。 “贡献”是指由任一“贡献者”许可在“本许可证”下的受版权法保护的作品。 “贡献者”是指将受版权法保护的作品许可在“本许可证”下的自然人或“法人实体”。 “法人实体”是指提交贡献的机构及其“关联实体”。 “关联实体”是指,对“本许可证”下的行为方而言,控制、受控制或与其共同受控制的机构,此处的控制是指有受控方或共同受控方至少50%直接或间接的投票权、资金或其他有价证券。 1. 授予版权许可 每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的版权许可,您可以复制、使用、修改、分发其“贡献”,不论修改与否。 2. 授予专利许可 每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的(根据本条规定撤销除外)专利许可,供您制造、委托制造、使用、许诺销售、销售、进口其“贡献”或以其他方式转移其“贡献”。前述专利许可仅限于“贡献者”现在或将来拥有或控制的其“贡献”本身或其“贡献”与许可“贡献”时的“软件”结合而将必然会侵犯的专利权利要求,不包括对“贡献”的修改或包含“贡献”的其他结合。如果您或您的“关联实体”直接或间接地,就“软件”或其中的“贡献”对任何人发起专利侵权诉讼(包括反诉或交叉诉讼)或其他专利维权行动,指控其侵犯专利权,则“本许可证”授予您对“软件”的专利许可自您提起诉讼或发起维权行动之日终止。 3. 无商标许可 “本许可证”不提供对“贡献者”的商品名称、商标、服务标志或产品名称的商标许可,但您为满足第4条规定的声明义务而必须使用除外。 4. 分发限制 您可以在任何媒介中将“软件”以源程序形式或可执行形式重新分发,不论修改与否,但您必须向接收者提供“本许可证”的副本,并保留“软件”中的版权、商标、专利及免责声明。 5. 免责声明与责任限制 “软件”及其中的“贡献”在提供时不带任何明示或默示的担保。在任何情况下,“贡献者”或版权所有者不对任何人因使用“软件”或其中的“贡献”而引发的任何直接或间接损失承担责任,不论因何种原因导致或者基于何种法律理论,即使其曾被建议有此种损失的可能性。 6. 语言 “本许可证”以中英文双语表述,中英文版本具有同等法律效力。如果中英文版本存在任何冲突不一致,以中文版为准。 条款结束 如何将木兰宽松许可证,第2版,应用到您的软件 如果您希望将木兰宽松许可证,第2版,应用到您的新软件,为了方便接收者查阅,建议您完成如下三步: 1, 请您补充如下声明中的空白,包括软件名、软件的首次发表年份以及您作为版权人的名字; 2, 请您在软件包的一级目录下创建以“LICENSE”为名的文件,将整个许可证文本放入该文件中; 3, 请将如下声明文本放入每个源文件的头部注释中。 Copyright (c) [Year] [name of copyright holder] [Software Name] is licensed under Mulan PSL v2. You can use this software according to the terms and conditions of the Mulan PSL v2. You may obtain a copy of Mulan PSL v2 at: http://license.coscl.org.cn/MulanPSL2 THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. See the Mulan PSL v2 for more details. Mulan Permissive Software License,Version 2 Mulan Permissive Software License,Version 2 (Mulan PSL v2) January 2020 http://license.coscl.org.cn/MulanPSL2 Your reproduction, use, modification and distribution of the Software shall be subject to Mulan PSL v2 (this License) with the following terms and conditions: 0. Definition Software means the program and related documents which are licensed under this License and comprise all Contribution(s). Contribution means the copyrightable work licensed by a particular Contributor under this License. Contributor means the Individual or Legal Entity who licenses its copyrightable work under this License. Legal Entity means the entity making a Contribution and all its Affiliates. Affiliates means entities that control, are controlled by, or are under common control with the acting entity under this License, ‘control’ means direct or indirect ownership of at least fifty percent (50%) of the voting power, capital or other securities of controlled or commonly controlled entity. 1. Grant of Copyright License Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable copyright license to reproduce, use, modify, or distribute its Contribution, with modification or not. 2. Grant of Patent License Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable (except for revocation under this Section) patent license to make, have made, use, offer for sale, sell, import or otherwise transfer its Contribution, where such patent license is only limited to the patent claims owned or controlled by such Contributor now or in future which will be necessarily infringed by its Contribution alone, or by combination of the Contribution with the Software to which the Contribution was contributed. The patent license shall not apply to any modification of the Contribution, and any other combination which includes the Contribution. If you or your Affiliates directly or indirectly institute patent litigation (including a cross claim or counterclaim in a litigation) or other patent enforcement activities against any individual or entity by alleging that the Software or any Contribution in it infringes patents, then any patent license granted to you under this License for the Software shall terminate as of the date such litigation or activity is filed or taken. 3. No Trademark License No trademark license is granted to use the trade names, trademarks, service marks, or product names of Contributor, except as required to fulfill notice requirements in Section 4. 4. Distribution Restriction You may distribute the Software in any medium with or without modification, whether in source or executable forms, provided that you provide recipients with a copy of this License and retain copyright, patent, trademark and disclaimer statements in the Software. 5. Disclaimer of Warranty and Limitation of Liability THE SOFTWARE AND CONTRIBUTION IN IT ARE PROVIDED WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED. IN NO EVENT SHALL ANY CONTRIBUTOR OR COPYRIGHT HOLDER BE LIABLE TO YOU FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO ANY DIRECT, OR INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING FROM YOUR USE OR INABILITY TO USE THE SOFTWARE OR THE CONTRIBUTION IN IT, NO MATTER HOW IT’S CAUSED OR BASED ON WHICH LEGAL THEORY, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 6. Language THIS LICENSE IS WRITTEN IN BOTH CHINESE AND ENGLISH, AND THE CHINESE VERSION AND ENGLISH VERSION SHALL HAVE THE SAME LEGAL EFFECT. IN THE CASE OF DIVERGENCE BETWEEN THE CHINESE AND ENGLISH VERSIONS, THE CHINESE VERSION SHALL PREVAIL. END OF THE TERMS AND CONDITIONS How to Apply the Mulan Permissive Software License,Version 2 (Mulan PSL v2) to Your Software To apply the Mulan PSL v2 to your work, for easy identification by recipients, you are suggested to complete following three steps: i Fill in the blanks in following statement, including insert your software name, the year of the first publication of your software, and your name identified as the copyright owner; ii Create a file named “LICENSE” which contains the whole context of this License in the first directory of your software package; iii Attach the statement to the appropriate annotated syntax at the beginning of each source file. Copyright (c) [Year] [name of copyright holder] [Software Name] is licensed under Mulan PSL v2. You can use this software according to the terms and conditions of the Mulan PSL v2. You may obtain a copy of Mulan PSL v2 at: http://license.coscl.org.cn/MulanPSL2 THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. See the Mulan PSL v2 for more details.

简介

openGauss Kubernetes Operator 展开 收起
MulanPSL-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/zhang_xubo/openGauss-operator.git
git@gitee.com:zhang_xubo/openGauss-operator.git
zhang_xubo
openGauss-operator
openGauss-operator
master

搜索帮助