问题描述
我在Minikube(安装在Mac上)中运行了一项服务(/deployment/pod),该服务需要调用直接在Mac(即Minikube外部)上运行的外部http服务.该外部服务的域名已定义在我的Mac/etc/hosts文件中.但是,我在Minikube中的服务无法调用该外部服务.知道我需要在哪里配置吗?非常感谢. C
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
推荐答案
创建Endpoints
,它将把流量转发到所需的外部IP地址(您的本地计算机).您可以使用Endpoints
直接连接,但根据Goole Cloud best practice
(文档)是通过Service
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
创建您的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
然后创建您Service
kind: Service
apiVersion: v1
metadata:
name: local-ip
Spec:
type: ClusterIP
ports:
- port: 27017
targetPort: 27017
现在,您可以使用Service
名称调用外部http服务.在这种情况下,loal-ip
就像minikube
的任何其他内部服务一样.
Now you can call external http service using the Service
name. In this case loal-ip
like any other internal service of minikube
.
这篇关于从Minikube内部调用外部服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!