Deploying an Oracle Database with Persistence in Oracle Kubernetes Engine


UPDATE: Follow this post for the deployment part, as it has been updated, the rest of the content is still valid, thanks.

Today we are deploying an Oracle database instance in a K8s cluster making them persistent so that data is not lost after container/pod restarts. Please follow this link to get the yaml file or simply execute the following:

kubectl apply -f https://raw.githubusercontent.com/javiermugueta/k8s-orcldb/master/orcldb.yaml
persistentvolumeclaim/data-pvc created
deployment.apps/orcldb created
service/oracledb created

After a while a new pod and service should be created, check it with:

kubectl get po
NAME READY STATUS RESTARTS AGE
orcldb-796ddfdd6f-tgfqf 1/1 Running 0 5m
kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
oracledb LoadBalancer 10.96.9.195 130.61.66.33 1521:31521/TCP 5m

Write down the external IP of the service created and set up a new connection to the database with your preferred tool as follows (password is Oradoc_db1):

Once connected, issue the following:

create table t (c varchar2(10));
insert into t (c) values ('aaaaaaaaaa');
insert into t select * from t;
commit;
select count(*) from t;

Table T created.
1 row inserted.
1 row inserted.
Commit complete.
COUNT(*)
----------
2

Now delete the pod:

kubectl delete po orcldb-796ddfdd6f-tgfqf

You’ll notice that the connection to the database is lost until the pod recreates again (you can’t have more than one replica for this particular use case):

But after a while, the pod gets created again and if you reconnect to the database you’ll find your data in there:

That’s all folks!

Enjoy 🙂

2 Comments

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.