oceanbase-ce
by apecloud
OceanBase has served over 400 customers across the globe and has been supporting all mission critical systems in Alipay.
About this chart
OceanBase
OceanBase Database is an enterprise-level native distributed database independently developed by Ant Group.[^2]
Features In KubeBlocks
Lifecycle Management
| Topology | Horizontalscaling | Vertical scaling | Expandvolume | Restart | Stop/Start | Configure | Expose | Switchover |
|---|---|---|---|---|---|---|---|---|
| distribution | Yes | Yes | No | Yes | Yes | Yes | Yes | N/A |
Backup and Restore
| Feature | Method | Description |
|---|---|---|
| Backup [^1] | full | Backs up all macro-blocks. |
| Restore | full | Restore a new cluster from a full backup. |
Versions
| Service Version | Description |
|---|---|
| 4.3.5 | OceanBase CE 4.3.5 LTS (oceanbase/oceanbase-ce:4.3.5-lts) |
| 4.2.5 | OceanBase CE 4.2.5 LTS (oceanbase/oceanbase-ce:4.2.5-lts) |
| 4.2.1 | OceanBase CE 4.2.1 LTS (oceanbase/oceanbase-ce:4.2.1-lts) |
Prerequisites
-
Kubernetes cluster >= v1.21
-
kubectlinstalled, refer to K8s Install Tools -
Helm, refer to Installing Helm
-
KubeBlocks installed and running, refer to Install Kubeblocks
-
OceanBase CE Addon Enabled, refer to Install Addons
-
Create K8s Namespace
demo, to keep resources created in this tutorial isolated:kubectl create ns demo
Examples
Create
Create a distributed oceanbase cluster
# cat examples/oceanbase-ce/cluster.yaml
apiVersion: apps.kubeblocks.io/v1
kind: Cluster
metadata:
name: ob-cluster
namespace: demo
spec:
# Specifies the behavior when a Cluster is deleted.
# Valid options are: [DoNotTerminate, Delete, WipeOut] (`Halt` is deprecated since KB 0.9)
# - `DoNotTerminate`: Prevents deletion of the Cluster. This policy ensures that all resources remain intact.
# - `Delete`: Extends the `Halt` policy by also removing PVCs, leading to a thorough cleanup while removing all persistent data.
# - `WipeOut`: An aggressive policy that deletes all Cluster resources, including volume snapshots and backups in external storage. This results in complete data removal and should be used cautiously, primarily in non-production environments to avoid irreversible data loss.
terminationPolicy: Delete
# Specifies the name of the ClusterDefinition to use when creating a Cluster.
# Note: DO NOT UPDATE THIS FIELD
# The value must be `oceanbase-ce` to create a OceanBase Cluster
clusterDef: oceanbase-ce
# Specifies the name of the ClusterTopology to be used when creating the
# Cluster.
# Valid options are: [distribution]
topology: distribution
# Specifies a list of ClusterComponentSpec objects used to define the
# individual Components that make up a Cluster.
# This field allows for detailed configuration of each Component within the Cluster
componentSpecs:
- name: oceanbase
# ServiceVersion specifies the version of the Service expected to be
# provisioned by this Component.
# Valid options are: [4.3.5, 4.2.5, 4.2.1]
serviceVersion: 4.3.5
# Determines whether metrics exporter information is annotated on the
# Component's headless Service.
# Valid options are [true, false]
disableExporter: false
# List of environment variables to add.
# These environment variables will be placed AFTER the environment variables
# declared in the Pod.
# Some engine specific ENVs can be define here.
env:
- name: ZONE_COUNT # number of zones, default to 3, immutable
value: "1"
- name: OB_CLUSTER_ID # set cluster_id of observer, default to 1, immutable
value: "1"
# Specifies the desired number of replicas in the Component
replicas: 1
# Specifies the resources required by the Component
resources:
limits:
cpu: "3"
memory: "4Gi"
requests:
cpu: "3"
memory: "4Gi"
volumeClaimTemplates:
# Refers to the name of a volumeMount defined in
# `componentDefinition.spec.runtime.containers[*].volumeMounts
- name: data-file # data-file for sstable, slog, sort_dir, etc
spec:
# The name of the StorageClass required by the claim.
# If not specified, the StorageClass annotated with
# `storageclass.kubernetes.io/is-default-class=true` will be used.
storageClassName: ""
accessModes:
- ReadWriteOnce
resources:
requests:
storage: "50Gi"
- name: data-log # data-log for clog, ilog
spec:
storageClassName: ""
accessModes:
- ReadWriteOnce
resources:
requests:
storage: "50Gi"
- name: log # log for running logs, observer.log, rootservice.log
spec:
storageClassName: ""
accessModes:
- ReadWriteOnce
resources:
requests:
storage: "20Gi"
- name: workdir # workdir for working directory, to save some meta and folder info
spec:
storageClassName: ""
accessModes:
- ReadWriteOnce
resources:
requests:
storage: "1Gi"
kubectl apply -f examples/oceanbase-ce/cluster.yaml
Optionally, you can create a cluster using HostNetwork mode, by turning on the feature-gate. And KubeBlocks will allocate AVAILABLE ports for the components. Details can be found in file Create HostNetwork.
# snippets of cluster-hostnetwork.yaml
apiVersion: apps.kubeblocks.io/v1
kind: Cluster
metadata:
annotations:
# `kubeblocks.io/host-network` is a reserved annotation
# it defines the feature gate to enable the host-network for specified components or shardings.
kubeblocks.io/host-network: "oceanbase"
spec:
Horizontal scaling
Scale-out
Horizontal scaling out the cluster by adding ONE more replica:
# cat examples/oceanbase-ce/scale-out.yaml
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
name: ob-scale-out
namespace: demo
spec:
# Specifies the name of the Cluster resource that this operation is targeting.
clusterName: ob-cluster
type: HorizontalScaling
# Lists HorizontalScaling objects, each specifying scaling requirements for a Component, including desired total replica counts, configurations for new instances, modifications for existing instances, and instance downscaling options
horizontalScaling:
# Specifies the name of the Component.
- componentName: oceanbase
# Specifies the replica changes for scaling in components
scaleOut:
# Specifies the replica changes for the component.
# add one more replica to current component
replicaChanges: 1
kubectl apply -f examples/oceanbase-ce/scale-out.yaml
After applying the operation, you will see a new pod created and the cluster status goes from Updating to Running.
And you can check the progress of the scaling operation with following command:
kubectl describe -n demo ops ob-scale-out
The newly added replica will be in Pending status, and it will be in Running status after the operation is completed. By checking the logs of the POD, you can see the progress of the scaling operation.
kubectl logs -f <pod-name> -n demo
And you will see the logs once the new replica is added to the cluster.
| Wait for the server to be ready...
│ Add the server to zone successfully
│ Cluster starts successfully
Scale-in
Horizontal scaling in the cluster by removing ONE replica:
# cat examples/oceanbase-ce/scale-in.yaml
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
name: ob-scale-in
namespace: demo
spec:
# Specifies the name of the Cluster resource that this operation is targeting.
clusterName: ob-cluster
type: HorizontalScaling
# Lists HorizontalScaling objects, each specifying scaling requirements for a Component, including desired total replica counts, configurations for new instances, modifications for existing instances, and instance downscaling options
horizontalScaling:
# Specifies the name of the Component.
- componentName: oceanbase
# Specifies the replica changes for scaling in components
scaleIn:
# Specifies the replica changes for the component.
# add one more replica to current component
replicaChanges: 1
kubectl apply -f examples/oceanbase-ce/scale-in.yaml
Scale-in/out using Cluster API
Alternatively, you can update the replicas field in the spec.componentSpecs.replicas section to your desired non-zero number.
# snippet of cluster.yaml
apiVersion: apps.kubeblocks.io/v1
kind: Cluster
spec:
componentSpecs:
- name: oceanbase
serviceVersion: "4.3.5"
disableExporter: false
replicas: 3 # increase `replicas` for scaling in, and decrease for scaling out
Vertical scaling
Vertical scaling involves increasing or decreasing resources to an existing database cluster. Resources that can be scaled include:, CPU cores/processing power and Memory (RAM).
To vertical scaling up or down specified component, you can apply the following yaml file:
# cat examples/oceanbase-ce/verticalscale.yaml
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
name: ob-verticalscaling
namespace: demo
spec:
# Specifies the name of the Cluster resource that this operation is targeting.
clusterName: ob-cluster
type: VerticalScaling
# Lists VerticalScaling objects, each specifying a component and its desired compute resources for vertical scaling.
verticalScaling:
- componentName: oceanbase
# VerticalScaling refers to the process of adjusting the compute resources (e.g., CPU, memory) allocated to a Component. It defines the parameters required for the operation.
requests:
cpu: '4'
memory: 6Gi
limits:
cpu: '4'
memory: 6Gi
kubectl apply -f examples/oceanbase-ce/verticalscale.yaml
Scale-up/down using Cluster API
Alternatively, you may update spec.componentSpecs.resources field to the desired resources for vertical scale.
# snippet of cluster.yaml
apiVersion: apps.kubeblocks.io/v1
kind: Cluster
spec:
componentSpecs:
- name: oceanbase
replicas: 1
resources:
requests:
cpu: "4" # Update the resources to your need.
memory: 6Gi" # Update the resources to your need.
limits:
cpu: "4" # Update the resources to your need.
memory: "6Gi" # Update the resources to your need.
Restart
Restart the specified components in the cluster, and instances will be recreated on after another to ensure the availability of the cluster
# cat examples/oceanbase-ce/restart.yaml
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
name: ob-restart
namespace: demo
spec:
# Specifies the name of the Cluster resource that this operation is targeting.
clusterName: ob-cluster
type: Restart
# Lists Components to be restarted. ComponentOps specifies the Component to be operated on.
restart:
# Specifies the name of the Component.
- componentName: oceanbase
kubectl apply -f examples/oceanbase-ce/restart.yaml
Stop
Stop the cluster will release all the pods of the cluster, but the storage will be retained. It is useful when you want to save the cost of the cluster.
# cat examples/oceanbase-ce/stop.yaml
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
name: ob-stop
namespace: demo
spec:
# Specifies the name of the Cluster resource that this operation is targeting.
clusterName: ob-cluster
type: Stop
kubectl apply -f examples/oceanbase-ce/stop.yaml
Stop using Cluster API
Alternatively, you may stop the cluster by setting the spec.componentSpecs.stop field to true.
# snippet of cluster.yaml
apiVersion: apps.kubeblocks.io/v1
kind: Cluster
spec:
componentSpecs:
- name: oceanbase
stop: true # set stop `true` to stop the component
replicas: 1
Start
Start the stopped cluster
# cat examples/oceanbase-ce/start.yaml
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
name: ob-start
namespace: demo
spec:
# Specifies the name of the Cluster resource that this operation is targeting.
clusterName: ob-cluster
type: Start
kubectl apply -f examples/oceanbase-ce/start.yaml
Start using Cluster API
Alternatively, you may start the cluster by setting the spec.componentSpecs.stop field to false.
# snippet of cluster.yaml
apiVersion: apps.kubeblocks.io/v1
kind: Cluster
spec:
componentSpecs:
- name: oceanbase
stop: false # set to `false` (or remove this field) to start the component
replicas: 1
Reconfigure
A database reconfiguration is the process of modifying database parameters, settings, or configurations to improve performance, security, or availability. The reconfiguration can be either:
- Dynamic: Applied without restart
- Static: Requires database restart
Reconfigure parameters with the specified components in the cluster
# cat examples/oceanbase-ce/configure.yaml
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
name: ob-reconfiguring
namespace: demo
spec:
# Specif
Deploy oceanbase-ce with OpenTenant
Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has oceanbase-ce on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.
- Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
- Place the chartoceanbase-ce is pinned at v1.2.0-alpha.0 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
- ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below opentenant validate opentenant.yaml terraform init && terraform apply