Skip to main content

Deploy OceanBase Database and web app in a Kubernetes cluster

This topic describes how to deploy OceanBase Database, related components, and applications in a Kubernetes cluster by using a real-world example.

Prerequisites

Before you start the deployment, make sure that you have deployed cert-manager, local-path-provisioner, and ob-operator in your Kubernetes cluster.

In this example, the following components are deployed:

  • OceanBase Database.
  • ob-configserver, which is used to register the IP address of the RootService server for OceanBase Database.
  • OceanBase Database Proxy (ODP), the proxy of OceanBase Database.
  • OceanBase Todo List. An extremely simple web application taken as an example to describe how to deploy web applications and use OceanBase cluster as backend database in the Kubernetes cluster.
  • Prometheus, the monitoring and alerting system that collects and calculates the monitoring metrics of OceanBase Database.
  • Grafana, the data visualization system. You can connect Grafana to Prometheus to display the monitoring data of OceanBase Database.

Preparations before deployment

Create a namespace:

kubectl apply -f https://raw.githubusercontent.com/oceanbase/ob-operator/stable/example/webapp/namespace.yaml

View the created namespace:

kubectl get namespace oceanbase

The following output indicates that the namespace is created:

NAME        STATUS   AGE
oceanbase Active 98s

Create secrets for the cluster and tenants:

kubectl apply -f https://raw.githubusercontent.com/oceanbase/ob-operator/stable/example/webapp/secret.yaml

View the created secrets:

kubectl get secret -n oceanbase

The following output indicates that the secrets are created:

NAME                      TYPE                                  DATA   AGE
sc-metatenant-root Opaque 1 11s
sc-metatenant-standbyro Opaque 1 11s
sc-sys-monitor Opaque 1 11s
sc-sys-operator Opaque 1 11s
sc-sys-proxyro Opaque 1 11s
sc-sys-root Opaque 1 11s

Deploy ob-configserver

ob-configserver allows you to register, store, and query metadata of the RootService server for OceanBase Database. The supported metadata storage types are sqlite3 and mysql. In this example, sqlite3 is used. Run the following command to deploy ob-configserver and create the corresponding service:

kubectl apply -f https://raw.githubusercontent.com/oceanbase/ob-operator/stable/example/webapp/configserver.yaml

Check the pod status:

kubectl get pods -n oceanbase | grep ob-configserver

# desired output
ob-configserver-856bf5d865-dlwxr 1/1 Running 0 16s

Check the svc status:

kubectl get svc svc-ob-configserver -n oceanbase

# desired output
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
svc-ob-configserver NodePort 10.96.3.39 <none> 8080:30080/TCP 98s

Deploy an OceanBase cluster

When you deploy an OceanBase cluster, add environment variables and set the system parameter obconfig_url to the IP address of ob-configserver service. OceanBase Database will register the information of RootService with ob-configserver. Deploy the OceanBase cluster:

kubectl apply -f https://raw.githubusercontent.com/oceanbase/ob-operator/stable/example/webapp/obcluster.yaml

Run the following command to query the status of the OceanBase cluster until the status becomes running:

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

# desired output
NAME STATUS AGE
metadb running 3m21s

Deploy ODP

You can start ODP by using ob-configserver or specifying the RS list. To maximize the performance of ODP, we recommend that you connect ODP to the cluster by using ob-configserver.

Run the following command to deploy ODP and create the ODP service:

kubectl apply -f https://raw.githubusercontent.com/oceanbase/ob-operator/stable/example/webapp/obproxy.yaml

When you query the pod status of ODP, you can see two ODP pods.

kubectl get pod -A | grep obproxy

# desired output
oceanbase obproxy-5cb8f4d975-pmr59 1/1 Running 0 21s
oceanbase obproxy-5cb8f4d975-xlvjp 1/1 Running 0 21s

View information about the ODP service:

kubectl get svc svc-obproxy -n oceanbase

# desired output
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
svc-obproxy ClusterIP 10.96.2.46 <none> 2883/TCP,2884/TCP 2m26s

Connect to the OceanBase cluster by using the IP address of the ODP service:

mysql -h${obproxy-service-address} -P2883 -uroot@sys#metadb -p

If the OceanBase cluster is connected, the ODP service is normal.

connection

