|
| 1 | +# Database Connection Strings — P7 Database Administrator |
| 2 | +**Cluster:** petclinic-cluster | **Region:** us-east-1 | **Namespace:** spring-petclinic |
| 3 | +**Verified:** 2026-05-14 |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## Secret (Credentials) |
| 8 | + |
| 9 | +All three databases share one Kubernetes Secret: |
| 10 | + |
| 11 | +```bash |
| 12 | +kubectl get secret petclinic-db-secret -n spring-petclinic |
| 13 | +``` |
| 14 | + |
| 15 | +| Key | Description | |
| 16 | +|-----|-------------| |
| 17 | +| `mysql-user` | App username (`petclinic`) | |
| 18 | +| `mysql-password` | App user password | |
| 19 | +| `mysql-root-password` | Root password | |
| 20 | + |
| 21 | +Reference in your deployment YAML: |
| 22 | +```yaml |
| 23 | +env: |
| 24 | + - name: SPRING_DATASOURCE_USERNAME |
| 25 | + valueFrom: |
| 26 | + secretKeyRef: |
| 27 | + name: petclinic-db-secret |
| 28 | + key: mysql-user |
| 29 | + - name: SPRING_DATASOURCE_PASSWORD |
| 30 | + valueFrom: |
| 31 | + secretKeyRef: |
| 32 | + name: petclinic-db-secret |
| 33 | + key: mysql-password |
| 34 | +``` |
| 35 | +
|
| 36 | +--- |
| 37 | +
|
| 38 | +## customers-db — used by `customers-service` (P5) |
| 39 | + |
| 40 | +| Property | Value | |
| 41 | +|----------|-------| |
| 42 | +| Pod | `customers-db-mysql-0` | |
| 43 | +| Status | Running | |
| 44 | +| ClusterIP | `172.20.37.167` | |
| 45 | +| Pod IP | `10.0.3.76` | |
| 46 | +| Port | `3306` | |
| 47 | + |
| 48 | +**JDBC URL:** |
| 49 | +``` |
| 50 | +jdbc:mysql://customers-db-mysql.spring-petclinic.svc.cluster.local:3306/petclinic |
| 51 | +``` |
| 52 | +
|
| 53 | +**Short form (within same namespace):** |
| 54 | +``` |
| 55 | +jdbc:mysql://customers-db-mysql:3306/petclinic |
| 56 | +``` |
| 57 | +
|
| 58 | +**For `customers-service` deployment env:** |
| 59 | +```yaml |
| 60 | +- name: SPRING_DATASOURCE_URL |
| 61 | + value: "jdbc:mysql://customers-db-mysql:3306/petclinic" |
| 62 | +- name: SPRING_PROFILES_ACTIVE |
| 63 | + value: "docker,mysql" |
| 64 | +``` |
| 65 | + |
| 66 | +--- |
| 67 | + |
| 68 | +## vets-db — used by `vets-service` (P5) |
| 69 | + |
| 70 | +| Property | Value | |
| 71 | +|----------|-------| |
| 72 | +| Pod | `vets-db-mysql-0` | |
| 73 | +| Status | Running | |
| 74 | +| ClusterIP | `172.20.196.142` | |
| 75 | +| Pod IP | `10.0.3.211` | |
| 76 | +| Port | `3306` | |
| 77 | + |
| 78 | +**JDBC URL:** |
| 79 | +``` |
| 80 | +jdbc:mysql://vets-db-mysql.spring-petclinic.svc.cluster.local:3306/petclinic |
| 81 | +``` |
| 82 | + |
| 83 | +**Short form (within same namespace):** |
| 84 | +``` |
| 85 | +jdbc:mysql://vets-db-mysql:3306/petclinic |
| 86 | +``` |
| 87 | + |
| 88 | +**For `vets-service` deployment env:** |
| 89 | +```yaml |
| 90 | +- name: SPRING_DATASOURCE_URL |
| 91 | + value: "jdbc:mysql://vets-db-mysql:3306/petclinic" |
| 92 | +- name: SPRING_PROFILES_ACTIVE |
| 93 | + value: "docker,mysql" |
| 94 | +``` |
| 95 | +
|
| 96 | +--- |
| 97 | +
|
| 98 | +## visits-db — used by `visits-service` (P6) |
| 99 | + |
| 100 | +| Property | Value | |
| 101 | +|----------|-------| |
| 102 | +| Pod | `visits-db-mysql-0` | |
| 103 | +| Status | Running | |
| 104 | +| ClusterIP | `172.20.124.137` | |
| 105 | +| Pod IP | `10.0.3.135` | |
| 106 | +| Port | `3306` | |
| 107 | + |
| 108 | +**JDBC URL:** |
| 109 | +``` |
| 110 | +jdbc:mysql://visits-db-mysql.spring-petclinic.svc.cluster.local:3306/petclinic |
| 111 | +``` |
| 112 | +
|
| 113 | +**Short form (within same namespace):** |
| 114 | +``` |
| 115 | +jdbc:mysql://visits-db-mysql:3306/petclinic |
| 116 | +``` |
| 117 | +
|
| 118 | +**For `visits-service` deployment env:** |
| 119 | +```yaml |
| 120 | +- name: SPRING_DATASOURCE_URL |
| 121 | + value: "jdbc:mysql://visits-db-mysql:3306/petclinic" |
| 122 | +- name: SPRING_PROFILES_ACTIVE |
| 123 | + value: "docker,mysql" |
| 124 | +``` |
| 125 | + |
| 126 | +--- |
| 127 | + |
| 128 | +## Quick Connectivity Test Commands |
| 129 | + |
| 130 | +```bash |
| 131 | +# Test customers-db |
| 132 | +kubectl exec -i customers-db-mysql-0 -n spring-petclinic -- \ |
| 133 | + mysql -u petclinic -p<PASSWORD> petclinic -e "SELECT 'OK';" |
| 134 | + |
| 135 | +# Test vets-db |
| 136 | +kubectl exec -i vets-db-mysql-0 -n spring-petclinic -- \ |
| 137 | + mysql -u petclinic -p<PASSWORD> petclinic -e "SELECT 'OK';" |
| 138 | + |
| 139 | +# Test visits-db |
| 140 | +kubectl exec -i visits-db-mysql-0 -n spring-petclinic -- \ |
| 141 | + mysql -u petclinic -p<PASSWORD> petclinic -e "SELECT 'OK';" |
| 142 | + |
| 143 | +# Get the password from the secret |
| 144 | +kubectl get secret petclinic-db-secret -n spring-petclinic \ |
| 145 | + -o jsonpath='{.data.mysql-password}' | base64 --decode |
| 146 | +``` |
| 147 | + |
| 148 | +--- |
| 149 | + |
| 150 | +## Notes for P5 and P6 |
| 151 | + |
| 152 | +- Databases are ready — **no manual schema setup needed.** Spring Boot auto-runs `schema.sql` and `data.sql` on first startup when `mysql` profile is active. |
| 153 | +- Always use the **Service DNS name** (e.g., `customers-db-mysql`), not the pod IP — pod IPs change on restart. |
| 154 | +- All databases are `ClusterIP` (internal only) — not reachable from outside the cluster. |
| 155 | +- Secret `petclinic-db-secret` already exists in the `spring-petclinic` namespace — just reference it in your deployment YAML. |
0 commit comments