Skip to content

Commit

Permalink
Update readme to use dbtemplate (#601)
Browse files Browse the repository at this point in the history
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
viveksinghggits and mergify[bot] committed Mar 6, 2020
1 parent ea72b13 commit bcc06f0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 50 deletions.
41 changes: 11 additions & 30 deletions examples/stable/mysql-deploymentconfig/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,37 +43,27 @@ oc login -u system:admin
```
and you are all set to go through rest of this example.

It is not necessary to use minishift to go through this example, you can go through this example as long as you have an OpenShift cluster setup.

# Install MySQL

We will follow standard MySQL installation steps that are mentioned [here](https://docs.okd.io/latest/using_images/db_images/mysql.html#initializing-the-database). Once you have the minishift setup, please go ahead and run below commands to deploy the
We will follow the steps that are suggested by OpenShift and can be found [here](https://github.com/openshift/origin/tree/master/examples/db-templates). Once you have the minishift setup, please go ahead and run below commands to deploy the
MySQL application

```bash
~ oc create ns mysql-test
~ oc new-app \
-e MYSQL_USER=vivek \
-e MYSQL_PASSWORD=vivek \
-e MYSQL_DATABASE=testdb \
-e MYSQL_ROOT_PASSWORD=viveksingh \
openshift/mysql-56-centos7 -n mysql-test
~ oc new-app https://raw.githubusercontent.com/openshift/origin/master/examples/db-templates/mysql-ephemeral-template.json \
-n mysql-test \
-p MYSQL_ROOT_PASSWORD=secretpassword
```

**Note**

After deploying the application we will manually have to create a secret that is going to store the root credential to this mysql instance.
Please follow below command to create the secret resource

```bash
~ oc create secret generic mysql --from-literal=mysql-root-password=viveksingh -n mysql-test
secret/mysql created
```

Once you have deployed the MySQL application, please verify the status of the MySQL pod using below command to make sure the pod is in `running` status

```bash
~ oc get pods -n mysql-test
NAME READY STATUS RESTARTS AGE
mysql-56-centos7-1-9v5cg 1/1 Running 0 27s
mysql-1-bzgcr 1/1 Running 0 27s
```

## Integrating with Kanister
Expand Down Expand Up @@ -121,10 +111,10 @@ to do so
```bash
~ oc get pods -n mysql-test
NAME READY STATUS RESTARTS AGE
mysql-56-centos7-1-9v5cg 1/1 Running 0 13m
mysql-1-bzgcr 1/1 Running 0 13m

# Exec into the pod and insert some data
~ oc exec -it -n mysql-test mysql-56-centos7-1-9v5cg bash
~ oc exec -it -n mysql-test mysql-1-bzgcr bash
bash-4.2$ mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Expand Down Expand Up @@ -178,15 +168,6 @@ mysql> select * from employees;

```
# Create ClusterRoleBinding
Since the Kanister resources need access to the the foundationDB cluster that has just been created,
using the CR, we will have create a `ClusterRoleBinding` to enable that access. You can create that `ClusterRoleBinding`
resource using below command
```bash
~ oc create -f kanister-clusteradmin-binding.yaml
```
## Protect the Application
Expand Down Expand Up @@ -219,10 +200,10 @@ Let's say someone accidentally deleted the databases that we have created using
```bash
~ oc get pods -n mysql-test
NAME READY STATUS RESTARTS AGE
mysql-56-centos7-1-9v5cg 1/1 Running 0 13m
mysql-1-bzgcr 1/1 Running 0 13m

# Exec into the pod and insert some data
~ oc exec -it -n mysql-test mysql-56-centos7-1-9v5cg bash
~ oc exec -it -n mysql-test mysql-1-bzgcr bash
bash-4.2$ mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ actions:
mysqlCloudDump:
keyValue:
s3path: "{{ .Phases.dumpToObjectStore.Output.s3path }}"
secretNames:
- mysql
phases:
- func: KubeTask
name: dumpToObjectStore
objects:
mysqlsecret:
kind: Secret
name: "{{ .DeploymentConfig.Name }}"
namespace: "{{ .DeploymentConfig.Namespace }}"
args:
image: kanisterio/mysql-sidecar:0.26.0
namespace: "{{ .DeploymentConfig.Namespace }}"
Expand All @@ -27,18 +30,21 @@ actions:
- |
date
s3_path="/mysql-backups/{{ .DeploymentConfig.Namespace }}/{{ .DeploymentConfig.Name }}/{{ toDate "2006-01-02T15:04:05.999999999Z07:00" .Time | date "2006-01-02T15-04-05" }}/dump.sql.gz"
root_password="{{ index .Secrets.mysql.Data "mysql-root-password" | toString }}"
root_password="{{ index .Phases.dumpToObjectStore.Secrets.mysqlsecret.Data "database-root-password" | toString }}"
mysqldump --column-statistics=0 -u root --password=${root_password} -h {{ .DeploymentConfig.Name }} --single-transaction --all-databases | gzip - | kando location push --profile '{{ toJson .Profile }}' --path ${s3_path} -
kando output s3path ${s3_path}
restore:
type: DeploymentConfig
inputArtifactNames:
- mysqlCloudDump
secretNames:
- mysql
phases:
- func: KubeTask
name: restoreFromBlobStore
objects:
mysqlsecret:
kind: Secret
name: "{{ .DeploymentConfig.Name }}"
namespace: "{{ .DeploymentConfig.Namespace }}"
args:
image: kanisterio/mysql-sidecar:0.26.0
namespace: "{{ .DeploymentConfig.Namespace }}"
Expand All @@ -51,7 +57,7 @@ actions:
- -c
- |
s3_path="{{ .ArtifactsIn.mysqlCloudDump.KeyValue.s3path }}"
root_password="{{ index .Secrets.mysql.Data "mysql-root-password" | toString }}"
root_password="{{ index .Phases.restoreFromBlobStore.Secrets.mysqlsecret.Data "database-root-password" | toString }}"
kando location pull --profile '{{ toJson .Profile }}' --path ${s3_path} - | gunzip | mysql -u root --password=${root_password} -h {{ .DeploymentConfig.Name }}
delete:
type: DeploymentConfig
Expand Down

0 comments on commit bcc06f0

Please sign in to comment.