I'm setting up a new server using kubernetes to run Spring boot microservice. How do i get Spring boot app connected to external oracle database? (Database ip is 170.27.10.10:1521)
Kube Master's IP: 170.16.163.10 Kube Node's IP: 170.16.163.11 Kube Node can connect to server db.
I create deployment by command:
kubectl run db-deployment --image 170.16.163.30:5000/mcrdb:0.0.4 --replicas=2 --port=8083
kubectl expose deployment db-deployment --type=LoadBalancer --port=8083 --target-port=8083
And create service:
kind: "Service"
apiVersion: "v1"
metadata:
name: "dbdev"
spec:
ports:
-
name: "oracle-db"
protocol: "TCP"
port: 1521
targetPort: 1521
nodePort: 0
kind: Endpoints
apiVersion: v1
metadata:
name: dbdev
subsets:
- addresses:
- ip: 170.27.10.10
ports:
- port: 1521
And config db in application.properties
spring.datasource.url=jdbc:oracle:thin:@170.27.10.10:1521/vservice
spring.datasource.username=dev_user
spring.datasource.password=dev_pass
Microservice can not started with error connect to oracle db.
can you try below changes
kind: Service
apiVersion: v1
metadata:
name: dbdev
spec:
ports:
-
name: oracle-db
protocol: TCP
port: 1521
targetPort: 1521
kind: Endpoints
apiVersion: v1
metadata:
name: dbdev
subsets:
- addresses:
- ip: 170.27.10.10
ports:
- port: 1521
application.properties
------------------------
spring.datasource.url=jdbc:oracle:thin:@dbdev:1521/vservice
spring.datasource.username=dev_user
spring.datasource.password=dev_pass