跳到主要内容

租户运维操作

租户资源涉及面较广,为了避免其变得过于臃肿、提高租户运维的灵活度,Operator 提供租户运维资源 OBTenantOperation 来完成租户内和租户间的运维功能。Operator 2.1.0 支持三种运维操作:修改 Root 密码、激活备租户和主备租户互切。其中,激活备租户和主备互切两个功能与物理备库相关。三种运维操作的配置示例如下:

#修改密码
apiVersion: oceanbase.oceanbase.com/v1alpha1
kind: OBTenantOperation
metadata:
name: op-chg-pwd
namespace: oceanbase
spec:
type: "CHANGE_PASSWORD"
changePwd:
tenant: "t1"
secretRef: "t1-credential-new"
#备租户升级为主租户
apiVersion: oceanbase.oceanbase.com/v1alpha1
kind: OBTenantOperation
metadata:
name: op-failover
namespace: oceanbase
spec:
type: "FAILOVER"
failover:
standbyTenant: "t1s"
#主备互切
apiVersion: oceanbase.oceanbase.com/v1alpha1
kind: OBTenantOperation
metadata:
name: op-switchover
namespace: oceanbase
spec:
type: "SWITCHOVER"
switchover:
primaryTenant: "t1"
standbyTenant: "t1s"

常用操作示例

创建备租户

kubectl apply -f tenant_restore.yaml

查看租户状态

kubectl get obtenants.oceanbase.oceanbase.com -n oceanbase

返回结果示例如下:

NAME   STATUS    TENANTNAME   TENANTROLE   CLUSTERNAME   AGE
t1 running t1 PRIMARY obcluster 3d4h
t1s running t1s STANDBY obcluster 3h30m

执行租户运维操作

kubectl apply -f tenant_op_change_pwd.yaml
kubectl apply -f tenant_op_failover.yaml

查看租户运维操作信息

kubectl get obtenantoperations.oceanbase.oceanbase.com -n oceanbase

返回结果示例如下:

NAME          TYPE       STATUS       AGE   CLUSTER     PRIMARYTENANT
op-failover FAILOVER SUCCESSFUL 8s obcluster t1s

需要说明的是,在打印的状态信息中,PRIMARYTENANT 指的是参数当中的首要租户,而非主租户。对应着的次要租户为 SECONDARYTENANT。为了节省空间默认不打印次要租户字段,使用命令 kubectl get obtenantoperations.oceanbase.oceanbase.com -o wide 可查看。