zoukankan      html  css  js  c++  java
  • kubernetes使用statefulset部署mongoDB 单机版 自定义配置文件、密码等

    注:

    • 官方镜像地址: https://hub.docker.com/_/mongo?tab=description

    • docker版的mongo移除了默认的/etc/mongo.conf, 修改了db数据存储路径为 /data/db.

    • 创建configmap配置,注意不能加fork=true,否则Pod会变成Completed。

    • 存储:aliyun nas

    • svc: ClusterIP ? Headless Service ?

    资源清单

    configmap.yaml

    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: mongodb-conf
      namespace: zisefeizhu
    data:
      mongodb.conf: |
        dbpath=/data/zisefeizhu/mongodb
        logpath=/data/zisefeizhu/mongodb/mongodb.log
        pidfilepath=/data/zisefeizhu/mongodb/master.pid
        directoryperdb=true
        logappend=true
        bind_ip=0.0.0.0
        port=27017
    

    storageclass.yaml

    apiVersion: storage.k8s.io/v1
    kind: StorageClass
    metadata:
      name: mongodb
      namespace: zisefeizhu
    mountOptions:
      - nolock,tcp,noresvport
      - vers=3
    parameters:
      volumeAs: subpath
      server: "7131dxxxxxxxxxxxxxxxxxxxxxxcs.com:/mongodb/"
    provisioner: nasplugin.csi.alibabacloud.com
    reclaimPolicy: Retain
    

    svc.yaml

    kind: Service
    apiVersion: v1
    metadata:
      labels:
        name: mongodb
      name: mongodb
      namespace: zisefeizhu
    spec:
      type: ClusterIP
      ports:
        - name: mongodb
          port: 27017
          targetPort: 27017
      selector:
        name: mongodb
    

    statefulset.yaml

    apiVersion: apps/v1
    kind: StatefulSet
    metadata:
      name: mongodb
      namespace: zisefeizhu
    spec:
      replicas: 1
      podManagementPolicy: OrderedReady  #按照顺序启动或者终止Pod
      serviceName: mongodb
      selector:
        matchLabels:
          name: mongodb
      template:
        metadata:
          labels:
            name: mongodb
        spec:
          containers:
            - name: mongodb
              image: mongo:4.2.1
              command:
                - sh
                - -c
                - "exec mongod -f /data/zisefeizhu/mongodb/conf/mongodb.conf"
              imagePullPolicy: IfNotPresent
              ports:
                - containerPort: 27017
                  name: mongodb
                  protocol: TCP
              volumeMounts:
                - name: mongodb-config
                  mountPath: /data/zisefeizhu/mongodb/conf/
                - name: data
                  mountPath: /data/zisefeizhu/mongodb/
          volumes:
            - name: mongodb-config
              configMap:
                name: mongodb-conf
      volumeClaimTemplates: #定义创建PVC使用的模板
        - metadata:
            name: data
            annotations: #这是指定storageclass
              volume.beta.kubernetes.io/storage-class: mongodb
          spec:
            accessModes:
              - ReadWriteOnce
            resources:
              requests:
                storage: 100Gi
    

    测试

    # ctl get pods -n zisefeizhu | grep mongodb
    mongodb-0   1/1     Running   0          25m
    

    连接

     ctl exec -it mongodb-0 -n zisefeizhu -- mongo
    MongoDB shell version v4.2.1
    connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
    Implicit session: session { "id" : UUID("de51ecc8-ce78-4e4d-8107-662f3adb0e77") }
    MongoDB server version: 4.2.1
    Server has startup warnings: 
    2021-03-29T07:18:24.047+0000 I  CONTROL  [initandlisten] 
    2021-03-29T07:18:24.047+0000 I  CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
    2021-03-29T07:18:24.047+0000 I  CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
    2021-03-29T07:18:24.047+0000 I  CONTROL  [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
    2021-03-29T07:18:24.047+0000 I  CONTROL  [initandlisten] 
    2021-03-29T07:18:24.047+0000 I  CONTROL  [initandlisten] 
    2021-03-29T07:18:24.047+0000 I  CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
    2021-03-29T07:18:24.047+0000 I  CONTROL  [initandlisten] **        We suggest setting it to 'never'
    2021-03-29T07:18:24.047+0000 I  CONTROL  [initandlisten] 
    ---
    Enable MongoDB's free cloud-based monitoring service, which will then receive and display
    metrics about your deployment (disk utilization, CPU, operation statistics, etc).
    
    The monitoring data will be available on a MongoDB website with a unique URL accessible to you
    and anyone you share the URL with. MongoDB may use this information to make product
    improvements and to suggest MongoDB products and deployment options to you.
    
    To enable free monitoring, run the following command: db.enableFreeMonitoring()
    To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
    ---
    > show databases;
    admin   0.000GB
    config  0.000GB
    local   0.000GB
    
    过手如登山,一步一重天
  • 相关阅读:
    马哥学习笔记二十一——LVS DR模型
    马哥学习笔记二十——集群系列之LVS调度方法及NAT模型
    CCNA学习笔记九——访问控制列表(ACL)
    CCNA学习笔记八——动态路由协议
    CCNA学习笔记七——路由概述
    CCNA学习笔记六——网络层协议
    WPF点补间、拟合回归直线
    WPF三种基本触发器与【与或】逻辑触发器
    C#与mysql做ASP.NET网页数据库查询速度测试
    VS2013单元测试及代码覆盖率分析--Xunit
  • 原文地址:https://www.cnblogs.com/zisefeizhu/p/14592741.html
Copyright © 2011-2022 走看看