Science and technology

Migrate databases to Kubernetes utilizing Konveyor

Kubernetes Database Operator is beneficial for constructing scalable database servers as a database (DB) cluster. But as a result of it’s important to create new artifacts expressed as YAML recordsdata, migrating present databases to Kubernetes requires numerous guide effort. This article introduces a brand new open supply instrument named Konveyor Tackle-DiVA-DOA (Data-intensive Validity Analyzer-Database Operator Adaptation). It routinely generates deployment-ready artifacts for database operator migration. And it does that by means of datacentric code evaluation.

What is Tackle-DiVA-DOA?

Tackle-DiVA-DOA (DOA, for brief) is an open supply datacentric database configuration analytics instrument in Konveyor Tackle. It imports goal database configuration recordsdata (resembling SQL and XML) and generates a set of Kubernetes artifacts for database migration to operators resembling Zalando Postgres Operator.

(Yasuharu Katsuno and Shin Saito, CC BY-SA 4.0)

DOA finds and analyzes the settings of an present system that makes use of a database administration system (DBMS). Then it generates manifests (YAML recordsdata) of Kubernetes and the Postgres operator for deploying an equal DB cluster.

(Yasuharu Katsuno and Shin Saito, CC BY-SA 4.0)

Database settings of an utility encompass DBMS configurations, SQL recordsdata, DB initialization scripts, and program codes to entry the DB.

  • DBMS configurations embrace parameters of DBMS, cluster configuration, and credentials. DOA shops the configuration to postgres.yaml and secrets and techniques to secret-db.yaml in case you want customized credentials.
     
  • SQL recordsdata are used to outline and initialize tables, views, and different entities within the database. These are saved within the Kubernetes ConfigMap definition cm-sqls.yaml.
     
  • Database initialization scripts usually create databases and schema and grant customers entry to the DB entities in order that SQL recordsdata work accurately. DOA tries to search out initialization necessities from scripts and paperwork or guesses if it may possibly’t. The outcome may also be saved in a ConfigMap named cm-init-db.yaml.
     
  • Code to entry the database, resembling host and database title, is in some circumstances embedded in program code. These are rewritten to work with the migrated DB cluster.

Tutorial

DOA is anticipated to run inside a container and comes with a script to construct its picture. Make positive Docker and Bash are put in in your surroundings, after which run the construct script as follows:

$ cd /tmp
$ git clone https://github.com/konveyor/tackle-diva.git
$ cd tackle-diva/doa
$ bash util/construct.sh

docker picture ls diva-doa
REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
diva-doa     2.2.0     5f9dd8f9f0eb   14 hours in the past   1.27GB
diva-doa     newest    5f9dd8f9f0eb   14 hours in the past   1.27GB

This builds DOA and packs as container photos. Now DOA is able to use.

The subsequent step executes a bundled run-doa.sh wrapper script, which runs the DOA container. Specify the Git repository of the goal database utility. This instance makes use of a Postgres database within the TradeApp utility. You can use the -o possibility for the placement of output recordsdata and an -i possibility for the title of the database initialization script:

$ cd /tmp/tackle-diva/doa
$ bash run-doa.sh -o /tmp/out -i start_up.sh
      https://github.com/saud-aslam/trading-app
[OK] efficiently accomplished.

The /tmp/out/ listing and /tmp/out/trading-app, a listing with the goal utility title, are created. In this instance, the appliance title is trading-app, which is the GitHub repository title. Generated artifacts (the YAML recordsdata) are additionally generated beneath the application-name listing:

$ ls -FR /tmp/out/trading-app/
/tmp/out/trading-app/:
cm-init-db.yaml  cm-sqls.yaml  create.sh*  delete.sh*  job-init.yaml  postgres.yaml  check/

/tmp/out/trading-app/check:
pod-test.yaml

The prefix of every YAML file denotes the form of useful resource that the file defines. For occasion, every cm-*.yaml file defines a ConfigMap, and job-init.yaml defines a Job useful resource. At this level, secret-db.yaml just isn’t created, and DOA makes use of credentials that the Postgres operator routinely generates.

