This topic describes how to deploy ob-operator, deploy an OceanBase demo environment, create a test tenant, delete an OceanBase cluster, and delete ob-operator.
Prerequisites
You have prepared a Kubernetes cluster, and labeled at least one node ob.zone=test. The node has at least two CPU cores, 10 GB of memory, and 100 GB of storage space.
You can run the kubectl label node <node_name> ob.zone=test command to label nodes.
Deploy ob-operator
Deploy CRDs
Run the following command to deploy custom resource definitions (CRDs):
kubectl apply -f https://raw.githubusercontent.com/oceanbase/ob-operator/master/deploy/crd.yaml
Run the following command to view the CRDs:
kubectl get crds
The following output indicates that the CRDs are deployed.
backups.cloud.oceanbase.com 2023-06-16T11:02:15Z
obclusters.cloud.oceanbase.com 2023-06-16T11:02:15Z
obzones.cloud.oceanbase.com 2023-06-16T11:02:15Z
restores.cloud.oceanbase.com 2023-06-16T11:02:15Z
rootservices.cloud.oceanbase.com 2023-06-16T11:02:15Z
statefulapps.cloud.oceanbase.com 2023-06-16T11:02:15Z
tenantbackups.cloud.oceanbase.com 2023-06-16T11:02:15Z
tenants.cloud.oceanbase.com 2023-06-16T11:02:15Z
Deploy ob-operator
Run the following command to deploy ob-operator:
kubectl apply -f https://raw.githubusercontent.com/oceanbase/ob-operator/master/deploy/operator.yaml
Run the following command to check whether ob-operator is deployed:
kubectl get pods -n oceanbase-system
The returned result is as follows:
NAME READY STATUS RESTARTS AGE
ob-operator-controller-manager-78587645d-w7vbk 2/2 Running 0 18d
If READY:2/2,STATUS:Running is displayed, ob-operator is deployed successfully.
Deploy an OceanBase cluster
Create a test cluster
Run the following command to create a test cluster:
kubectl apply -f https://raw.githubusercontent.com/oceanbase/ob-operator/master/deploy/obcluster_mini.yaml
View the cluster deployment status
Run the following command to check whether the created cluster is deployed:
kubectl get obcluster ob-test -o yaml
If the status in the returned result is Ready, the cluster is deployed.
status:
status: Ready
topology:
- cluster: cn
clusterStatus: Ready
lastTransitionTime: "2023-07-12T08:46:16Z"
zone:
- availableReplicas: 1
expectedReplicas: 1
name: zone1
region: region1
zoneStatus: Ready
- availableReplicas: 1
expectedReplicas: 1
name: zone2
region: region1
zoneStatus: Ready
- availableReplicas: 1
expectedReplicas: 1
name: zone3
region: region1
zoneStatus: Ready
Test the connection to the cluster
Run the following command to obtain the endpoint of the cluster:
kubectl get svc svc-ob-test
The returned result is as follows:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
svc-ob-test ClusterIP xxx.xxx.xxx.xxx <none> 2881/TCP 41h
Use mysql to connect to the cluster.
mysql -hxxx.xxx.xxx.xxx -P2881 -uroot oceanbase -A -c
Note
The OceanBase cluster service is of the ClusterIP type, and you must establish a connection to the cluster from a Kubernetes node. If you want to remotely connect to the cluster, you must configure port forwarding.
For more information, see Create a cluster.
Create a tenant
Create a test tenant
Run the following command to create a test tenant:
kubectl apply -f https://raw.githubusercontent.com/oceanbase/ob-operator/master/deploy/obtenant_mini.yaml
View the tenant status
Run the following command to check whether the tenant is created:
kubectl get tenant obtenant -o yaml
If the status field in the status section is Running in the returned result, the tenant is deployed.
status:
connectWhiteList: '%'
status: Running
topology:
- priority: 2
resource:
logDiskSize: "3221225472"
maxCPU: 2500m
maxDiskSize: "0"
maxIops: 1024
memorySize: "1073741824"
minCPU: "1"
minIops: 1024
type:
name: FULL
replica: 1
unitNum: 1
units:
- migrate:
serverIP: ""
serverPort: 0
serverIP: xxx.xxx.xxx.xxx
serverPort: 2882
status: ACTIVE
unitId: 1001
zone: zone1
Connect to the tenant
After the tenant is created, run the following command to connect to the tenant:
mysql -hxxx.xxx.xxx.xxx -P2881 -uroot@obtenant oceanbase -A -c
For more information, see Create a tenant.
Delete an OceanBase cluster
Run the following command to delete an OceanBase cluster:
kubectl delete -f https://raw.githubusercontent.com/oceanbase/ob-operator/master/deploy/obcluster_mini.yaml
Run the following command to check whether the cluster is deleted:
kubectl get obcluster
The following result is returned. If no OceanBase cluster resources are found, the cluster is deleted.
No resources found in default namespace.
For more information, see Delete a cluster.
Delete ob-operator
Delete ob-operator
Run the following command to delete ob-operator:
kubectl delete -f https://raw.githubusercontent.com/oceanbase/ob-operator/master/deploy/operator.yaml
Run the following command to check whether ob-operator is deleted:
kubectl get pods -n oceanbase-system
If ob-operator is not found, it is deleted.
Delete CRDs
Run the following command to delete CRDs:
kubectl delete -f https://raw.githubusercontent.com/oceanbase/ob-operator/master/deploy/crd.yaml
Run the following command to check whether the CRDs are deleted:
kubectl get crds
If no resources are found under cloud.oceanbase.com, the CRDs are deleted.