从Minikube内部呼叫外部服务

Chr*_*n68 2 kubernetes minikube

我有一个服务(/ deployment/pod)在我的Minikube(安装在我的Mac上)上运行,需要调用直接在我的Mac上运行的外部http服务(即Minikube外部).该外部服务的域名已定义到我的Mac/etc/hosts文件中.然而,我在Minikube内的服务不能称之为外部服务.知道我需要配置在哪里?非常感谢.C

Sha*_*uza 5

创建Endpoints将流量转发到您想要的外部IP地址(您的本地计算机).你可以直接连接使用,Endpoints但根据Goole Cloud best practice(doc)是通过一个访问它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
Run Code Online (Sandbox Code Playgroud)

然后创造你 Service

kind: Service
apiVersion: v1
metadata:
 name: local-ip
Spec:
 type: ClusterIP
 ports:
 - port: 27017
   targetPort: 27017
Run Code Online (Sandbox Code Playgroud)

现在,您可以使用Service名称调用外部http服务.在这种情况下,loal-ip像任何其他内部服务minikube.