Skip to main content

Create a tenant

This topic describes how to create a tenant by using ob-operator.

Prerequisites

Before you create a tenant, make sure the following conditions are met:

  • You have deployed ob-operator V2.1.0 or later.

  • You have deployed an OceanBase cluster, which is running normally.

Create a tenant by using the configuration file

You can create a tenant by using the configuration file of the tenant. For more information about the configuration file, visit GitHub.

Run the following command to create a tenant. This command creates an OceanBase Database tenant with custom resources in the current Kubernetes cluster.

kubectl apply -f tenant.yaml

Example

Create a MySQL tenant named t1 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 pools 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: oceanbase.oceanbase.com/v1alpha1  
kind: OBTenant
metadata:
name: t1
namespace: oceanbase
spec:
obcluster: obcluster
tenantName: t1
unitNum: 1
charset: utf8mb4
connectWhiteList: '%'
forceDelete: true
credentials: # optional
root: t1-ro # optional, empty root password if not given
standbyRo: t1-ro # optional, generate automatically if not given
pools:
- zone: zone1
type:
name: Full
replica: 1
isActive: true
resource:
maxCPU: 1
minCPU: 1
memorySize: 5Gi
maxIops: 1024
minIops: 1024
iopsWeight: 2
logDiskSize: 12Gi
- zone: zone2
type:
name: Full
replica: 1
isActive: true
resource:
maxCPU: 1
minCPU: 1
memorySize: 5Gi
maxIops: 1024
minIops: 1024
iopsWeight: 2
logDiskSize: 12Gi
- zone: zone3
type:
name: Full
replica: 1
isActive: true
priority: 3
resource:
maxCPU: 1
minCPU: 1
memorySize: 5Gi
maxIops: 1024
minIops: 1024
iopsWeight: 2
logDiskSize: 12Gi

The following table describes the parameters.

ParameterDescription
metadata.nameRequired. The name of the tenant resource, which must be unique in the same namespace of the Kubernetes cluster.
metadata.namespaceRequired. The namespace where the tenant resources are located.
obclusterRequired. The name of the OceanBase cluster in which the tenant is to be created.
tenantNameRequired. 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).
unitNumRequired. 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.
charsetOptional. The character set of the tenant. For more information about character sets, see Character sets. This parameter is set to utf8mb4 by default.
collateOptional. The collation of the tenant. For more information about collations, see Collations.
connectWhiteListOptional. 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. 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.
forceDeleteOptional. Specifies whether to forcibly delete the tenant. The default value is false.
credentialsOptional. The secret resources referenced for creating the user and changing the password when you create the tenant. You can specify the passwords of the root account and the standbyro account. If you do not specify this parameter, the password is not changed.
poolsThe topology of the tenant, which defines the replica and resource distribution of the tenant in each zone.
type.nameRequired. The type of replicas in the zone. The valid values are full and readonly. This parameter is case insensitive.
type.replicaOptional. The number of replicas in the zone. This parameter is set to 1 by default.
type.isActiveSpecifies whether to enable the zone.
priorityOptional. The priority of the current zone. A larger number indicates a higher priority. This parameter is set to 0 by default.
resourceThe resource information of the tenant in the zone.
maxCPURequired. The maximum number of CPU cores provided by a resource unit in the zone for the tenant. The minimum value is 1.
minCPUOptional. The minimum number of CPU cores provided by a resource unit in the zone for the tenant. This parameter is equal to the value of the maxCPU parameter by default.
memorySizeRequired. The size of memory provided by a resource unit in the zone for the tenant. The minimum value is 1GB. Take note of the value of the cluster parameter __min_full_resource_pool_memory when you specify this parameter.
maxIopsOptional. The maximum I/O resources provided by a resource unit in the zone for the tenant.
minIopsOptional. The minimum I/O resources provided by a resource unit in the zone for the tenant.
iopsWeightOptional. The weight of the tenant for using I/O resources provided by a resource unit in the zone. The default value is 1.
logDiskSizeOptional. The size of log space provided by a resource unit in the zone for the tenant. The default value is three times the memory size. The minimum value is 2Gi.

Verify whether 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 resources of the created tenant and whether the status of the custom resource is Running. The related configurations are displayed in the status section.

