using azure cosmos mongodb inside kubernetes

11/6/2017

I have a nodeJS api which uses a mongoDb. I deploy the application in a kubernetes cluster. Here you can find the kubernetes yml files https://github.com/daumann/chronas-api/tree/azure/kuberneties

Now I want to use the azure cosmosdb for mongodb instatt of an container. https://docs.microsoft.com/en-us/azure/cosmos-db/mongodb-introduction

Can someone help me how I can do that. It would be create to use only the yml files from kuberneties to do so.

Cheers

-- aumanjoa
azure
azure-cosmosdb
kubernetes
mongodb
node.js

1 Answer

11/7/2017

Assuming you already launched your cosmos-db through Azure, you will need to use the generated connection string that you can pass to your application as a secret (since it contains a password). The connection string is of the format:

mongodb://username:password@host:port/[database]?ssl=true

To create a secret (assuming you paste your connection string into the connstring.txt file:

kubectl create secret generic cosmos-db-secret --from-file=./connstring.txt

Then in your application's deployment definition add:

env:
  - name: MONGO_HOST
    valueFrom:
      secretKeyRef:
        name: cosmos-db-secret
        key: connstring
-- vascop
Source: StackOverflow