Calling an external service from within Minikube

前端 未结 2 1996
长情又很酷
长情又很酷 2020-12-10 10:00

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 Miniku

相关标签:
2条回答
  • 2020-12-10 10:16

    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.

    0 讨论(0)
  • 2020-12-10 10:21

    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.

    0 讨论(0)
提交回复
热议问题