title: How to consume external MongoDB service in Kubernetes
body: <p>I have been setting up a Kubernetes cluster for my work deployment. I have my MongoDB hosted on an external droplet and want to configure external service access.</p>
  
  <p>I am following this <a href="https://cloud.google.com/blog/products/gcp/kubernetes-best-practices-mapping-external-services" rel="nofollow noreferrer">tutorial</a>.
  When I apply the my configuration with kubectl everything seems to be running fine.</p>
  
  <p>My setup service &amp; Endpoint</p>
  
  <pre><code>kind: Service
  apiVersion: v1
  metadata:
   name: mongo
  spec:
   ports:
   - name: mongodb
     port: xxxx
  ------
  kind: Endpoints
  apiVersion: v1
  metadata:
   name: mongo
  subsets:
   - addresses:
       - ip: 159.89.x.x
     ports:
       - port: xxx
  </code></pre>
  
  <p>I am developing using typescript and this is how I currently set up my DB connection</p>
  
  <pre><code>const MONGO_URI = `mongodb://${config.mongourl}:${config.mongoport}/${config.collection}?authSource=admin`;
   const options ={
      user:`${config.mngusername}`, 
      pass:`${config.mngpassword}`,
      keepAlive: true, 
      keepAliveInitialDelay: 300000,
      useNewUrlParser: true,
      useCreateIndex: true
   }
  mongoose.connect(MONGO_URI, options);
  </code></pre>
  
  <p>My question is, how do I consume the setup service/deploymentsin my code.
  <br><b>thanks</b></p>