If the cluster not exist message is returned, it indicates that the OceanBase cluster has not registered the cluster metadata with ob-configserver. Try again later. You can view the registration result by using the curl "http://127.0.0.1:30080/services?Action=ObRootServiceInfo&ObCluster=metadb" statement. If the RsList parameter is not empty in the response, the cluster metadata is registered.

Deploy applications

Create a tenant

You can create a dedicated tenant for each type of business for better resource isolation. In this example, one tenant is created.

Run the following command to create a tenant:

kubectl apply -f https://raw.githubusercontent.com/oceanbase/ob-operator/stable/example/webapp/tenant.yaml

Run the following command to query the status of the tenant until the status becomes running:

kubectl get obtenants.oceanbase.oceanbase.com metatenant -n oceanbase
NAME STATUS TENANTNAME TENANTROLE CLUSTERNAME AGE
metatenant running metatenant PRIMARY metadb 106s

Run the following command to verify that the tenant can be connected:

mysql -h${obproxy-service-address} -P2883 -uroot@metatenant#metadb -p

If the tenant is connected, you can use it.

Deploy an application

OceanBase Todo List is an extremely simple web application taken as an example to describe how to deploy web applications and use OceanBase cluster as backend database in the Kubernetes cluster.

Run the following command to create databases first:

# Connect to the tenant
mysql -h${obproxy-service-address} -P2883 -uroot@metatenant#metadb -p

# Create dev database
create database dev;

Run the following command to deploy the application:

kubectl apply -f https://raw.githubusercontent.com/oceanbase/ob-operator/stable/example/webapp/oceanbase-todo.yaml

After the deployment process is completed, run the following command to view the application status:

# Check the pod
kubectl get pods -n oceanbase | grep oceanbase-todo
oceanbase-todo-746c7ff78f-49dxv 1/1 Running 0 12m
oceanbase-todo-746c7ff78f-4875t 1/1 Running 0 12m

# Check service
kubectl get svc svc-oceanbase-todo -n oceanbase
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
svc-oceanbase-todo NodePort 10.43.39.231 <none> 20031:32080/TCP 12m

An application provides service a while after it is deployed. You can access the application by using the service address.

# Check service with the following command:
curl 'http://${service_ip}:${service_port}'

# Take Cluster IP 10.43.39.231 as an example
curl http://10.43.39.231:20031
# Desired output is as follows:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/png" href="/logo.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>OceanBase Todo List</title>
<script type="module" crossorigin src="/assets/index-DHbyEFSo.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-B8po_uIp.css">
</head>
<body>
<div id="root"></div>
</body>
</html>

If you want to access the application from the Internet, you can use service of type NodePort to expose the application at a port on the K8s node. The NodePort is 32080 in this example. You can access the application on address: http://${node_ip}:32080.

Deploy the monitoring system

Deploy Prometheus

When you deploy the OceanBase cluster, an OBAgent sidecar container is created in each pod to provide monitoring data over the Prometheus protocol. A service is also created to automatically identify the IP address of OBAgent to collect data with the service discovery feature enabled.

Run the following command to deploy Prometheus:

kubectl apply -f https://raw.githubusercontent.com/oceanbase/ob-operator/stable/example/webapp/prometheus.yaml

Run the following command to view the deployment status:

# check pod status
kubectl get pods -n oceanbase | grep prometheus
prometheus-576d7757b9-jsvfh 1/1 Running 0 3m17s

# check service status
kubectl get svc svc-prometheus -n oceanbase
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
svc-prometheus NodePort 10.96.1.212 <none> 9090:30090/TCP 3m45s

Deploy Grafana

Grafana displays the metrics of OceanBase Database by using Prometheus as a data source. Run the following command to deploy Grafana:

kubectl apply -f https://raw.githubusercontent.com/oceanbase/ob-operator/stable/example/webapp/grafana.yaml

Run the following command to view the deployment status:

# check pod status
kubectl get pods -n oceanbase | grep grafana
grafana-b7c6c6ccb-dkv57 1/1 Running 0 2m

# check service status
kubectl get svc svc-grafana -n oceanbase
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
svc-grafana NodePort 10.96.2.145 <none> 3000:30030/TCP 2m

Open a browser and visit the service address to view the monitoring metrics of OceanBase Database.

Grafana

Summary

This topic describes how to deploy OceanBase Database and related components such as ODP and ob-configserver, applications, and the monitoring system. You can deploy other applications based on the example.

Note

You can find all configuration files used in this topic in the webapp directory.