aumanjoa
aumanjoa

Reputation: 955

using azure cosmos mongodb inside kubernetes

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://learn.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

Upvotes: 1

Views: 1243

Answers (1)

vascop
vascop

Reputation: 5212

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

Upvotes: 1

Related Questions