Now you might have the useful resource definitions required to deploy a PostgreSQL cluster on a Kubernetes occasion. You can deploy them utilizing the utility script create.sh. Alternatively, you need to use the kubectl create command:

$ cd /tmp/out/trading-app
$ bash create.sh  # or just “kubectl apply -f .”

configmap/trading-app-cm-init-db created
configmap/trading-app-cm-sqls created
job.batch/trading-app-init created
postgresql.acid.zalan.do/diva-trading-app-db created

The Kubernetes assets are created, together with postgresql (a useful resource of the database cluster created by the Postgres operator), service, rs, pod, job, cm, secret, pv, and pvc. For instance, you may see 4 database pods named trading-app-*, as a result of the variety of database situations is outlined as 4 in postgres.yaml.

$ kubectl get all,postgresql,cm,secret,pv,pvc
NAME                                        READY   STATUS      RESTARTS   AGE

pod/trading-app-db-0                        1/1     Running     0          7m11s
pod/trading-app-db-1                        1/1     Running     0          5m
pod/trading-app-db-2                        1/1     Running     0          4m14s
pod/trading-app-db-3                        1/1     Running     0          4m

NAME                                      TEAM          VERSION   PODS   VOLUME   CPU-REQUEST   MEMORY-REQUEST   AGE   STATUS
postgresql.acid.zalan.do/trading-app-db   trading-app   13        4      1Gi                                     15m   Running

NAME                            TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE
service/trading-app-db          ClusterIP   10.97.59.252    <none>        5432/TCP   15m
service/trading-app-db-repl     ClusterIP   10.108.49.133   <none>        5432/TCP   15m

NAME                         COMPLETIONS   DURATION   AGE
job.batch/trading-app-init   1/1           2m39s      15m

Note that the Postgres operator comes with a person interface (UI). You can discover the created cluster on the UI. You have to export the endpoint URL to open the UI on a browser. If you utilize minikube, do as follows:

$ minikube service postgres-operator-ui

Then a browser window routinely opens that reveals the UI.

(Yasuharu Katsuno and Shin Saito, CC BY-SA 4.0)

Now you may get entry to the database situations utilizing a check pod. DOA additionally generated a pod definition for testing.

$ kubectl apply -f /tmp/out/trading-app/check/pod-test.yaml # creates a check Pod
pod/trading-app-test created
$ kubectl exec trading-app-test -it -- bash  # login to the pod

The database hostname and the credential to entry the DB are injected into the pod, so you may entry the database utilizing them. Execute the psql metacommand to indicate all tables and views (in a database):

# printenv DB_HOST; printenv PGPASSWORD
(values of the variable are proven)

# psql -h ${DB_HOST} -U postgres -d jrvstrading -c 'dt'
             List of relations
 Schema |      Name      | Type  |  Owner  
--------+----------------+-------+----------
 public | account        | desk | postgres
 public | quote          | desk | postgres
 public | security_order | desk | postgres
 public | dealer         | desk | postgres
(4 rows)

# psql -h ${DB_HOST} -U postgres -d jrvstrading -c 'dv'
                List of relations
 Schema |         Name          | Type |  Owner  
--------+-----------------------+------+----------
 public | pg_stat_kcache        | view | postgres
 public | pg_stat_kcache_detail | view | postgres
 public | pg_stat_statements    | view | postgres
 public | place              | view | postgres
(4 rows)

After the check is finished, sign off from the pod and take away the check pod:

# exit
$ kubectl delete -f /tmp/out/trading-app/check/pod-test.yaml

Finally, delete the created cluster utilizing a script:

$ bash delete.sh

Welcome to Konveyor Tackle world!

To be taught extra about utility refactoring, you may take a look at the Konveyor Tackle site, be part of the group, and entry the supply code on GitHub.

Most Popular

To Top