简体   繁体   English

在kubernetes中运行mongodb-Azure Aks失败

[英]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.

相关问题 如何在 Azure Kube.netes 服务 (AKS) 上对 MongoDB 执行增量备份,它不是副本集 (StandAlone)? - How can I perform incremental backup for MongoDB which is not replicaset( StandAlone) on Azure Kubernetes Services(AKS)? 在Azure中运行MongoDB - Run MongoDB in Azure azure aks将在k8集群中运行的mongodb备份到本地文件或azure存储中 - azure aks take backup of mongodb running in k8 cluster to local file or azure storage MongoDB Atlas - Ruby 连接在 Kubernetes 中不起作用 - MongoDB Atlas - Ruby connection not working inside Kubernetes CrashLoopBackOff同时增加了针对MongoDB映像的Azure AKS群集上的副本数量超过1 - CrashLoopBackOff while increasing replicas count more than 1 on Azure AKS cluster for MongoDB image 使用 MongoDb 指南针 GUI 连接到 MongoDB 副本集(在 kubernetes 内) - Connecting to a MongoDB replicaset (inside kubernetes) with MongoDb compass GUI 将 MongoDB 罗盘客户端连接到 kubernetes 集群内的 mongodb 数据库 - Connect MongoDB compass client to the mongodb database inside kubernetes cluster helm upgrade mongodb 失败并出现错误“无法构建 kubernetes 对象” - helm upgrade mongodb fails with error "unable to build kubernetes objects" Kubernetes与MongoDb - Kubernetes with MongoDb 在 Azure VM 中对 mongoDB 运行定期代码 - Run periodic codes to mongoDB in Azure VM
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM