k8s mongodb 集群配置

service.yaml

apiVersion: v1
kind: Service
metadata:
 name: mongo
 labels:
 name: mongo
spec:
 ports:
 - port: 27017
 targetPort: 27017
 clusterIP: None
 selector:
 role: mongo

 

StatefulSet

apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
 name: mongo
spec:
 serviceName: "mongo"
 replicas: 3
 template:
 metadata:
 labels:
   role: mongo
   environment: test
 spec:
 terminationGracePeriodSeconds: 10
 containers:
   - name: mongo
     image: mongo
     command:
       - mongod
       - "--replSet"
       - rs0
       - "--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: "fast"
 spec:
 accessModes: ["ReadWriteOnce"]
 resources:
   requests:
     storage: 100Gi

 

 

 

 

 

https://kubernetes.io/blog/2017/01/running-mongodb-on-kubernetes-with-statefulsets/

    原文作者:MongoDB
    原文地址: https://www.cnblogs.com/fengjian2016/p/9163393.html
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