简体   繁体   English

Kubernetes在Pod内部使用外部服务

[英]Kubernetes use External Services inside Pod

im Running Kubernetes (minikube) on Windows via Virtualbox. 通过Virtualbox在Windows上运行Kubernetes(minikube)。 I've got a Services running on my Host-Service i dont want to put inside my Kubernetes Cluster, how can i access that Services from Inside my Pods? 我有一个服务在我的主机服务上运行我不想放入我的Kubernetes集群,我如何从Inside my Pods访问该服务?

Im new to to Kubernetes i hope this Questions isnt to stupid to ask. 我是Kubernetes的新手,我希望这个问题不是愚蠢的问题。

I tried to create a Service + Endpoint but it didnt work: 我试图创建一个Service + Endpoint,但它没有用:

 kind: Endpoints apiVersion: v1 metadata: name: vetdb subsets: - addresses: - ip: 192.168.99.100 ports: - port: 3307 

 kind: Service apiVersion: v1 metadata: name: vetdb spec: selector: app: vetdb type: ClusterIP ports: - port: 3306 targetPort: 3307 

i started a ubuntu image inside the same cluster the pod should be running on later and tested the connection: 我在稍后运行pod的同一群集中启动了一个ubuntu映像并测试了连接:

 $ root@my-shell-7766cd89c6-rtxt2:/# curl vetdb:3307 --output test Host '192.168.99.102' is not allowed to connect to this MariaDB serverroot@my-shell 

This is the same Output i get running (except other Host-IP) 这与我运行的输出相同(除了其他主机IP)

curl 192.168.99.100:3307

on my Host PC ==> Itworks. 在我的主机PC上==> Itworks。

But i cant access the Host from inside my Microservices where i really need to access the URL. 但我无法从我的微服务中访问主机,我真的需要访问该URL。

 $ kubectl get pods NAME READY STATUS RESTARTS AGE eureka-77f949499-g2l82 1/1 Running 0 2h my-shell-7766cd89c6-rtxt2 1/1 Running 0 2h vet-ms-54b89f9c86-29psf 1/1 Running 10 18m vet-ms-67c774fd9b-2fnjc 0/1 CrashLoopBackOff 7 18m 

The Curl Response i posted above was from Pod: my-shell-7766cd89c6-rtxt2 But i need to access vetdb from vet-ms-* 上面发布的卷曲响应来自Pod: my-shell-7766cd89c6-rtxt2但我需要从vet-ms-*访问vetdb

 $ kubectl logs -f vet-ms-67c774fd9b-2fnjc ... Caused by: java.net.UnknownHostException: vetdb ... 

Spring URL Settings i tried 我试过的Spring URL设置

spring.profiles.datasource.url: jdbc:mysql://vetdb:3307/vetdb?useSSL=false&allowPublicKeyRetrieval=true
 spring.profiles.datasource.url: jdbc:mysql://vetdb:3306/vetdb?useSSL=false&allowPublicKeyRetrieval=true 
spring.profiles.datasource.url: jdbc:mysql://vetdb/vetdb?useSSL=false&allowPublicKeyRetrieval=true

Ty guys Ty伙计们



Edit:// i allowed every Host to Connect to the DB to remove this error 编辑://我允许每个主机连接到数据库以删除此错误

Host '192.168.99.102' is not allowed to connect to this MariaDB

but i still get the Same Unknown Host Exception inside of my Microservices. 但我仍然在我的微服务中得到相同的未知主机异常。

I think the Ubuntu image test is most informative here. 我认为Ubuntu图像测试在这里提供的信息最丰富。

From the error message I think the problem is in the MySQL config. 从错误消息我认为问题出在MySQL配置中。 You must configure server to listen on port of your host IP address (ie not localhost or socketfile). 您必须将服务器配置为侦听主机IP地址的端口(即不是localhost或socketfile)。

In addition, you must also ensure that IP address from pod subnets are allowed to connect also. 此外,还必须确保允许来自pod子网的IP地址进行连接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM