我正在使用kubernetes设置新服务器来运行Spring Boot微服务。我如何将Spring Boot App连接到外部Oracle数据库? (数据库ip为170.27.10.10:1521)
Kube Master的IP:170.16.163.10 Kube Node的IP:170.16.163.11 Kube Node可以连接到服务器数据库。
我通过命令创建部署:
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
并创建服务:
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
在application.properties中配置db
spring.datasource.url=jdbc:oracle:thin:@170.27.10.10:1521/vservice
spring.datasource.username=dev_user
spring.datasource.password=dev_pass
微服务无法连接到oracle db时出错。
答案 0 :(得分:0)
您可以尝试以下更改
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