kubectl describe obtenants.oceanbase.oceanbase.com -n oceanbase t1

Here is a sample result:

Name:         t1
Namespace: oceanbase
Labels: <none>
Annotations: <none>
API Version: oceanbase.oceanbase.com/v1alpha1
Kind: OBTenant
Metadata:
Creation Timestamp: 2023-11-13T07:28:31Z
Finalizers:
finalizers.oceanbase.com.deleteobtenant
Generation: 2
Resource Version: 940236
UID: 34036a49-26bf-47cf-8201-444b3850aaa2
Spec:
Charset: utf8mb4
Connect White List: %
Credentials:
Root: t1-ro
Standby Ro: t1-ro
Force Delete: true
Obcluster: obcluster
Pools:
Priority: 1
Resource:
Iops Weight: 2
Log Disk Size: 12Gi
Max CPU: 1
Max Iops: 1024
Memory Size: 5Gi
Min CPU: 1
Min Iops: 1024
Type:
Is Active: true
Name: Full
Replica: 1
Zone: zone1
Priority: 1
Resource:
Iops Weight: 2
Log Disk Size: 12Gi
Max CPU: 1
Max Iops: 1024
Memory Size: 5Gi
Min CPU: 1
Min Iops: 1024
Type:
Is Active: true
Name: Full
Replica: 1
Zone: zone2
Priority: 3
Resource:
Iops Weight: 2
Log Disk Size: 12Gi
Max CPU: 1
Max Iops: 1024
Memory Size: 5Gi
Min CPU: 1
Min Iops: 1024
Type:
Is Active: true
Name: Full
Replica: 1
Zone: zone3
Tenant Name: t1
Tenant Role: PRIMARY
Unit Num: 1
Status:
Credentials:
Root: t1-ro
Standby Ro: t1-ro
Resource Pool:
Priority: 1
Type:
Is Active: true
Name: FULL
Replica: 1
Unit Config:
Iops Weight: 2
Log Disk Size: 12884901888
Max CPU: 1
Max Iops: 1024
Memory Size: 5368709120
Min CPU: 1
Min Iops: 1024
Unit Num: 1
Units:
Migrate:
Server IP:
Server Port: 0
Server IP: 10.42.0.189
Server Port: 2882
Status: ACTIVE
Unit Id: 1006
Zone List: zone1
Priority: 1
Type:
Is Active: true
Name: FULL
Replica: 1
Unit Config:
Iops Weight: 2
Log Disk Size: 12884901888
Max CPU: 1
Max Iops: 1024
Memory Size: 5368709120
Min CPU: 1
Min Iops: 1024
Unit Num: 1
Units:
Migrate:
Server IP:
Server Port: 0
Server IP: 10.42.1.118
Server Port: 2882
Status: ACTIVE
Unit Id: 1007
Zone List: zone2
Priority: 2
Type:
Is Active: true
Name: FULL
Replica: 1
Unit Config:
Iops Weight: 2
Log Disk Size: 12884901888
Max CPU: 1
Max Iops: 1024
Memory Size: 5368709120
Min CPU: 1
Min Iops: 1024
Unit Num: 1
Units:
Migrate:
Server IP:
Server Port: 0
Server IP: 10.42.0.190
Server Port: 2882
Status: ACTIVE
Unit Id: 1008
Zone List: zone3
Status: running
Tenant Record Info:
Charset: utf8mb4
Connect White List: %
Locality: FULL{1}@zone1, FULL{1}@zone2, FULL{1}@zone3
Pool List: pool_t1_zone1,pool_t1_zone2,pool_t1_zone3
Primary Zone: zone3;zone1,zone2
Tenant ID: 1006
Unit Num: 1
Zone List: zone1,zone2,zone3
Tenant Role: PRIMARY
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal 2m58s obtenant-controller start creating
Normal 115s obtenant-controller create OBTenant successfully

What to do next

After the tenant is created, the password of its administrator account is the value of secret specified in the spec.credentials.root field. If you have not specified the secret field, the password is empty. You can use the obclient -h${podIP} -P2881 -uroot@tenantname -p -A or mysql -h${podIP} -P2881 -uroot@tenantname -p -A statement to log on to the database.