{"id":20149381,"url":"https://github.com/junior/springboot-demo-k8s-mysql","last_synced_at":"2025-10-09T07:33:16.211Z","repository":{"id":54393518,"uuid":"340268420","full_name":"junior/springboot-demo-k8s-mysql","owner":"junior","description":"SpringBoot Demo with MySQL running on Kubernetes","archived":false,"fork":false,"pushed_at":"2021-02-21T04:23:54.000Z","size":50,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-09-21T08:44:47.481Z","etag":null,"topics":["autoscaling","grafana","hpa","kubernetes","mysql","mysql8","springboot","springboot-demo"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"upl-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/junior.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-02-19T05:31:55.000Z","updated_at":"2024-11-11T15:20:13.000Z","dependencies_parsed_at":"2022-08-13T14:20:28.922Z","dependency_job_id":null,"html_url":"https://github.com/junior/springboot-demo-k8s-mysql","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/junior/springboot-demo-k8s-mysql","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junior%2Fspringboot-demo-k8s-mysql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junior%2Fspringboot-demo-k8s-mysql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junior%2Fspringboot-demo-k8s-mysql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junior%2Fspringboot-demo-k8s-mysql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/junior","download_url":"https://codeload.github.com/junior/springboot-demo-k8s-mysql/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junior%2Fspringboot-demo-k8s-mysql/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279000960,"owners_count":26082973,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-09T02:00:07.460Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["autoscaling","grafana","hpa","kubernetes","mysql","mysql8","springboot","springboot-demo"],"created_at":"2024-11-13T22:43:13.409Z","updated_at":"2025-10-09T07:33:16.194Z","avatar_url":"https://github.com/junior.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Springboot demo app\n\nSpringBoot Demo with MySQL running on Kubernetes\n\n## Deploy to Kubernetes\n\n### Create namespace\n\n```shell\nkubectl create namespace demoapp\n```\n\n### Default namespace to demoapp\n\n```shell\nkubectl config set-context --current --namespace=demoapp\n```\n\n### Create MySQL Secrets\n\n```shell\nkubectl create secret generic mysql-secrets \\\n  --from-literal=rootpassword=r00tDefaultPassword1! \\\n  --from-literal=username=demo \\\n  --from-literal=password=defaultPassword1! \\\n  --from-literal=database=DB\n```\n\n### Clone the repo if using OCI CloudShell or local\n\n```shell\ngit clone https://github.com/junior/springboot-demo-k8s-mysql.git\n```\n\n```shell\ncd springboot-demo-k8s-mysql/kubernetes\n```\n\n### Deploy MySQL 8\n\n#### Create PVC for MySQl on Oracle Cloud Infrastructure using CSI for Block Volume\n\n```shell\nkubectl apply -f mysql-pvc-oci-bv.yaml\n```\n\n\u003e Use mysql-pvc-manual.yaml if deploying local\n\n#### Create Service for MySQL\n\n```shell\nkubectl apply -f mysql-svc.yaml\n```\n\n#### Create Deployment for MySQL\n\n```shell\nkubectl apply -f mysql-dep.yaml\n```\n\n### Deploy the Spring Boot Demo App\n\n#### Create Service for Demo App\n\nNote: This step will create a new LoadBalancer on the infrastructure\n\n```shell\nkubectl apply -f app-svc.yaml\n```\n\n#### Create Deployment for Demo App\n\nNote: The app will create the necessary tables on the MySQL on the first run\n\n```shell\nkubectl apply -f app-dep.yaml\n```\n\n#### Optional: Check logs\n\n```shell\nkubectl logs -l app=demoapp --follow\n```\n\n#### Optional: Insert Data to MySQL\n\n##### Connect to mysql\n\n```shell\nkubectl run -it --rm --image=mysql:8 --restart=Never mysql-client -- mysql DB -h mysql -pr00tDefaultPassword1!\n```\n\nPress enter\n\n```shell\nIf you don't see a command prompt, try pressing enter.\n\nmysql\u003e\n```\n\n```sql\ninsert into users (first_name, last_name) values ('joe', 'doe');\n```\n\nExpected results:\n\n```shell\nIf you don't see a command prompt, try pressing enter.\n\nmysql\u003e insert into users (first_name, last_name) values ('joe', 'doe');\nQuery OK, 1 row affected (0.00 sec)\n\nmysql\u003e quit\nBye\npod \"mysql-client\" deleted\n```\n\n#### Optional: Test with port-forward\n\n```shell\nkubectl port-forward deploy/demoapp 8081:8081\n```\n\nNavigate to http://localhost:8081/users\n\n#### Test with LoadBalancer IP Address\n\n```shell\nkubectl get svc\n```\n\nNavigate to http://\u003cdemoapp_EXTERNAL_IP_ADDRESS\u003e/users\n\n## Create Horizontal Pod Autoscaler for Demo App\n\n### Install metrics server\n\n```shell\nkubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml\n```\n\n### Create autoscale for Demo App\n\n```shell\nkubectl autoscale deployment demoapp --cpu-percent=30 --min=1 --max=10\n```\n\n### Check HPA\n\n```shell\nkubectl get hpa\n```\n\n### Increase load\n\n```shell\nkubectl 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\"\n```\n\nWithin a minute or so, we should see the higher CPU load by executing:\n\n```shell\nkubectl get hpa\n```\n\n## Prometheus and Grafana\n\n### Install the grafana-prometheus stack\n\n```shell\nhelm install prometheus prometheus-community/kube-prometheus-stack\n```\n\n### get the grafana admin password\n\n```shell\nkubectl get secret prometheus-grafana \\\n -o jsonpath=\"{.data.admin-password}\" | base64 --decode ; echo\n ```\n\n### Test Grafana with port-forward\n\n ```shell\nkubectl port-forward svc/prometheus-grafana 8085:80\n ```\n\n Navigate to http://localhost:8085/\n\n## Build Demo App image\n\nSkip this step if you just want to test the app on Kubernetes\n\n```shell\ndocker build --pull --no-cache --squash --rm --progress plain -f Dockerfile -t sbdemo .\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjunior%2Fspringboot-demo-k8s-mysql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjunior%2Fspringboot-demo-k8s-mysql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjunior%2Fspringboot-demo-k8s-mysql/lists"}