Migrating OpenResty Edge Admin Database to Kubernetes

Before starting the migration process, please ensure that you have deployed the latest version of OpenResty Edge according to the documentation guide Deploying OpenResty Edge in Kubernetes.

Exporting the Current Database

Run the pg_dump command on the machine where the Edge Admin database is installed to export the database. Open a command line terminal and execute the following instruction:

/usr/local/openresty-postgresql12/bin/pg_dump or_edge_admin -C -U postgres | gzip > or_edge_admin-$(date +%F).gz

During execution, the system may prompt you to enter a password.

Transferring the Exported Database File to the Kubernetes Pod

Use the kubectl cp command to transfer the locally exported database file to a Kubernetes Pod:

kubectl cp or_edge_admin-$(date +%F).gz openresty-edge/oredge-admin-database-0:/tmp/or_edge_admin-$(date +%F).gz

Please note that openresty-edge is the namespace name where the OpenResty Edge service is located, and oredge-admin-database-0 is the name of the target Pod.

Importing the Database into the Kubernetes Pod

Next, enter the Pod and import the database using the psql command.

First, use the following command to enter the Pod:

kubectl exec -it oredge-admin-database-0 -n openresty-edge -- /bin/bash

Inside the Pod, delete all initial data from the existing database or_edge_admin (please back up any important data beforehand):

/usr/local/openresty-postgresql12/bin/psql -U or_edge_admin -d or_edge_admin --command 'DROP SCHEMA public CASCADE'

/usr/local/openresty-postgresql12/bin/psql -U or_edge_admin -d or_edge_admin --command 'CREATE SCHEMA public'

Then, in the Pod’s command line, start importing data using the psql command:

zcat /tmp/or_edge_admin-$(date +%F).gz | /usr/local/openresty-postgresql12/bin/psql -U or_edge_admin -d or_edge_admin

Wait patiently for the data import process to complete.

Updating the Edge Admin Database Schema to the Latest Version

Run the following commands to upgrade the database schema:

bash /docker-entrypoint-post.d/update-admin-db.sh

Recompiling OpenResty Edge Configuration

Log in to the Edge Admin Pod oredge-admin-0:

kubectl exec -it oredge-admin-0 -n openresty-edge -- /bin/bash

Execute the following commands to recompile the configuration of OpenResty Edge:

cd /usr/local/oredge-admin
sudo bash utils/recompile-apps.sh wildcard-http
sudo bash utils/recompile-apps.sh http
sudo bash utils/recompile-apps.sh http_proxy
sudo bash utils/recompile-apps.sh socks5_proxy
sudo bash utils/recompile-apps.sh global
sudo bash utils/recompile-apps.sh waf
sudo bash utils/recompile-apps.sh dns
sudo bash utils/recompile-apps.sh global-action
sudo bash utils/recompile-apps.sh gateway

After following the above steps, you should have successfully migrated the database data, integrating the OpenResty Edge Admin database into your Kubernetes cluster.