Calling an external service from within Minikube

萝らか妹 提交于 2019-11-30 20:29:12

问题


I have a service (/deployment/pod) running in my Minikube (installed on my Mac) that needs to call an external http service that runs directly on my Mac (i.e. outside Minikube). The domain name of that external service is defined into my Mac /etc/hosts file. Yet, my service within Minikube cannot call that external service. Any idea what I need to configure where? Many thanks. C


回答1:


Create Endpoints that will forward traffic to your desire external IP address (your local machine). You can directly connect using Endpoints but according to Goole Cloud best practice (doc) is to access it through a Service

Create your Endpoints

kind: Endpoints
apiVersion: v1
metadata:
 name: local-ip
subsets:
 - addresses:
     - ip: 10.240.0.4  # IP of your desire end point
   ports:
     - port: 27017     # Port that you want to access

Then create you Service

kind: Service
apiVersion: v1
metadata:
 name: local-ip
Spec:
 type: ClusterIP
 ports:
 - port: 27017
   targetPort: 27017

Now you can call external http service using the Service name. In this case loal-ip like any other internal service of minikube.




回答2:


Because your minikube is running on a virtual machine on your laptop , you just need minikube ssh into that machine and enter the address of your external service into the /etc/hosts file of that virtual machine.




回答3:


Thanks to both of you for your prompt answer. The solution that consists in changing the /etc/hosts file would not work. The other solution (creating an endpoint and a corresponding service) worked well. Thanks again - I have really been struggling with that.



来源:https://stackoverflow.com/questions/54464722/calling-an-external-service-from-within-minikube

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!