Skip to main content

Create a cluster

This topic describes how to create an OceanBase cluster by using ob-operator.

Preparations before deployment

You must have deployed ob-operator in a Kubernetes cluster. For more information, see Deploy ob-operator. Make sure that the Kubernetes cluster has an available storage class. We recommend that you use local-path-provisioner.

Deploy OceanBase Database

Create a namespace

Run the following command to create a namespace for deploying an OceanBase cluster.

kubectl create namespace oceanbase

Create secrets for default users

Run the following command to create secrets for specific users of the cluster.

kubectl create secret -n oceanbase generic root-password --from-literal=password='root_password'

Define the OceanBase cluster

You can use the YAML configuration file to define the OceanBase cluster. Here is an example:

apiVersion: oceanbase.oceanbase.com/v1alpha1
kind: OBCluster
metadata:
name: test
namespace: oceanbase
annotations:
"oceanbase.oceanbase.com/independent-pvc-lifecycle": "true"
# "oceanbase.oceanbase.com/mode": "standalone" or "service"
# "oceanbase.oceanbase.com/single-pvc": "true"
spec:
clusterName: obcluster
clusterId: 1
serviceAccount: "default"
userSecrets:
root: root-password
topology:
- zone: zone1
replica: 1
# nodeSelector:
# k1: v1
# affinity:
# nodeAffinity:
# podAffinity:
# podAntiAffinity:
# tolerations:
# - key: "obtopo"
# value: "zone"
# effect: "NoSchedule"
- zone: zone2
replica: 1
- zone: zone3
replica: 1
observer:
image: oceanbase/oceanbase-cloud-native:4.2.0.0-101000032023091319
resource:
cpu: 2
memory: 10Gi
storage:
dataStorage:
storageClass: local-path
size: 50Gi
redoLogStorage:
storageClass: local-path
size: 50Gi
logStorage:
storageClass: local-path
size: 20Gi
monitor:
image: oceanbase/obagent:4.2.0-100000062023080210
resource:
cpu: 1
memory: 1Gi

# parameters:
# - name: system_memory
# value: 2G
# backupVolume:
# volume:
# name: backup
# nfs:
# server: 1.1.1.1
# path: /opt/nfs
# readOnly: false

Parameters

The following table describes the parameters.

ParameterDescription
metadata.nameRequired. The name of the cluster, which is the name of resources in the Kubernetes cluster.
metadata.namespaceRequired. The namespace where the cluster resides.
spec.clusterNameRequired. The name of the OceanBase cluster.
spec.clusterIdRequired. The ID of the OceanBase cluster.
spec.serviceAccountOptional. The service account that will be bound to OBServer pods.
spec.userSecretsRequired. The secrets of default users of the OceanBase cluster.
spec.userSecrets.rootRequired. The secret of the root@sys user in the OceanBase cluster. The secret must contain the password keyword.
spec.userSecrets.proxyroOptional. The secret of the proxyro@sys user in the OceanBase cluster. The secret must contain the password keyword.
spec.userSecrets.monitorOptional. The secret of the monitor@sys user in the OceanBase cluster. The secret must contain the password keyword.
spec.userSecrets.operatorOptional. The secret of the operator@sys user in the OceanBase cluster. The secret must contain the password keyword.
spec.topologyRequired. The definition of the topology of the OceanBase cluster, which contains the definition of each zone.
spec.topology[i].zoneRequired. The name of the zone in the OceanBase cluster.
spec.topology[i].replicaRequired. The number of OBServer nodes in the zone.
spec.topology[i].nodeSelectorOptional. Specifies the distribution of pods across the OBServer nodes in the zone. The value is in the mapping format. This parameter must be used with the labels of OBServer nodes.
spec.topology[i].affinitySpecifies the affinity among the OBServer nodes in the zone. For more information, visit kubernetes.io.
spec.topology[i].tolerationsSpecifies the toleration of OBServer nodes in the zone. For more information, visit kubernetes.io.
spec.observer.imageRequired. The OBServer image of the OceanBase cluster.
spec.observer.resourceRequired. The resource specifications of OBServer nodes.
spec.observer.resource.cpuRequired. The number of CPU cores for OBServer nodes.
spec.observer.resource.memoryRequired. The memory size for OBServer nodes.
spec.observer.storageRequired. The storage size for OBServer nodes.
spec.observer.storage.dataStorageRequired. The data storage size for OBServer nodes.
spec.observer.storage.redoLogStorageRequired. The clog storage size for OBServer nodes.
spec.observer.storage.logStorageRequired. The runtime log storage size for OBServer nodes.
spec.observer.storage.*.storageClassOptional. The storage class required for creating a PersistentVolumeClaim (PVC). Set to default storageClass in kubernetes cluster if leaving it empty. This parameter takes effect on storage configurations.
spec.observer.storage.*.sizeRequired. The size of the created PVC. This parameter takes effect on storage configurations.
spec.monitorOptional. The monitoring configuration. We recommend that you enable this parameter. ob-operator uses obagent to collect monitoring data. You can connect ob-operator to Prometheus to monitor the status of the OceanBase cluster.
spec.monitor.imageRequired. The image used for monitoring.
spec.monitor.resourceRequired. The resources allocated to the monitoring container.
spec.monitor.resource.cpuRequired. The number of CPU cores allocated to the monitoring container.
spec.monitor.resource.memoryRequired. The memory size allocated to the monitoring container.
spec.parametersThe optional custom parameter of the OceanBase cluster. This parameter takes effect globally in the cluster.
spec.parameters[i].nameRequired. The name of the parameter.
spec.parameters[i].valueRequired. The value of the parameter.
spec.backupVolumeOptional. The backup storage for the OceanBase cluster. If you want to enable the backup feature and do not use Alibaba Cloud Object Storage Service (OSS) for backup storage, you need to specify this parameter. You can configure a Network File System (NFS) volume.

Annotations

The following table describes available annotations. For short, the annotation annotation implies there is an oceanbase.oceanbase.com/ in front of it.

AnnotationDescription
independent-pvc-lifecycletrue: Require ob-operator >= 2.1.1. PVCs won't be deleted even if the OBCluster is deleted.
modestandalone: Require ob-operator >= 2.1.1 and observer version >= 4.2.0. Bootstrap the single-node cluster with 127.0.0.1, which cannot contact other nodes any more.
service: Require ob-operator >= 2.2.0 and observer version >= 4.2.1.4 excepting 4.2.2.x. Create a specific K8s service for each OBServer and use the service's ClusterIP as the OBServer's IP address.
single-pvctrue: Require ob-operator >= 2.1.2. Create and bind a single PVC to a OBServer pod (three PVCs by default).

Create a cluster

After you save the configuration file, run the following command to create an OceanBase cluster in the Kubernetes cluster:

kubectl apply -f obcluster.yaml

In general, it takes about 2 minutes to create a cluster. Run the following command to query the cluster status. If the cluster status changes to Running, the cluster is created.

kubectl get obclusters.oceanbase.oceanbase.com test -n oceanbase

# desired output
NAME STATUS AGE
test running 6m2s

Connect to the cluster

Run the following command to obtain the IP address of the pod for the server where the cluster is deployed. The pod name is in the {cluster_name}-{cluster_id}-{zone}-uuid format.

kubectl get pods -n oceanbase -o wide

Run the following command to connect to the pod:

mysql -h{POD_IP} -P2881 -uroot -proot_password oceanbase -A -c

What to do next

After the cluster is created, you must create a tenant for your business. For more information, see Manage tenants.