Skip to content

Commit

Permalink
Updated code for MySQL operator (#2)
Browse files Browse the repository at this point in the history
* Updated code
  • Loading branch information
chrisleekr authored Nov 21, 2020
1 parent 3b45113 commit f44b90a
Show file tree
Hide file tree
Showing 21 changed files with 211 additions and 197 deletions.
11 changes: 7 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ jobs:
- name: Install Terraform
run: |
cd /tmp
wget https://releases.hashicorp.com/terraform/0.13.4/terraform_0.13.4_linux_amd64.zip
unzip terraform_0.13.4_linux_amd64.zip
wget https://releases.hashicorp.com/terraform/0.13.5/terraform_0.13.5_linux_amd64.zip
unzip terraform_0.13.5_linux_amd64.zip
sudo mv terraform /usr/local/bin
terraform version
- name: Install Helm
run: |
cd /tmp
wget https://get.helm.sh/helm-v3.3.4-linux-amd64.tar.gz
tar xvfz helm-v3.3.4-linux-amd64.tar.gz
wget https://get.helm.sh/helm-v3.4.1-linux-amd64.tar.gz
tar xvfz helm-v3.4.1-linux-amd64.tar.gz
sudo mv linux-amd64/helm /usr/local/bin/helm
helm version
- name: Checkout source code
Expand All @@ -26,6 +26,9 @@ 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ terraform/terraform.tfstate
terraform/terraform.tfstate.backup
terraform/.terraform.tfstate.lock.info
helm/nvm/template
helm/nvm-db/template
10 changes: 8 additions & 2 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,22 @@ lint-helm:
artifacts:
paths:
- helm/nvm/template
- helm/nvm-db/template
expire_in: "7 days"
script:
- cd helm/nvm
- pushd helm/nvm
- helm lint
- helm template . > template
- popd
- pushd helm/nvm-db
- helm lint
- helm template . > template
- popd

lint-terraform:
stage: lint
image: $REGISTRY_DOMAIN/chrisleekr/k8s-nodejs-vuejs-mysql-boilerplate:build
script:
- cd terraform
- pushd terraform
- terraform init
- terraform validate
15 changes: 14 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,18 @@
".git": true,
"**/.DS_Store": true,
"**/.vscode": true
}
},
"cSpell.words": [
"Autoscaler",
"Grafana",
"Kubernetes",
"Minikube",
"Presslabs",
"chrisleekr",
"containerised",
"kubectl",
"popd",
"pushd",
"vuejs"
]
}
54 changes: 29 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Kubernetes for Node.js (REST API) + Vue.js (Frontend/Backend) + MySQL Boilerplate
# Kubernetes sample project for Node.js (REST API) + Vue.js (Frontend/Backend) + MySQL Boilerplate

