在kubernetes里面使用azure色的宇宙mongodb
我有一个使用mongoDb的nodeJS api。 我在kubernetes集群中部署应用程序。 在这里你可以findkubernetes的yml文件https://github.com/daumann/chronas-api/tree/azure/kuberneties
现在我想用一个容器的mongodb instatt的azure cosmosdb。 https://docs.microsoft.com/en-us/azure/cosmos-db/mongodb-introduction
有人可以帮助我,我怎么能做到这一点。 这将创build仅使用kuberneties的yml文件来做到这一点。
干杯
假设您已经通过Azure启动了您的cosmos-db,则需要使用生成的连接string作为秘密(因为它包含密码)可以传递给应用程序。 连接string的格式为:
mongodb://username:password@host:port/[database]?ssl=true
要创build一个秘密(假设您将连接string粘贴到connstring.txt
文件中:
kubectl create secret generic cosmos-db-secret --from-file=./connstring.txt
然后在应用程序的部署定义中添加:
env: - name: MONGO_HOST valueFrom: secretKeyRef: name: cosmos-db-secret key: connstring