• k8s-statefulset创建mongo集群


    首先创建headless

    #创建对应的headless service
    apiVersion: v1
    kind: Service
    metadata:
     name: mongo
     labels:
      name: mongo
    spec:
     ports:
     - port: 27017
       targetPort: 27017
     clusterIP: None
     selector:
      role: mongo     
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

    创建statefulset

    #创建StatusFulSet mongoDB
    apiVersion: apps/v1
    kind: StatefulSet
    metadata:
     name: mongo
    spec:
     selector:
       matchLabels:
        role: mongo #必须匹配 .spec.template.metadata.labels
     serviceName: "mongo"
     replicas: 3
     template:
      metadata:
       labels:
        role: mongo
        environment: test
      spec:
       terminationGracePeriodSeconds: 10
       containers:
       - name: mongo
         image: mongo
         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 #设置为mongo容器的标签,用于sidecar查询它所要管理的mongoDB集群实例
           value: "role=mongo,environment=test"
         - name: KUBERNETES_MONGO_SERVICE_NAME #设置为mongo,表示sidecar将使用mongo这个服务名来完成MongoDB集群的设置
           value: "mongo"
     volumeClaimTemplates:
     - metadata:
        name: mongo-persistent-storage
       spec:
        accessModes: [ "ReadWriteOnce" ] #读写权限
        storageClassName: standard  #存储类storageClass名 这里使用k8s自带的StorageClass,它使用的是本地存储 localPath
        resources:
         requests:
           storage: 5Gi
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
  • 相关阅读:
    【新学期、新Flag】例文:我的新学期Flag
    营养成分查询易语言代码
    @Mapper与@MapperScan注解
    Springboo整合Sentinel
    [微前端实战]---021软件设计原则与分层
    nodejs版本管理实践指南
    51单片机学习:DAC模数转换实验
    低效程序根源追溯——记一次刷题对性能的不满
    golang profiling
    一文搞懂云原生架构
  • 原文地址:https://blog.csdn.net/ltgsoldier1/article/details/133246031