This project demonstrates simple IaC (Infrastructure as Code) for [NVM boilerplate](https://github.com/chrisleekr/nodejs-vuejs-mysql-boilerplate) to Minikube.

This is not for a production use.
This is a Kubernetes sample project, not for a production use.

## Prerequisites

- [Minikube v1.13.1](https://kubernetes.io/docs/tasks/tools/install-minikube/)
- [Kubernetes v.1.19.2](https://kubernetes.io/docs/tasks/tools/install-kubectl/)
- [Helm v3.3.4](https://helm.sh/docs/intro/install/)
- [Terraform v0.13.3](https://learn.hashicorp.com/tutorials/terraform/install-cli)
- [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/)
- [Helm v3.4.1](https://helm.sh/docs/intro/install/)
- [Terraform v0.13.5](https://learn.hashicorp.com/tutorials/terraform/install-cli)

## How to test in your Minikube

Expand Down Expand Up @@ -38,32 +38,36 @@ This is not for a production use.
## With this project, you can find

- Sample Terraform
- Sample Helm charts to deploy multiple micro-services
- Sample Helm charts to deploy multiple containerised micro-services

## Repository: Node.js + Vue.js + MySQL Boilerplate
## Micro-services Repository: Node.js + Vue.js + MySQL Boilerplate

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

## Todo
## Presslabs MySQL Operator

- [ ] Update MySQL with a replicated stateful application
- [ ] Add HorizontalPodAutoscaler
To see orchestrator, run following port forward and open [http://localhost:8080](http://localhost:8080)

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

To see operator logs, run following command

## Troubleshooting
```bash
$ kubectl -nnvm-db logs presslabs-mysql-operator-0 -c operator -f
```

### Failed to enable ingress in Mac OS
To access mysql, run following command

```bash
$ minikube addons enable ingress
❌ Exiting due to MK_USAGE: Due to networking limitations of driver docker on darwin, ingress addon is not supported.
Alternatively to use this addon you can use a vm-based driver:

'minikube start --vm=true'

To track the update on this work in progress feature please check:
https://github.com/kubernetes/minikube/issues/7332
$ minikube stop
$ minikube delete
$ minikube start --vm=true
$ minikube addons enable ingress
$ kubectl -nnvm-db port-forward mysql-cluster-mysql-0 3307:3306
$ mysql -h127.0.0.1 -uroot -proot -P3307 boilerplate
```

## Todo

- [x] Update MySQL with a replicated stateful application - Use presslabs/mysql-operator
- [ ] Expose MySQL write node for migration to avoid api migration failure
- [ ] Add HorizontalPodAutoscaler
- [ ] Add Prometheus and Grafana
7 changes: 4 additions & 3 deletions build/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
FROM alpine:edge

ENV TERRAFORM_VERSION=0.13.4-r0
ENV HELM_VERSION=3.3.4-r0
ENV TERRAFORM_VERSION=0.13.5-r0
ENV HELM_VERSION=3.4.0-r0

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

22 changes: 22 additions & 0 deletions helm/nvm-db/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
5 changes: 5 additions & 0 deletions helm/nvm-db/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v2
name: nvm-db
description: A Helm chart for Kubernetes
version: 0.1.3
icon: https://github.com/chrisleekr/nodejs-vuejs-mysql-boilerplate/raw/master/frontend-nuxt/static/icon.png
20 changes: 20 additions & 0 deletions helm/nvm-db/templates/mysql-operator/mysql-cluster.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
apiVersion: mysql.presslabs.org/v1alpha1
kind: MysqlCluster
metadata:
name: mysql-cluster
namespace: {{$.Values.namespace}}
spec:
replicas: 2
secretName: mysql-secret
podSpec:
resources:
requests:
memory: 1G
cpu: 200m
volumeSpec:
persistentVolumeClaim:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 1Gi
10 changes: 10 additions & 0 deletions helm/nvm-db/templates/mysql-operator/mysql-secrets.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
apiVersion: v1
kind: Secret
metadata:
name: mysql-secret
namespace: {{$.Values.namespace}}
type: Opaque
data:
{{ range .Values.secrets }}{{.key}}: "{{.value | b64enc}}"
{{ end }}
11 changes: 11 additions & 0 deletions helm/nvm-db/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace: nvm-db

secrets:
- key: "ROOT_PASSWORD"
value: "root"
- key: "USER"
value: "boilerplate"
- key: "PASSWORD"
value: "boilerplate-password"
- key: "DATABASE"
value: "boilerplate"
2 changes: 1 addition & 1 deletion helm/nvm/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
apiVersion: v2
name: nvm
description: A Helm chart for Kubernetes
version: 0.1.2
version: 0.1.5
icon: https://github.com/chrisleekr/nodejs-vuejs-mysql-boilerplate/raw/master/frontend-nuxt/static/icon.png
22 changes: 22 additions & 0 deletions helm/nvm/templates/apps/apps-ingress-root.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: "nginx"
nginx.ingress.kubernetes.io/app-root: /frontend-vue
nginx.ingress.kubernetes.io/enable-rewrite-log: "true"
name: ingress-app-root
namespace: {{$.Values.namespace}}
spec:
rules:
- host: "{{ $.Values.ingress.host }}"
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: frontend-vue
port:
number: 80
9 changes: 6 additions & 3 deletions helm/nvm/templates/apps/apps-ingress.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{ range .Values.apps }}
---
apiVersion: networking.k8s.io/v1beta1
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-{{.name}}
Expand All @@ -20,7 +20,10 @@ spec:
http:
paths:
- path: {{ .ingress.path }}
pathType: Prefix
backend:
serviceName: {{.name}}
servicePort: {{.containerPort}}
service:
name: {{.name}}
port:
number: {{.containerPort}}
{{ end }}
42 changes: 0 additions & 42 deletions helm/nvm/templates/mysql/mysql-deployment.yaml

This file was deleted.

25 changes: 0 additions & 25 deletions helm/nvm/templates/mysql/mysql-pv.yaml

This file was deleted.

9 changes: 0 additions & 9 deletions helm/nvm/templates/mysql/mysql-secret.yaml

This file was deleted.

12 changes: 0 additions & 12 deletions helm/nvm/templates/mysql/mysql-services.yaml

This file was deleted.

Loading

0 comments on commit f44b90a

Please sign in to comment.