[英]run mongodb inside kubernetes - azure aks fails
I try to run an mongodb inside an kubernetes cluster which is hosted on azure aks 我尝试在以azure aks托管的kubernetes集群中运行mongodb
I was not able to get it running, following this tutorial: https://kubernetes.io/blog/2017/01/running-mongodb-on-kubernetes-with-statefulsets/ 按照本教程操作后,我无法使其运行: https : //kubernetes.io/blog/2017/01/running-mongodb-on-kubernetes-with-statefulsets/
here is the yaml I use: 这是我使用的Yaml:
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
name: default-view
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: view
subjects:
- kind: ServiceAccount
name: default
namespace: default
---
apiVersion: v1
kind: Service
metadata:
name: mongo
labels:
name: mongo
spec:
ports:
- port: 27017
targetPort: 27017
clusterIP: None
selector:
role: mongo
---
apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
name: mongo
spec:
serviceName: "mongo"
replicas: 2
template:
metadata:
labels:
role: mongo
environment: test
spec:
terminationGracePeriodSeconds: 10
containers:
- name: mongo
image: mongo
command:
- mongod
- "--replSet"
- rs0
- "--bind_ip"
- 0.0.0.0
- "--smallfiles"
- "--noprealloc"
ports:
- containerPort: 27017
volumeMounts:
- name: mongo-persistent-storage
mountPath: /data/db
- name: mongo-sidecar
image: cvallance/mongo-k8s-sidecar
env:
- name: MONGO_SIDECAR_POD_LABELS
value: "role=mongo,environment=test"
volumeClaimTemplates:
- metadata:
name: mongo-persistent-storage
annotations:
volume.beta.kubernetes.io/storage-class: "managed-premium"
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 32Gi
The connection string I use is: 我使用的连接字符串是:
"mongodb://mongo-0.mongo,mongo-1.mongo:27017/databasename\\_?" “MongoDB的://mongo-0.mongo,mongo-1.mongo:27017 /数据库名称\\ _”
from my JS application I get: 从我的JS应用程序中我得到:
database names cannot contain the character '\\'
数据库名称不能包含字符“ \\”
How I can connect from the JS application to the mongodb? 如何从JS应用程序连接到mongodb?
mongodb://mongo-0.mongo,mongo-1.mongo:27017
MongoDB的://mongo-0.mongo,mongo-1.mongo:27017
You are indicating that you have a replicaset with 2 members and both use the port 27017. Your mongodb library will handle that url to connect to the cluster. 您所指示的副本集包含2个成员,并且都使用端口27017。mongodb库将处理该URL以连接到集群。
In order to connect locally you have to do a port forwarding: 为了本地连接,您必须进行端口转发:
kubectl port-forward mongo-0 27017 # or mongo-1
kubectl端口转发mongo-0 27017#或mongo-1
Then you can connect to the chosen mongodb with Robo 3T using your localhost (127.0.0.1) and the port 27017. 然后,您可以使用本地主机(127.0.0.1)和端口27017使用Robo 3T连接到所选的mongodb。
I was able to fix the problem using this connection string: 我可以使用以下连接字符串解决问题:
mongodb://mongo-0.mongo,mongo-1.mongo:27017/chronas-api_?
MongoDB的://mongo-0.mongo,mongo-1.mongo:27017 / chronas-API_?
But can someone please explain me this connection string magic and also how I can connect to this cluster using "Robo 3T"? 但是有人可以向我解释一下这种连接字符串魔术,以及如何使用“ Robo 3T”连接到该集群吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.