Run a database
Contents
Overview
This section describes how to run an ephemeral Oracle database or MySQL database in your Kubernetes cluster using approaches suitable for sample or basic testing purposes.
NOTES:
-
The databases are configured with ephemeral storage, which means all information will be lost on any shutdown or pod failure.
-
The Oracle Database images are supported for non-production use only. For more details, see My Oracle Support note: Oracle Support for Database Running on Docker Doc ID 2216342.1 .
Oracle database in Kubernetes
The following example shows how to set up an ephemeral Oracle database with the following attributes:
| Attribute | Value |
|---|---|
| Kubernetes namespace | default |
| Kubernetes pod | oracle-db |
| Kubernetes service name | oracle-db |
| Kubernetes service port | 1521 |
| Kubernetes node port | 30011 |
| Image | container-registry.oracle.com/database/enterprise:12.2.0.1-slim |
| DBA user (with full privileges) | sys as sysdba |
| DBA password | <password placeholder> |
| Database Domain (not the same as a WebLogic Domain) | k8s |
| Database PDB | devpdb |
| Database URL inside Kubernetes cluster (from any namespace) | oracle-db.default.svc.cluster.local:1521/devpdb.k8s |
| Database URL outside Kubernetes cluster | dns-name-that-resolves-to-node-location:30011/devpdb.k8s |
-
Get the operator source and put it in
/tmp/weblogic-kubernetes-operator.For example:
NOTE: We will refer to the top directory of the operator source tree as
/tmp/weblogic-kubernetes-operator; however, you can use a different location.For additional information about obtaining the operator source, see the Developer Guide Requirements .
-
Ensure that you have access to the database image:
-
Use a browser to log in to
https://container-registry.oracle.com, selectDatabase -> enterprise, and accept the license agreement. -
Get the database image:
- In the local shell,
docker login container-registry.oracle.com. - In the local shell,
docker pull container-registry.oracle.com/database/enterprise:12.2.0.1-slim.
- In the local shell,
-
If your Kubernetes cluster nodes do not all have access to the database image in a local cache, then:
- Deploy a Kubernetes
docker secretto the default namespace with login credentials forcontainer-registry.oracle.com: Pass the name of this secret as a parameter to thestart-db-service.shin the following step using-s your-image-pull-secret. - Alternatively, copy the database image to each local Docker cache in the cluster.
- For more information, see the FAQ, Cannot pull image .
WARNING: The Oracle Database images are supported only for non-production use. For more details, see My Oracle Support note: Oracle Support for Database Running on Docker Doc ID 2216342.1 .
- Deploy a Kubernetes
-
-
Create a secret named
oracle-db-secretin the default namespace with your desired Oracle SYS DBA password in itspasswordkey.- For example:
(Replace
<password placeholder>with your desired password.) - Oracle Database passwords can contain upper case, lower case, digits, and special characters. Use only “_” and “#” as special characters to eliminate potential parsing errors for Oracle Database connection strings.
- For example:
(Replace
-
Create a deployment using the database image:
Use the sample script in
/tmp/weblogic-kubernetes-operator/kubernetes/samples/scripts/create-oracle-db-serviceto create an Oracle database running in the deployment,oracle-db.Notes:
- Call
start-db-service.sh -hto see how to customize the namespace, node port, secret name, etc. - Call
stop-db-service.shto shutdown and cleanup theoracle-dbdeployment. - To troubleshoot, use the
kubectl describe pod DB_POD_NAMEandkubectl logs DB_POD_NAMEcommands on the database pod.
- Call
MySQL database in Kubernetes
The following example shows how to set up an ephemeral MySQL database with the following attributes:
| Attribute | Value |
|---|---|
| Kubernetes namespace | default |
| Kubernetes pod | mysql-db |
| Kubernetes service name | mysql-db |
| Kubernetes service port | 3306 |
| Image | mysql:5.6 |
| Root user (with full privileges) | <user name placeholder> |
| Root password | <password placeholder> |
| Database URL inside Kubernetes cluster (from any namespace) | jdbc:mysql://mysql-db.default.svc.cluster.local:3306/mysql |
Copy the following YAML into a file named mysql.yaml:
In file mysql.yaml, replace <user name placeholder> and <password placeholder>, respectively, with the output from piping the
root user name and password through base64:
Deploy MySQL using the command kubectl create -f mysql.yaml.
To shut down and clean up the resources, use kubectl delete -f mysql.yaml.