总体设计
OpengaussCluster资源关系示意图

Pod迁移示意图

opengauss-operator部署及使用
一、部署流程
1.环境准备
- docker: 20.10.8
- 集群:kubernetes v1.21.5
- CNI插件:flannel v0.15.0
- CSI插件: nfs-subdir-external-provisioner:v4.0.2 (需要设置为default)
2.拉取镜像
由于部署和使用对时间有需求,需要提前在各个节点拉取镜像
docker pull enmotech/opengauss:2.1.0
docker pull gcr.io/distroless/static:nonroot (需要能访问google服务)
docker pull gcr.io/kubebuilder/kube-rbac-proxy:v0.8.0 (需要能访问google服务)
docker pull zenghaocq/opengauss-controller:0.2.0
docker pull larryyang97/opengauss-webhook
3.部署CRD
在项目路径下运行如下命令进行部署:
make install
#如需卸载
make uninstall
4.部署controller
在项目路径下运行如下命令进行部署:
make deploy
#如需卸载
make undeploy
5.部署webhook
webhook部署需要获取caBundle和生成证书,相关源代码和部署文件在./webhooks
首先切换到源码的webhooks/deploy目录下
1. 获取caBundle
echo $(kubectl get configmap -n kube-system extension-apiserver-authentication -o=jsonpath='{.data.client-ca-file}' | base64 | tr -d '\n')
2.使用1中获取的caBundle替换hook.yaml中的caBundle字段
apiVersion: admissionregistration.k8s.io/v1
kind: MutatingWebhookConfiguration
metadata:
name: "pod-migration-webhook.opengauss.org"
webhooks:
<...>
clientConfig:
caBundle: <substitute with your caBundle here>
<...>
3.使用webhook-cert.sh脚本生成证书和秘钥
bash webhook-cert.sh --service opengauss-pod-migration-webhook-service --secret webhook-tls-secret
4.部署
kubectl apply -f ./
二、使用operator
这里描述yaml文件,用如下命令即可。
kubectl apply -f <file-name>.yaml
#如
kubectl apply -f config/samples/db_v1_opengausscluster.yaml
1.部署单节点opengauss集群
使用OpenGaussCluster这一CRD部署,将primary设置为1,standby节点个数设置为0即可
apiVersion: db.opengauss.org/v1
kind: OpenGaussCluster
metadata:
name: opengausscluster-sample #名字不要过长
spec:
image: enmotech/opengauss:2.1.0 #镜像名
primary:
replicas: 1 #单机部署
standby:
replicas: 0
2.部署主备模式
本operator使用无需提前为pod指定ip,目前支持一主多从,已经测试过一主八从。1-2分钟左右,所有pod处于running ready状态
apiVersion: db.opengauss.org/v1
kind: OpenGaussCluster
metadata:
name: opengausscluster-sample
spec:
image: enmotech/opengauss:2.1.0 #镜像名
password: "Test@12345" #初始密码,可以进入数据库更改
primary:
replicas: 1 #primary副本数
storage: 512Mi
storageClass: nfs-client #注意当storageClass为空的时候,使用系统默认storageClass
#应该指定nfs storageClass的名字
standby:
replicas: 2 #standby副本数
storage: 512Mi
storageClass: nfs-client
3.缩扩容
修改OpenGaussCluster.spec.standby.replicas
字段即可完成缩扩容,用kubectel edit
修改,或者重新kubectl apply -f <file-name>.yaml
均可
注意,当前不支持从0扩容或者缩容到0
apiVersion: db.opengauss.org/v1
kind: OpenGaussCluster
metadata:
name: opengausscluster-sample
spec:
image: enmotech/opengauss:2.1.0 #镜像名
password: "Test@12345"
primary:
replicas: 1 #primary副本数
storage: 512Mi
storageClass: nfs-client
standby:
replicas: 3 #standby副本数,更改为期望的副本数,
storage: 512Mi
storageClass: nfs-client
4.升级
修改OpenGaussCluster.spec.image
字段即可完成,注意目前只保证enmotech/opengauss:2.1.0及更高版本兼容,这里演示enmotech/opengauss:2.1.0到enmotech/opengauss:latest的升级测试
升级镜像版本,用```kubectel edit```修改,或者重新```kubectl apply -f <file-name>.yaml```均可
```yaml
apiVersion: db.opengauss.org/v1
kind: OpenGaussCluster
metadata:
name: opengausscluster-sample
spec:
image: enmotech/opengauss:latest #要升级的镜像名
primary:
replicas: 1
standby:
replicas: 3
5.pod迁移
使用OpenGaussPodMigration这一CRD实现迁移,迁移需要部署webhook
apiVersion: db.opengauss.org/v1
kind: OpenGaussPodMigration
metadata:
name: opengausspodmigration-sample
labels:
clusterName: opengausscluster-sample #必要!迁移的pod对应的OpenGaussCluster名字
spec:
podName: opengausscluster-sample-s-1 #要迁移的pod名字
targetNodeName: node1 #要迁移到的节点名字
总体设计
OpengaussCluster资源关系示意图
Pod迁移示意图
opengauss-operator部署及使用
一、部署流程
1.环境准备
2.拉取镜像
由于部署和使用对时间有需求,需要提前在各个节点拉取镜像
3.部署CRD
在项目路径下运行如下命令进行部署:
4.部署controller
在项目路径下运行如下命令进行部署:
5.部署webhook
webhook部署需要获取caBundle和生成证书,相关源代码和部署文件在
./webhooks
首先切换到源码的webhooks/deploy目录下1. 获取caBundle
2.使用1中获取的caBundle替换hook.yaml中的caBundle字段
3.使用webhook-cert.sh脚本生成证书和秘钥
4.部署
二、使用operator
这里描述yaml文件,用如下命令即可。
1.部署单节点opengauss集群
使用OpenGaussCluster这一CRD部署,将primary设置为1,standby节点个数设置为0即可
2.部署主备模式
本operator使用无需提前为pod指定ip,目前支持一主多从,已经测试过一主八从。1-2分钟左右,所有pod处于
running ready状态
3.缩扩容
修改
OpenGaussCluster.spec.standby.replicas
字段即可完成缩扩容,用kubectel edit
修改,或者重新kubectl apply -f <file-name>.yaml
均可注意,当前不支持从0扩容或者缩容到0
4.升级
修改
OpenGaussCluster.spec.image
字段即可完成,注意目前只保证enmotech/opengauss:2.1.0及更高版本兼容,这里演示enmotech/opengauss:2.1.0到enmotech/opengauss:latest的升级测试5.pod迁移
使用OpenGaussPodMigration这一CRD实现迁移,迁移需要部署webhook