|
1 | | -# springboot-demo-k8s-mysql |
| 1 | +# Springboot demo app |
| 2 | + |
2 | 3 | SpringBoot Demo with MySQL running on Kubernetes |
| 4 | + |
| 5 | +## Build Demo App image |
| 6 | + |
| 7 | +```shell |
| 8 | +docker build --pull --no-cache --squash --rm --progress plain -f Dockerfile -t sbdemo . |
| 9 | +``` |
| 10 | + |
| 11 | +## Deploy to Kubernetes |
| 12 | + |
| 13 | +### Create namespace |
| 14 | + |
| 15 | +```shell |
| 16 | +kubectl create namespace demoapp |
| 17 | +``` |
| 18 | + |
| 19 | +### Default namespace to demoapp |
| 20 | + |
| 21 | +```shell |
| 22 | +kubectl config set-context --current --namespace=demoapp |
| 23 | +``` |
| 24 | + |
| 25 | +### Create MySQL Secrets |
| 26 | + |
| 27 | +```shell |
| 28 | +kubectl create secret generic mysql-secrets \ |
| 29 | + --from-literal=rootpassword=r00tDefaultPassword1! \ |
| 30 | + --from-literal=username=demo \ |
| 31 | + --from-literal=password=defaultPassword1! \ |
| 32 | + --from-literal=database=DB |
| 33 | +``` |
| 34 | + |
| 35 | +### Deploy MySQL 5.7 |
| 36 | + |
| 37 | +#### Create PVC for MySQl on Oracle Cloud Infrastructure using CSI for Block Volume |
| 38 | + |
| 39 | +```shell |
| 40 | +kubectl apply -f mysql-pvc-oci-bv.yaml |
| 41 | +``` |
| 42 | + |
| 43 | +> Use mysql-pv-manual.yaml if deploying local |
| 44 | +
|
| 45 | +#### Create Service for MySQL |
| 46 | + |
| 47 | +```shell |
| 48 | +kubectl apply -f mysql-svc.yaml |
| 49 | +``` |
| 50 | + |
| 51 | +#### Create Deployment for MySQL |
| 52 | + |
| 53 | +```shell |
| 54 | +kubectl apply -f mysql-dep.yaml |
| 55 | +``` |
| 56 | + |
| 57 | +#### Optional: Insert Data |
| 58 | + |
| 59 | +##### Connect to mysql |
| 60 | + |
| 61 | +```shell |
| 62 | +kubectl run -it --rm --image=mysql:5.7 --restart=Never mysql-client -- mysql DB -h mysql -pr00tDefaultPassword1! |
| 63 | +``` |
| 64 | + |
| 65 | +Press enter |
| 66 | + |
| 67 | +```shell |
| 68 | +If you don't see a command prompt, try pressing enter. |
| 69 | +
|
| 70 | +mysql> |
| 71 | +``` |
| 72 | +
|
| 73 | +```sql |
| 74 | +insert into users (first_name, last_name) values ('joe', 'doe'); |
| 75 | +``` |
| 76 | +
|
| 77 | +Expected results: |
| 78 | +
|
| 79 | +```shell |
| 80 | +If you don't see a command prompt, try pressing enter. |
| 81 | + |
| 82 | +mysql> insert into users (first_name, last_name) values ('joe', 'doe'); |
| 83 | +Query OK, 1 row affected (0.00 sec) |
| 84 | + |
| 85 | +mysql> quit |
| 86 | +Bye |
| 87 | +pod "mysql-client" deleted |
| 88 | +``` |
| 89 | + |
| 90 | +### Deploy the Spring Boot Demo App |
| 91 | + |
| 92 | +#### Create Service for Demo App |
| 93 | + |
| 94 | +```shell |
| 95 | +kubectl apply -f app-svc.yaml |
| 96 | +``` |
| 97 | + |
| 98 | +#### Create Deployment for Demo App |
| 99 | + |
| 100 | +```shell |
| 101 | +kubectl apply -f app-dep.yaml |
| 102 | +``` |
| 103 | + |
| 104 | +#### Optional: Check logs |
| 105 | + |
| 106 | +```shell |
| 107 | +kubectl logs -l app=demoapp --follow |
| 108 | +``` |
| 109 | + |
| 110 | +#### Optional: Test with port-forward |
| 111 | + |
| 112 | +```shell |
| 113 | +kubectl logs -l app=demoapp --follow |
| 114 | +``` |
0 commit comments