简体   繁体   English

Kubernetes与MongoDb

[英]Kubernetes with MongoDb

I followed the https://www.mongodb.com/blog/post/running-mongodb-as-a-microservice-with-docker-and-kubernetes and tried to run a single mongodb instance with a LoadBalancer Service and Replication Controller on a Google Cloud account. 我按照https://www.mongodb.com/blog/post/running-mongodb-as-a-microservice-with-docker-and-kubernetes尝试运行带有LoadBalancer服务和复制控制器的单个mongodb实例Google Cloud帐户。

Following is the yaml file: 以下是yaml文件:

---
apiVersion: v1
kind: Service
metadata:
  name: mongo-svc-a
  labels:
    name: mongo-svc-a
spec:
  type: LoadBalancer
  ports:
  - port: 27017
    targetPort: 27017
    protocol: TCP
    name: mongo-svc-a
  selector:
    name: mongo-node1
    instance: rod
---
apiVersion: v1
kind: ReplicationController
metadata:
  name: mongo-rc1
  labels:
    name: mongo-rc
spec:
  replicas: 1
  selector:
    name: mongo-node1
  template:
    metadata:
      labels:
        name: mongo-node1
        instance: rod
    spec:
      containers:
      - name: mongo-node1
        image: mongo
        ports:
        - containerPort: 27017
        volumeMounts:
        - name: mongo-persistent-storage1
          mountPath: /data/db
      volumes:
      - name: mongo-persistent-storage1
        gcePersistentDisk:
          pdName: mongodb-disk1-in-cluster1
          fsType: ext4

Following are the details of the Service, Replication Controller and Pods that were created. 以下是已创建的服务,复制控制器和窗格的详细信息。 All seems to be fine. 一切似乎都很好。

$ kubectl describe service mongo-svc-a 
Name:                   mongo-svc-a
Namespace:              default
Labels:                 name=mongo-svc-a
Selector:               instance=rod,name=mongo-node1
Type:                   LoadBalancer
IP:                     10.3.241.11
LoadBalancer Ingress:   104.198.236.2
Port:                   mongo-svc-a     27017/TCP
NodePort:               mongo-svc-a     31808/TCP
Endpoints:              10.0.0.3:27017
Session Affinity:       None
No events.


$ kubectl describe rc mongo-rc1
Name:           mongo-rc1
Namespace:      default
Image(s):       mongo
Selector:       name=mongo-node1
Labels:         name=mongo-rc
Replicas:       1 current / 1 desired
Pods Status:    1 Running / 0 Waiting / 0 Succeeded / 0 Failed
Volumes:
  mongo-persistent-storage1:
    Type:       GCEPersistentDisk (a Persistent Disk resource in Google Compute Engine)
    PDName:     mongodb-disk1-in-cluster1
    FSType:     ext4
    Partition:  0
    ReadOnly:   false
No events.


$ kubectl describe pod mongo-rc1-h0j8r
Name:           mongo-rc1-h0j8r
Namespace:      default
Node:           gke-cluster1-default-pool-d58b6c05-74fq/10.128.0.6
Start Time:     Sat, 11 Feb 2017 18:43:00 +0530
Labels:         instance=rod
                name=mongo-node1
Status:         Running
IP:             10.0.0.3
Controllers:    ReplicationController/mongo-rc1
Containers:
  mongo-node1:
    Container ID:       docker://9f28e482d3806b74f7f595c47e6c7940c2313e95860db13d137ad6eaa88bb341
    Image:              mongo
    Image ID:           docker://sha256:ad974e767ec4f06945b1e7ffdfc57bd10e06baf66cdaf5a003e0e6a36924e30b
    Port:               27017/TCP
    Requests:
      cpu:              100m
    State:              Running
      Started:          Sat, 11 Feb 2017 18:45:37 +0530
    Ready:              True
    Restart Count:      0
    Volume Mounts:
      /data/db from mongo-persistent-storage1 (rw)
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-3wfv3 (ro)
    Environment Variables:      <none>
Conditions:
  Type          Status
  Initialized   True 
  Ready         True 
  PodScheduled  True 
Volumes:
  mongo-persistent-storage1:
    Type:       GCEPersistentDisk (a Persistent Disk resource in Google Compute Engine)
    PDName:     mongodb-disk1-in-cluster1
    FSType:     ext4
    Partition:  0
    ReadOnly:   false
  default-token-3wfv3:
    Type:       Secret (a volume populated by a Secret)
    SecretName: default-token-3wfv3
QoS Class:      Burstable
Tolerations:    <none>
No events.

But when i try to remote connect, mongo --hostname <Extenal_IP_of_the_service> to the newly created monogdb instance, i am unable to connect. 但是当我尝试远程连接mongo --hostname <Extenal_IP_of_the_service>到新创建的monogdb实例时,我无法连接。 I believe the configuration seems alright. 我相信配置似乎没问题。 Any help would be appreciated. 任何帮助,将不胜感激。 Thanks, 谢谢,

  • Pavan 帕文

Tried a different approach and nailed it. 尝试了不同的方法并将其钉死。

Followed the following tutorial: https://kubernetes.io/docs/tutorials/stateful-application/run-stateful-application/ 遵循以下教程: https//kubernetes.io/docs/tutorials/stateful-application/run-stateful-application/

Exposed the headless service: 暴露无头服务:

kubectl expose service your_service_name --port=27017 --target-port=27017 --name=mongo-lb-service --type=LoadBalancer

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM