This topic describes how to create a tenant by using ob-operator.
Prerequisites
ob-operator V1.2.0-snapshot or later is deployed.
OceanBase Database is deployed and runs normally.
Create a tenant
You can create a tenant by applying a tenant configuration file. For more information about the configuration file, see GitHub.
Run the following command to create a tenant. This command creates a tenant with custom resources in the current Kubernetes cluster.
kubectl apply -f tenant.yaml
Example
Create a MySQL tenant named obtenant with three replicas and allow all clients to connect to the tenant.
During the creation of the tenant, ob-operator creates resource units and resource pools based on the zones in the topology specified in the tenant.yaml configuration file. ob-operator creates resource units based on the parameter settings in the resource section and creates resource pools based on the resource units.
apiVersion: cloud.oceanbase.com/v1
kind: Tenant
metadata:
name: obtenant
namespace: obcluster
spec:
# Required
clusterName: ob-test
clusterID: 1
# Optional
charset:
collate:
connectWhiteList: '%'
topology:
- zone: zone1
unitNum: 1
type:
name: FUll
replica: 1
priority: 3
resource:
maxCPU: 2500m
memorySize: 1Gi
# Optional
minCPU: 2
maxIops: 1024
minIops: 1024
# v3
maxDiskSize: 3Gi
maxSessionNum: 512
# v4
iopsWeight:
logDiskSize:
- zone: zone2
unitNum: 1
type:
name: Full
replica: 1
priority: 3
resource:
maxCPU: 2500m
memorySize: 1Gi
# Optional
minCPU: 2
maxIops: 1024
minIops: 1024
# v3
maxDiskSize: 1Gi
maxSessionNum: 64
# v4
iopsWeight: 2
logDiskSize: 4Gi
- zone: zone3
unitNum: 1
type:
name: Full
replica: 1
priority: 3
resource:
maxCPU: 2500m
memorySize: 1Gi
# Optional
minCPU: 2
maxIops: 1024
minIops: 1024
# v3
maxDiskSize: 1Gi
maxSessionNum: 64
# v4
iopsWeight: 2
logDiskSize: 4Gi
The following table describes the parameters.
| Parameter | Description |
|---|---|
| metadata.name | The name of the tenant. Like a variable, a tenant name can contain up to 128 characters, which can be letters, digits, and underscores (_). The tenant name must start with a letter or an underscore (_) and cannot be a keyword of OceanBase Database. For more information about the keywords supported by OceanBase Database, see Reserved keywords (MySQL mode) or Reserved keywords (Oracle mode). |
| metadata.namespace | The namespace where the tenant resides. This parameter is required. |
| clusterName | The name of the OceanBase cluster in which the tenant is to be created. This parameter is required. |
| clusterID | The ID of the OceanBase cluster in which the tenant is to be created. This parameter is required. |
| charset | The character set of the tenant. For more information about character sets, see Character sets. This parameter is optional and is set to utf8mb4 by default. |
| collate | The collation of the tenant. For more information about collations, see Collations. This parameter is optional. |
| connectWhiteList | The IP addresses of the clients that are allowed to connect to the tenant. % indicates that all client IP addresses are allowed to connect to the tenant. This parameter is optional. The default value is %. When you modify this parameter, the value must include the CIDR block of ob-operator; otherwise, ob-operator cannot connect to the tenant. |
| topology | The topology of the tenant, which defines the replica and resource distribution of the tenant in each zone. |
| zone | The name of an available zone. This parameter is required. |
| unitNum | The number of resource units to be created for the zone. The value must be less than the number of OBServer nodes in the zone. This parameter is required. |
| type.name | The type of replicas in the zone. The valid values are full, logonly, and readonly. This parameter is case insensitive and is required. |
| type.replica | The number of replicas in the zone. This parameter is optional and is set to 1 by default. |
| priority | The priority of the current zone. A larger number indicates a higher priority. This parameter is optional and is set to 0 by default. |
| resource | The resource information of the tenant in the zone. |
| maxCPU | The maximum number of CPU cores provided by a resource unit in the zone for the tenant. This parameter is required. The minimum value of this parameter is 1 for OceanBase Database V3.x and V4.x. |
| memorySize | The size of memory provided by a resource unit in the zone for the tenant. This parameter is required. The minimum value is 1Gi. |
| minCPU | The minimum number of CPU cores provided by a resource unit in the zone for the tenant. This parameter is optional and is equal to the value of the maxCPU parameter by default. |
| maxIops | The maximum I/O resources provided by a resource unit in the zone for the tenant. This parameter is optional. |
| minIops | The minimum I/O resources provided by a resource unit in the zone for the tenant. This parameter is optional. |
| maxDiskSize | The maximum size of disk space provided by a resource unit in the zone for the tenant. This parameter is optional and is required only in OceanBase Database V3.x. The default value is 512Mi. |
| maxSessionNum | The maximum number of sessions provided by a resource unit in the zone for the tenant. This parameter is optional and is required only in OceanBase Database V3.x. The default value is 64. |
| iopsWeight | The weight of the tenant for using I/O resources provided by a resource unit in the zone. This parameter is optional and is required only in OceanBase Database V4.x. The default value is 1. |
| logDiskSize | The size of log space provided by a resource unit in the zone for the tenant. This parameter is optional and is required only in OceanBase Database V4.x. The default value is three times the memory size. The minimum value is 2 GiB. |
Verify that the tenant is created
After the tenant creation process is completed, run the following command to check whether the current Kubernetes cluster contains the custom resource of the created tenant and whether the status of the custom resource is Running. The related configurations are displayed in the status section.
kubectl get tenant -A -o yaml
Here is an example of the returned result:
apiVersion: v1
items:
- apiVersion: cloud.oceanbase.com/v1
kind: Tenant
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"cloud.oceanbase.com/v1","kind":"Tenant","metadata":{"annotations":{},"name":"obtenant","namespace":"obcluster"},"spec":{"charset":null,"clusterID":1,"clusterName":"ob-test","collate":null,"connectWhiteList":"%","topology":[{"priority":3,"resource":{"iopsWeight":null,"logDiskSize":null,"maxCPU":"2500m","maxDiskSize":"3Gi","maxIops":1024,"maxSessionNum":512,"memorySize":"1Gi","minCPU":2,"minIops":1024},"type":{"name":"FUll","replica":1},"unitNum":1,"zone":"zone1"},{"priority":3,"resource":{"iopsWeight":2,"logDiskSize":"4Gi","maxCPU":"2500m","maxDiskSize":"1Gi","maxIops":1024,"maxSessionNum":64,"memorySize":"1Gi","minCPU":2,"minIops":1024},"type":{"name":"Full","replica":1},"unitNum":1,"zone":"zone2"},{"priority":3,"resource":{"iopsWeight":2,"logDiskSize":"4Gi","maxCPU":"2500m","maxDiskSize":"1Gi","maxIops":1024,"maxSessionNum":64,"memorySize":"1Gi","minCPU":2,"minIops":1024},"type":{"name":"Full","replica":1},"unitNum":1,"zone":"zone3"}]}}
creationTimestamp: "2023-04-03T12:38:15Z"
finalizers:
- cloud.oceanbase.com.finalizers.obtenant
generation: 2
name: obtenant
namespace: obcluster
resourceVersion: "3348758"
uid: 9710ab83-3457-4552-88aa-d25a26f2898d
spec:
clusterID: 1
clusterName: ob-test
connectWhiteList: '%'
...
status:
connectWhiteList: '%'
status: Running
...
kind: List
metadata:
resourceVersion: ""
What to do next
After a tenant is created, the password of the root account is empty by default. You can run the obclient -hxxx.xxx.xxx.xxx -P2883 -uusername@tenantname#clustername -p -A command to log on to the database and then change the password. For more information about how to change the password of a user, see ALTER USER.