SpringBoot Demo with MySQL running on Kubernetes
kubectl create namespace demoappkubectl config set-context --current --namespace=demoappkubectl create secret generic mysql-secrets \
--from-literal=rootpassword=r00tDefaultPassword1! \
--from-literal=username=demo \
--from-literal=password=defaultPassword1! \
--from-literal=database=DB
### Clone the repo if using OCI CloudShell or local
```shell
cd springboot-demo-k8s-mysql/kuberneteskubectl apply -f mysql-pvc-manual.yamlkubectl apply -f mysql-svc.yamlkubectl apply -f mysql-dep.yaml
kubectl get podsNote: This step will create a new LoadBalancer on the infrastructure
kubectl apply -f app-svc.yamlNote: The app will create the necessary tables on the MySQL on the first run
kubectl apply -f app-dep.yamlkubectl logs -l app=demoapp --followkubectl run -it --rm --image=mysql:8 --restart=Never mysql-client -- mysql DB -h mysql -pr00tDefaultPassword1!Press enter
If you don't see a command prompt, try pressing enter.
mysql>insert into users (first_name, last_name) values ('joe', 'doe');
insert into users (first_name, last_name) values ('joe', 'doe');
insert into users (first_name, last_name) values ('joe', 'doe');
insert into users (first_name, last_name) values ('joe', 'doe');
insert into users (first_name, last_name) values ('joe', 'doe');
insert into users (first_name, last_name) values ('joe', 'doe');
insert into users (first_name, last_name) values ('joe', 'doe');
insert into users (first_name, last_name) values ('joe', 'doe');
insert into users (first_name, last_name) values ('joe', 'doe');
insert into users (first_name, last_name) values ('joe', 'doe');
insert into users (first_name, last_name) values ('joe', 'doe');
insert into users (first_name, last_name) values ('joe', 'doe');
insert into users (first_name, last_name) values ('joe', 'doe');
insert into users (first_name, last_name) values ('joe', 'doe');
insert into users (first_name, last_name) values ('joe', 'doe');
insert into users (first_name, last_name) values ('joe', 'doe');
insert into users (first_name, last_name) values ('joe', 'doe');
insert into users (first_name, last_name) values ('joe', 'doe');
insert into users (first_name, last_name) values ('joe', 'doe');
insert into users (first_name, last_name) values ('joe', 'doe');
insert into users (first_name, last_name) values ('joe', 'doe');Expected results:
If you don't see a command prompt, try pressing enter.
mysql> insert into users (first_name, last_name) values ('joe', 'doe');
Query OK, 1 row affected (0.00 sec)
mysql> quit
Bye
pod "mysql-client" deletedkubectl port-forward deploy/demoapp 8081:8081Navigate to http://localhost:8081/users
kubectl get svcNavigate to http://<demoapp_EXTERNAL_IP_ADDRESS>/users
kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yamlkubectl autoscale deployment demoapp --cpu-percent=5 --min=1 --max=3kubectl get hpakubectl run -i --tty load-generator --rm --image=busybox --restart=Never -- /bin/sh -c "while sleep 0.01; do wget -q -O- http://demoapp/users; done"Within a minute or so, we should see the higher CPU load by executing:
kubectl get hpakubectl create namespace demoapp kubectl config set-context --current --namespace=demoapp
kubectl create secret generic mysql-secrets
--from-literal=rootpassword=r00tDefaultPassword1!
--from-literal=username=demo
--from-literal=password=defaultPassword1!
--from-literal=database=DB
kubectl apply -f mysql-pvc-manual.yaml
kubectl apply -f mysql-svc.yaml kubectl apply -f mysql-dep.yaml kubectl apply -f app-svc.yaml
kubectl apply -f app-dep.yaml kubectl logs -l app=demoapp --follow
in windows cmd kubectl run -it --rm --image=mysql:8 --restart=Never mysql-client -- mysql DB -h mysql -pr00tDefaultPassword1!
kubectl port-forward deploy/demoapp 8081:8081
choco install kubernetes-helm
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo add stable https://charts.helm.sh/stable
helm repo update
helm install prometheus prometheus-community/kube-prometheus-stack
kubectl port-forward deployment/prometheus-grafana 3000kubectl get secret prometheus-grafana \
-o jsonpath="{.data.admin-password}" | base64 --decode ; echokubectl port-forward svc/prometheus-grafana 8085:80Navigate to http://localhost:8085/
Skip this step if you just want to test the app on Kubernetes
docker build --pull --no-cache --squash --rm --progress plain -f Dockerfile -t sbdemo .