Skip to content

Commit

Permalink
feat: replace to oracle mysql operator (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisleekr authored Dec 29, 2022
1 parent 8bff120 commit 620fe6b
Show file tree
Hide file tree
Showing 27 changed files with 678 additions and 224 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ jobs:
- name: Install Terraform
run: |
cd /tmp
wget https://releases.hashicorp.com/terraform/0.13.5/terraform_0.13.5_linux_amd64.zip
unzip terraform_0.13.5_linux_amd64.zip
wget https://releases.hashicorp.com/terraform/1.3.6/terraform_1.3.6_linux_amd64.zip
unzip terraform_1.3.6_linux_amd64.zip
sudo mv terraform /usr/local/bin
terraform version
- name: Install Helm
Expand All @@ -26,9 +26,6 @@ jobs:
cd $GITHUB_WORKSPACE/helm/nvm
helm lint
helm template . > template
cd $GITHUB_WORKSPACE/helm/nvm-db
helm lint
helm template . > template
- name: Lint Terraform
run: |
cd $GITHUB_WORKSPACE/terraform
Expand Down
4 changes: 0 additions & 4 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ lint-helm:
- helm lint
- helm template . > template
- popd
- pushd helm/nvm-db
- helm lint
- helm template . > template
- popd

lint-terraform:
stage: lint
Expand Down
53 changes: 27 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,21 @@ This is a Kubernetes sample project, not for a production use.

## Prerequisites

- [Minikube v1.15.1](https://kubernetes.io/docs/tasks/tools/install-minikube/)
- [Kubernetes v.1.19.4](https://kubernetes.io/docs/tasks/tools/install-kubectl/)
- [Minikube v1.28.0](https://kubernetes.io/docs/tasks/tools/install-minikube/)
- [Kubernetes v1.20.2](https://kubernetes.io/docs/tasks/tools/install-kubectl/)
- [Helm v3.4.1](https://helm.sh/docs/intro/install/)
- [Terraform v0.13.5](https://learn.hashicorp.com/tutorials/terraform/install-cli)
- [Terraform v1.3.6](https://learn.hashicorp.com/tutorials/terraform/install-cli)

## How to test in your Minikube

1. Start minikube

```bash
$ minikube start
$ minikube addons enable ingress
$ minikube addons enable metrics-server
$ minikube start --addons ingress,metrics-server
```

2. Go to `terraform` folder

3. Run Terraform commands

```bash
Expand All @@ -42,6 +41,8 @@ This is a Kubernetes sample project, not for a production use.
$ ./script/update-hosts.sh
```

5. Open new browser and go to [nvm-boilerplate.local](http://nvm-boilerplate.local)

## With this project, you can find

- Sample Terraform
Expand All @@ -51,29 +52,20 @@ This is a Kubernetes sample project, not for a production use.

- [https://github.com/chrisleekr/nodejs-vuejs-mysql-boilerplate](https://github.com/chrisleekr/nodejs-vuejs-mysql-boilerplate)

## Presslabs MySQL Operator

To see orchestrator, run following port forward.

```bash
$ kubectl -nnvm-db port-forward service/presslabs-mysql-operator 8080:80
```

![image](https://user-images.githubusercontent.com/5715919/100513791-ed9ff900-31c3-11eb-80c6-7a3d332d272d.png)
## Oracle MySQL Operator

And open [http://localhost:8080](http://localhost:8080)

To see operator logs, run following command
To access MySQL, run following command

```bash
$ kubectl -nnvm-db logs presslabs-mysql-operator-0 -c operator -f
```
# Get root password
$ kubectl -nmysql get secrets mysql-innodbcluster-cluster-secret -oyaml
$ echo "<rootPassword>" | base64 -d

To access mysql, run following command
# Port forward
$ kubectl -nmysql port-forward svc/mysql-innodbcluster 6446:6446

```bash
$ kubectl -nnvm-db port-forward mysql-cluster-mysql-0 3307:3306
$ mysql -h127.0.0.1 -uroot -proot -P3307 boilerplate
# Access to R/W MySQL
$ mysql -h127.0.0.1 -uroot -p -P6446 boilerplate
```

## Horizontal Pod Autoscaler
Expand All @@ -99,10 +91,18 @@ Apply complete! Resources: 0 added, 1 changed, 0 destroyed.
Outputs:
grafana_admin_password = ynSVNykpU72RM5x6
grafana_admin_password = <sensitive>
mysql_boilerplate_password = <sensitive>
mysql_root_password = <sensitive>
```

You can get the password by executing the following command:

```bash
terraform output grafana_admin_password
```

For example, as above, if admin password `ynSVNykpU72RM5x6` then you can login Grafana with `admin`/`ynSVNykpU72RM5x6`.
With the password, you can login Grafana with `admin`/`<Password>`.

![image](https://user-images.githubusercontent.com/5715919/100513860-4a031880-31c4-11eb-8ef2-04202055aa78.png)

Expand All @@ -112,3 +112,4 @@ For example, as above, if admin password `ynSVNykpU72RM5x6` then you can login G
- [x] Add HorizontalPodAutoscaler
- [x] Add Prometheus and Grafana
- [x] Expose MySQL write node for migration to avoid api migration failure
- [x] Replaced presslab/mysql-operator to Oracle MySQL operator/InnoDB cluster
24 changes: 16 additions & 8 deletions build/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
FROM alpine:edge
FROM alpine:3.17

ENV TERRAFORM_VERSION=0.13.5-r0
ENV HELM_VERSION=3.4.0-r0
ENV TERRAFORM_VERSION=1.3.6
ENV HELM_VERSION=3.4.1

RUN apk --no-cache add \
-X http://dl-cdn.alpinelinux.org/alpine/edge/testing \
terraform=$TERRAFORM_VERSION \
helm=$HELM_VERSION \
bash=5.0.18-r0

bash=5.2.15-r0 \
curl=7.87.0-r0 && \
# Install Terraform
wget https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip && \
unzip terraform_${TERRAFORM_VERSION}_linux_amd64.zip && \
mv terraform /usr/local/bin/ && \
terraform --version && \
# Install helm
curl -L https://get.helm.sh/helm-v${HELM_VERSION}-linux-amd64.tar.gz | tar xz && \
mv linux-amd64/helm /usr/bin/helm && \
chmod +x /usr/bin/helm && \
rm -rf linux-amd64 && \
helm version
22 changes: 0 additions & 22 deletions helm/nvm-db/.helmignore

This file was deleted.

5 changes: 0 additions & 5 deletions helm/nvm-db/Chart.yaml

This file was deleted.

20 changes: 0 additions & 20 deletions helm/nvm-db/templates/mysql-operator/mysql-cluster.yaml

This file was deleted.

10 changes: 0 additions & 10 deletions helm/nvm-db/templates/mysql-operator/mysql-secrets.yaml

This file was deleted.

13 changes: 0 additions & 13 deletions helm/nvm-db/values.yaml

This file was deleted.

8 changes: 4 additions & 4 deletions helm/nvm/templates/apps/apps-migration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ metadata:
labels:
environment: {{$.Values.environment}}
app: migration
annotations:
helm.sh/hook: "post-install,post-upgrade"
helm.sh/hook-weight: "1"
helm.sh/hook-delete-policy: hook-succeeded
# annotations:
# helm.sh/hook: "post-install,post-upgrade"
# helm.sh/hook-weight: "1"
# helm.sh/hook-delete-policy: hook-succeeded
spec:
backoffLimit: 3
activeDeadlineSeconds: 600
Expand Down
42 changes: 32 additions & 10 deletions helm/nvm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@ migration:
repository: chrisleekr/nodejs-vuejs-mysql-boilerplate
version: api-latest
env:
- name: "DB_HOST"
value: "mysql-cluster-mysql-master.nvm-db"
- name: "DB_PORT"
value: 3306
- name: "DB_CONNECTION_LIMIT"
value: 10
- name: "DB_DEBUG"
value: "true"
secretEnv:
- name: "DB_HOST"
secretKeyRef:
name: "nvm-secret"
key: "db-host"
- name: "DB_PORT"
secretKeyRef:
name: "nvm-secret"
key: "db-port"
- name: "DB_NAME"
secretKeyRef:
name: "nvm-secret"
Expand Down Expand Up @@ -59,16 +63,10 @@ apps:
path: /
port: 3000
env:
- name: "DB_HOST"
value: "mysql.nvm-db"
- name: "DB_PORT"
value: 3306
- name: "DB_CONNECTION_LIMIT"
value: 10
- name: "DB_DEBUG"
value: "true"
- name: "JWT_SECRET_KEY"
value: "aaGhu2foo7sheithePhai4Aef"
- name: "JWT_EXPIRES_IN"
value: "1w"
- name: "BCRYPT_SALTING_ROUND"
Expand Down Expand Up @@ -100,6 +98,14 @@ apps:
- name: "TZ"
value: "Australia/Melbourne"
secretEnv:
- name: "DB_HOST"
secretKeyRef:
name: "nvm-secret"
key: "db-host"
- name: "DB_PORT"
secretKeyRef:
name: "nvm-secret"
key: "db-port"
- name: "DB_NAME"
secretKeyRef:
name: "nvm-secret"
Expand All @@ -112,6 +118,14 @@ apps:
secretKeyRef:
name: "nvm-secret"
key: "db-password"
- name: "JWT_SECRET_KEY"
secretKeyRef:
name: "nvm-secret"
key: "jwt-secret-key"
- name: "JWT_REFRESH_SECRET_KEY"
secretKeyRef:
name: "nvm-secret"
key: "jwt-refresh-secret-key"
frontendVue:
name: frontend-vue
image:
Expand Down Expand Up @@ -188,9 +202,17 @@ apps:
port: 8025

secrets:
- key: "db-host"
value: "mysql-innodbcluster.mysql.svc.cluster.local"
- key: "db-port"
value: 6446
- key: "db-user"
value: "boilerplate"
- key: "db-password"
value: "boilerplate-password"
- key: "db-name"
value: "boilerplate"
- key: "jwt-secret-key"
value: ""
- key: "jwt-refresh-secret-key"
value: ""
Loading

0 comments on commit 620fe6b

Please sign in to comment.