Create a cluster

2025-11-28 06:07:04  Updated

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.

Parameter Description
metadata.name Required. The name of the cluster, which is the name of resources in the Kubernetes cluster.
metadata.namespace Required. The namespace where the cluster resides.
spec.clusterName Required. The name of the OceanBase cluster.
spec.clusterId Required. The ID of the OceanBase cluster.
spec.serviceAccount Optional. The service account that will be bound to OBServer pods.
spec.userSecrets Required. The secrets of default users of the OceanBase cluster.
spec.userSecrets.root Required. The secret of the root@sys user in the OceanBase cluster. The secret must contain the password keyword.
spec.userSecrets.proxyro Optional. The secret of the proxyro@sys user in the OceanBase cluster. The secret must contain the password keyword.
spec.userSecrets.monitor Optional. The secret of the monitor@sys user in the OceanBase cluster. The secret must contain the password keyword.
spec.userSecrets.operator Optional. The secret of the operator@sys user in the OceanBase cluster. The secret must contain the password keyword.
spec.topology Required. The definition of the topology of the OceanBase cluster, which contains the definition of each zone.
spec.topology[i].zone Required. The name of the zone in the OceanBase cluster.
spec.topology[i].replica Required. The number of OBServer nodes in the zone.
spec.topology[i].nodeSelector Optional. 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].affinity Specifies the affinity among the OBServer nodes in the zone. For more information, visit kubernetes.io.
spec.topology[i].tolerations Specifies the toleration of OBServer nodes in the zone. For more information, visit kubernetes.io.
spec.observer.image Required. The OBServer image of the OceanBase cluster.
spec.observer.resource Required. The resource specifications of OBServer nodes.
spec.observer.resource.cpu Required. The number of CPU cores for OBServer nodes.
spec.observer.resource.memory Required. The memory size for OBServer nodes.
spec.observer.storage Required. The storage size for OBServer nodes.
spec.observer.storage.dataStorage Required. The data storage size for OBServer nodes.
spec.observer.storage.redoLogStorage Required. The clog storage size for OBServer nodes.
spec.observer.storage.logStorage Required. The runtime log storage size for OBServer nodes.
spec.observer.storage.*.storageClass Optional. 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.*.size Required. The size of the created PVC. This parameter takes effect on storage configurations.
spec.monitor Optional. 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.image Required. The image used for monitoring.
spec.monitor.resource Required. The resources allocated to the monitoring container.
spec.monitor.resource.cpu Required. The number of CPU cores allocated to the monitoring container.
spec.monitor.resource.memory Required. The memory size allocated to the monitoring container.
spec.parameters The optional custom parameter of the OceanBase cluster. This parameter takes effect globally in the cluster.
spec.parameters[i].name Required. The name of the parameter.
spec.parameters[i].value Required. The value of the parameter.
spec.backupVolume Optional. 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.

Annotation Description
independent-pvc-lifecycle true: Require ob-operator >= 2.1.1. PVCs won't be deleted even if the OBCluster is deleted.
mode standalone: 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-pvc true: 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.

Contact Us