<p>I have a mongodb server hosted outside GCP, I want to connect to it using Kubernetes endpoint service as shown here [<a href="https://www.youtube.com/watch?v=fvpq4jqtuZ8]" rel="nofollow noreferrer">https://www.youtube.com/watch?v=fvpq4jqtuZ8]</a>. How can I do that? Can you write a sample YAML file for the same?</p>

Darshan Naik
<p>use <strong>static Kubernetes service</strong>, when you have got <strong>the Internal IP and Port number</strong> for externally hosted service. </p>

<pre><code>kind: Service
apiVersion: v1
metadata:
 name: mongo
Spec:
 type: ClusterIP
 ports:
 - port: 27017
   targetPort: 27017
</code></pre>

<p>As  there are no Pod selectors for this service , There will not be any endpoints thus we can create a endpoint object manually.</p>

<pre><code>kind: Endpoints
apiVersion: v1
metadata:
name: mongo
subsets:
- addresses:
    - ip: 10.240.0.4  # Replace ME with your IP
  ports:
    - port: 27017
</code></pre>

<p>make sure that service and endpoints are having same name (for example mongo)</p>

<blockquote>
  <p>If the IP address changes in the future, you can update the Endpoint with the new IP address, and your applications won’t need to make any changes.<a href="https://cloud.google.com/blog/products/gcp/kubernetes-best-practices-mapping-external-services" rel="noreferrer">mapping-external-services</a></p>
</blockquote>
