I built a spring boot project and deployed it with Kubernetes Deployment
,and its configuration file is as follows:
server:
port: 80
spring:
application:
name: demo-kube-svca
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://mysql.dev.svc.cluster.local/kube
username: root
password: 123456
My mysql database is simple to deploy with docker:
Docker run -d \
-p 3306:3306 \
-e MYSQL_ROOT_PASSWORD=123456 \
--name=mysql \
--privileged=true \
Mysql: 8.0
Finally, I want to import the MySQL service into Service Mesh with ServiceEntry
.
apiVersion: networking.istio.io/v1alpha3
Kind: ServiceEntry
Metadata:
Name: mysql-external
Spec:
Hosts:
- mysql.dev.svc.cluster.local
Addresses:
- 192.168.0.123/32
Ports:
- number: 3306
Name: mysql
Protocol: tcp
Location: MESH_EXTERNAL
However, when I use the program to access the database, the error is reported in the log:
Caused by: java.net.UnknownHostException: mysql.dev.svc.cluster.local: Name does not resolve
I refer to the official documentation: https://istio.io/blog/2018/egress-tcp/, I think it may be a problem with my configuration, but I don't know what to do, can you help me?
ServiceEntry
only open firewall in sidecar proxy for you - still you need mysql deployed on Kubernetes to use mysql.dev.svc.cluster.local svc or if you have mysql deployed under IP 192.168.0.123 please use it instead of host.
Edit:
If you need to cover 192.168.0.123 IP address with a service inside Kubernetes you should use external service - as I wrote Istio's ServiceEntry only configure firewall.