How to consume external MongoDB service in Kubernetes How to consume external MongoDB service in Kubernetes kubernetes kubernetes

How to consume external MongoDB service in Kubernetes


There are many ways to consume an external service, such as:

  1. Hardcoding the IP:Port of the service in your app.
  2. Using environment variables in your app and injecting them through configmaps.
  3. Creating a service/endpoint, ExternalName service, or a service with External IPs. This allows your applications to useKubernetes' Service Discovery mechanisms.

In your case you can just use:
const MONGO_URI = 'mongodb://mongo/${config.collection}?authSource=admin';
as the name mongo will be mapped to 159.89.x.x:xxx