美文网首页
k8s一键部署单节点mongo

k8s一键部署单节点mongo

作者: 渡边Hok | 来源:发表于2021-12-31 17:53 被阅读0次
    kind: PersistentVolumeClaim
    apiVersion: v1
    metadata:
      name: default-mongo-pvc
      namespace: default
      labels:
        dir: default-mongo
    spec:
      accessModes:
        - ReadWriteMany
      resources:
        requests:
          storage: 500Mi
      storageClassName: nfs-subdir-client  //需安装nfs-client插件
      volumeMode: Filesystem
    
    ---
    kind: ConfigMap
    metadata:
      name: mongodb-conf
      namespace: default
    apiVersion: v1
    data:
      mongod.conf: |-
        #dbpath=/mongo/data
        #logpath=/mongo/log/mongodb.log
        #pidfilepath=/mongo/key/master.pid
        directoryperdb=true
        logappend=true
        bind_ip=0.0.0.0
        port=27017
    
    ---
    
    apiVersion: apps/v1
    kind: StatefulSet
    metadata: 
      name: mongo-1
      namespace: default
      app: mongo-cluster
    spec: 
      selector: 
        matchLabels: 
          name: mongo-1
      serviceName: "mongo-1"
      replicas: 1
      podManagementPolicy: Parallel
      template: 
        metadata: 
          labels: 
            name: mongo-1
            app: mongo-cluster
        spec: 
          terminationGracePeriodSeconds: 10
          affinity: 
             podAntiAffinity: 
               requiredDuringSchedulingIgnoredDuringExecution: 
               - labelSelector: 
                   matchExpressions: 
                   - key: "name"
                     operator: In
                     values: 
                     - mongo
                 topologyKey: "kubernetes.io/hostname"
          containers: 
          - name: mongo
            image: mongo:4.2
            imagePullPolicy: IfNotPresent
            command:  
            - mongod 
            - "-f"
            - "/etc/mongod.conf"
            - "--bind_ip_all"
            ports: 
            - containerPort: 27017
            volumeMounts: 
            - name: mongo-cnf-volume
              mountPath: /etc/mongod.conf/
              subPath: mongod.conf
            - name: mongo-dir
              mountPath: /mongo
          volumes:
            - name: mongo-cnf-volume     #映射configMap信息
              configMap:
                name: mongodb-conf
                items:
                  - key: mongod.conf
                    path: mongod.conf
            - name: mongo-dir
              persistentVolumeClaim:
                claimName: default-mongo-pvc
    ---
    
    
    kind: Service
    apiVersion: v1
    metadata:
      name: mongo
      namespace: default
    spec:
      ports:
        - protocol: TCP
          port: 37017
          targetPort: 27017 
      selector:
        name: mongo-1
      type: LoadBalancer
    

    相关文章

      网友评论

          本文标题:k8s一键部署单节点mongo

          本文链接:https://www.haomeiwen.com/subject/effnqrtx.html