K8S 部署mongoDB 6.0 分片集群 —— 筑梦之路

119 篇文章 7 订阅
109 篇文章 3 订阅

#vim mongodb-sharded-cluster-Secret.yaml
apiVersion: v1
kind: Secret
metadata:
  name: mongodb-sharded-cluster
  namespace: "default"
  labels:
    app.kubernetes.io/name: mongodb-sharded
    helm.sh/chart: mongodb-sharded-6.0.3
    app.kubernetes.io/instance: mongodb-sharded-cluster
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: mongodb
type: Opaque
data:
  # root密码S95W8OF7rf
  mongodb-root-password: "Uzk1VzhPRjdyZg=="
  mongodb-replica-set-key: "MkRkQlFRenI4TA=="

---
#vim mongodb-sharded-cluster-ConfigMap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: mongodb-sharded-cluster-replicaset-entrypoint
  namespace: "default"
  labels:
    app.kubernetes.io/name: mongodb-sharded
    helm.sh/chart: mongodb-sharded-6.0.3
    app.kubernetes.io/instance: mongodb-sharded-cluster
    app.kubernetes.io/managed-by: Helm
data:
  replicaset-entrypoint.sh: |-
    #!/bin/bash

    sleep 5

    . /liblog.sh

    # Perform adaptations depending on the host name
    if [[ $HOSTNAME =~ (.*)-0$ ]]; then
      info "Setting node as primary"
      export MONGODB_REPLICA_SET_MODE=primary
    else
      info "Setting node as secondary"
      export MONGODB_REPLICA_SET_MODE=secondary
      export MONGODB_INITIAL_PRIMARY_ROOT_PASSWORD="$MONGODB_ROOT_PASSWORD"
      unset MONGODB_ROOT_PASSWORD
    fi

    exec /entrypoint.sh /run.sh

---
# vim mongodb-sharded-cluster-headless.yaml
apiVersion: v1
kind: Service
metadata:
  name: mongodb-sharded-cluster-headless
  namespace: "default"
  labels:
    app.kubernetes.io/name: mongodb-sharded
    helm.sh/chart: mongodb-sharded-6.0.3
    app.kubernetes.io/instance: mongodb-sharded-cluster
    app.kubernetes.io/managed-by: Helm
  annotations:
    {}
spec:
  type: ClusterIP
  clusterIP: None
  ports:
    - name: mongodb
      port: 27017
  selector: 
    app.kubernetes.io/name: mongodb-sharded
    app.kubernetes.io/instance: mongodb-sharded-cluster

---
# vim mongodb-sharded-cluster-svc.yaml
apiVersion: v1
kind: Service
metadata:
  name: mongodb-sharded-cluster
  namespace: "default"
  labels: 
    app.kubernetes.io/name: mongodb-sharded
    helm.sh/chart: mongodb-sharded-6.0.3
    app.kubernetes.io/instance: mongodb-sharded-cluster
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: mongos
  annotations:
    {}
spec:
  type: ClusterIP
  ports:
    - name: mongodb
      port: 27017
      targetPort: mongodb
      nodePort: null
  selector: 
    app.kubernetes.io/name: mongodb-sharded
    app.kubernetes.io/instance: mongodb-sharded-cluster
    app.kubernetes.io/component: mongos
  sessionAffinity: None

---
# vim mongos-deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mongodb-sharded-cluster-mongos
  namespace: "default"
  labels:
    app.kubernetes.io/name: mongodb-sharded
    helm.sh/chart: mongodb-sharded-6.0.3
    app.kubernetes.io/instance: mongodb-sharded-cluster
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: mongos
spec:
  strategy:
    type: RollingUpdate
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: mongodb-sharded
      app.kubernetes.io/instance: mongodb-sharded-cluster
      app.kubernetes.io/component: mongos
  template:
    metadata:
      labels:
        app.kubernetes.io/name: mongodb-sharded
        helm.sh/chart: mongodb-sharded-6.0.3
        app.kubernetes.io/instance: mongodb-sharded-cluster
        app.kubernetes.io/managed-by: Helm
        app.kubernetes.io/component: mongos
    spec:
      serviceAccountName: "default"
      affinity:
        podAffinity:
          
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
            - podAffinityTerm:
                labelSelector:
                  matchLabels:
                    app.kubernetes.io/name: mongodb-sharded
                    app.kubernetes.io/instance: mongodb-sharded-cluster
                    app.kubernetes.io/component: mongos
                namespaces:
                  - "default"
                topologyKey: kubernetes.io/hostname
              weight: 1
        nodeAffinity:
          
      securityContext:
        fsGroup: 1001
      
      containers:
        - name: mongos
          image: hub.kce.ksyun.com/leoxinyuan/mongodb-sharded:6.0.1-debian-11-r0
          imagePullPolicy: "IfNotPresent"
          securityContext:
            readOnlyRootFilesystem: false
            runAsNonRoot: true
            runAsUser: 1001
          env:
            - name: MONGODB_ENABLE_NUMACTL
              value: "no"
            - name: BITNAMI_DEBUG
              value: "false"
            - name: MONGODB_SHARDING_MODE
              value: "mongos"
            - name: MONGODB_MAX_TIMEOUT
              value: "120"
            - name: MONGODB_ROOT_USER
              value: "root"
            - name: MONGODB_ROOT_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: mongodb-sharded-cluster
                  key: mongodb-root-password
            - name: MONGODB_REPLICA_SET_KEY
              valueFrom:
                secretKeyRef:
                  name: mongodb-sharded-cluster
                  key: mongodb-replica-set-key
            - name: MONGODB_POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: MONGODB_ADVERTISED_HOSTNAME
              value: "$(MONGODB_POD_NAME)"
            - name: MONGODB_PORT_NUMBER
              value: "27017"
            - name: MONGODB_CFG_PRIMARY_HOST
              value: mongodb-sharded-cluster-configsvr-0.mongodb-sharded-cluster-headless.default.svc.cluster.local
            - name: MONGODB_CFG_REPLICA_SET_NAME
              value: mongodb-sharded-cluster-configsvr
            - name: MONGODB_SYSTEM_LOG_VERBOSITY
              value: "0"
            - name: MONGODB_DISABLE_SYSTEM_LOG
              value: "no"
            - name: MONGODB_ENABLE_IPV6
              value: "no"
            - name: MONGODB_ENABLE_DIRECTORY_PER_DB
              value: "no"
          ports:
            - name: mongodb
              containerPort: 27017
          livenessProbe:
            failureThreshold: 2
            initialDelaySeconds: 60
            periodSeconds: 30
            successThreshold: 1
            timeoutSeconds: 20
            exec:
              command:
                - /bin/sh 
                - -c 
                - mongosh --port $MONGODB_PORT_NUMBER --eval "db.adminCommand('ping')"
          readinessProbe:
            failureThreshold: 6
            initialDelaySeconds: 10
            periodSeconds: 30
            successThreshold: 1
            timeoutSeconds: 20
            exec:
              command:
                - /bin/sh 
                - -c 
                - mongosh --port $MONGODB_PORT_NUMBER --eval "db.adminCommand('ping')"

---

# vim config-server-statefulset.yaml
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: mongodb-sharded-cluster-configsvr
  namespace: "default"
  labels:
    app.kubernetes.io/name: mongodb-sharded
    helm.sh/chart: mongodb-sharded-6.0.3
    app.kubernetes.io/instance: mongodb-sharded-cluster
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: configsvr
spec:
  selector:
    matchLabels:
      app.kubernetes.io/name: mongodb-sharded
      app.kubernetes.io/instance: mongodb-sharded-cluster
      app.kubernetes.io/component: configsvr
  serviceName: mongodb-sharded-cluster-headless
  replicas: 3
  podManagementPolicy: OrderedReady
  updateStrategy:
    type: RollingUpdate
  template:
    metadata:
      labels:
        app.kubernetes.io/name: mongodb-sharded
        helm.sh/chart: mongodb-sharded-6.0.3
        app.kubernetes.io/instance: mongodb-sharded-cluster
        app.kubernetes.io/managed-by: Helm
        app.kubernetes.io/component: configsvr
    spec:
      serviceAccountName: "default"
      affinity:
        podAffinity:
          
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
            - podAffinityTerm:
                labelSelector:
                  matchLabels:
                    app.kubernetes.io/name: mongodb-sharded
                    app.kubernetes.io/instance: mongodb-sharded-cluster
                    app.kubernetes.io/component: configsvr
                namespaces:
                  - "default"
                topologyKey: kubernetes.io/hostname
              weight: 1
        nodeAffinity:
          
      securityContext:
        fsGroup: 1001
      
      initContainers:
      containers:
        - name: mongodb
          image: hub.kce.ksyun.com/leoxinyuan/mongodb-sharded:6.0.1-debian-11-r0
          imagePullPolicy: IfNotPresent
          securityContext:
            readOnlyRootFilesystem: false
            runAsNonRoot: true
            runAsUser: 1001
          ports:
            - containerPort: 27017
              name: mongodb
          env:
            - name: MONGODB_ENABLE_NUMACTL
              value: "no"
            - name: BITNAMI_DEBUG
              value: "false"
            - name: MONGODB_SYSTEM_LOG_VERBOSITY
              value: "0"
            - name: MONGODB_DISABLE_SYSTEM_LOG
              value: "no"
            - name: MONGODB_MAX_TIMEOUT
              value: "120"
            - name: MONGODB_SHARDING_MODE
              value: "configsvr"
            - name: MONGODB_POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: MONGODB_PORT_NUMBER
              value: "27017"
            - name: MONGODB_INITIAL_PRIMARY_HOST
              value: mongodb-sharded-cluster-configsvr-0.mongodb-sharded-cluster-headless.default.svc.cluster.local
            - name: MONGODB_REPLICA_SET_NAME
              value: mongodb-sharded-cluster-configsvr
            - name: MONGODB_ADVERTISED_HOSTNAME
              value: $(MONGODB_POD_NAME).mongodb-sharded-cluster-headless.default.svc.cluster.local
            - name: MONGODB_ROOT_USER
              value: "root"
            - name: MONGODB_ROOT_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: mongodb-sharded-cluster
                  key: mongodb-root-password
            - name: MONGODB_REPLICA_SET_KEY
              valueFrom:
                secretKeyRef:
                  name: mongodb-sharded-cluster
                  key: mongodb-replica-set-key
            - name: MONGODB_ENABLE_IPV6
              value: "no"
            - name: MONGODB_ENABLE_DIRECTORY_PER_DB
              value: "no"
          command:
            - /bin/bash
            - /entrypoint/replicaset-entrypoint.sh
          livenessProbe:
            failureThreshold: 2
            initialDelaySeconds: 60
            periodSeconds: 30
            successThreshold: 1
            timeoutSeconds: 20
            exec:
              command:
                - pgrep
                - mongod
          readinessProbe:
            failureThreshold: 6
            initialDelaySeconds: 10
            periodSeconds: 30
            successThreshold: 1
            timeoutSeconds: 20
            exec:
              command:
                - /bin/sh 
                - -c 
                - mongosh --port $MONGODB_PORT_NUMBER --eval "db.adminCommand('ping')"
          startupProbe:
            failureThreshold: 30
            initialDelaySeconds: 0
            periodSeconds: 10
            successThreshold: 1
            timeoutSeconds: 5
            tcpSocket:
              port: mongodb
          volumeMounts:
            - name: replicaset-entrypoint-configmap
              mountPath: /entrypoint
            - name: datadir
              mountPath: /bitnami/mongodb
          resources:
            {}
      volumes:
        - name: replicaset-entrypoint-configmap
          configMap:
            name: mongodb-sharded-cluster-replicaset-entrypoint
  volumeClaimTemplates:
    - metadata:
        name: datadir
      spec:
        accessModes:
          - "ReadWriteOnce"
        resources:
          requests:
            storage: "8Gi"
        storageClassName: gluster-storageclass

---


# vim shard-data-statefulset.yaml
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: mongodb-sharded-cluster-shard0-data
  namespace: "default"
  labels:
    app.kubernetes.io/name: mongodb-sharded
    helm.sh/chart: mongodb-sharded-6.0.3
    app.kubernetes.io/instance: mongodb-sharded-cluster
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: shardsvr
spec:
  selector:
    matchLabels:
      app.kubernetes.io/name: mongodb-sharded
      app.kubernetes.io/instance: mongodb-sharded-cluster
      app.kubernetes.io/component: shardsvr
  podManagementPolicy: OrderedReady
  updateStrategy:
    type: RollingUpdate
  serviceName: mongodb-sharded-cluster-headless
  replicas: 2
  template:
    metadata:
      labels:
        app.kubernetes.io/name: mongodb-sharded
        helm.sh/chart: mongodb-sharded-6.0.3
        app.kubernetes.io/instance: mongodb-sharded-cluster
        app.kubernetes.io/managed-by: Helm
        app.kubernetes.io/component: shardsvr
        shard: "0"
    spec:
      affinity:
        podAffinity:
          
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
            - podAffinityTerm:
                labelSelector:
                  matchLabels:
                    app.kubernetes.io/name: mongodb-sharded
                    app.kubernetes.io/instance: mongodb-sharded-cluster
                    app.kubernetes.io/component: shardsvr
                namespaces:
                  - "default"
                topologyKey: kubernetes.io/hostname
              weight: 1
        nodeAffinity:
          
      serviceAccountName: "default"
      securityContext:
        fsGroup: 1001
      
      initContainers:
      containers:
        - name: mongodb
          image: hub.kce.ksyun.com/leoxinyuan/mongodb-sharded:6.0.1-debian-11-r0
          imagePullPolicy: IfNotPresent
          securityContext:
            readOnlyRootFilesystem: false
            runAsNonRoot: true
            runAsUser: 1001
          ports:
            - containerPort: 27017
              name: mongodb
          env:
            - name: MONGODB_ENABLE_NUMACTL
              value: "no"
            - name: BITNAMI_DEBUG
              value: "false"
            - name: MONGODB_SYSTEM_LOG_VERBOSITY
              value: "0"
            - name: MONGODB_MAX_TIMEOUT
              value: "120"
            - name: MONGODB_DISABLE_SYSTEM_LOG
              value: "no"
            - name: MONGODB_PORT_NUMBER
              value: "27017"
            - name: MONGODB_SHARDING_MODE
              value: "shardsvr"
            - name: MONGODB_POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: MONGODB_MONGOS_HOST
              value: mongodb-sharded-cluster
            - name: MONGODB_MONGOS_PORT_NUMBER
              value: "27017"
            - name: MONGODB_INITIAL_PRIMARY_HOST
              value: mongodb-sharded-cluster-shard0-data-0.mongodb-sharded-cluster-headless.default.svc.cluster.local
            - name: MONGODB_REPLICA_SET_NAME
              value: mongodb-sharded-cluster-shard-0
            - name: MONGODB_ADVERTISED_HOSTNAME
              value: $(MONGODB_POD_NAME).mongodb-sharded-cluster-headless.default.svc.cluster.local
            - name: MONGODB_ROOT_USER
              value: "root"
            - name: MONGODB_ROOT_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: mongodb-sharded-cluster
                  key: mongodb-root-password
            - name: MONGODB_REPLICA_SET_KEY
              valueFrom:
                secretKeyRef:
                  name: mongodb-sharded-cluster
                  key: mongodb-replica-set-key
            - name: MONGODB_ENABLE_IPV6
              value: "no"
            - name: MONGODB_ENABLE_DIRECTORY_PER_DB
              value: "no"
          command:
            - /bin/bash
            - /entrypoint/replicaset-entrypoint.sh
          livenessProbe:
            failureThreshold: 2
            initialDelaySeconds: 60
            periodSeconds: 30
            successThreshold: 1
            timeoutSeconds: 20
            exec:
              command:
                - pgrep
                - mongod
          readinessProbe:
            failureThreshold: 6
            initialDelaySeconds: 10
            periodSeconds: 30
            successThreshold: 1
            timeoutSeconds: 20
            exec:
              command:
                - /bin/sh 
                - -c 
                - mongosh --port $MONGODB_PORT_NUMBER --eval "db.adminCommand('ping')"
          volumeMounts:
            - name: replicaset-entrypoint-configmap
              mountPath: /entrypoint
            - name: datadir
              mountPath: /bitnami/mongodb
          resources:
            {}
      volumes:
        - name: replicaset-entrypoint-configmap
          configMap:
            name: mongodb-sharded-cluster-replicaset-entrypoint
  volumeClaimTemplates:
    - metadata:
        name: datadir
      spec:
        accessModes:
          - "ReadWriteOnce"
        resources:
          requests:
            storage: "8Gi"
        storageClassName: gluster-storageclass
---
# 
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: mongodb-sharded-cluster-shard1-data
  namespace: "default"
  labels:
    app.kubernetes.io/name: mongodb-sharded
    helm.sh/chart: mongodb-sharded-6.0.3
    app.kubernetes.io/instance: mongodb-sharded-cluster
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: shardsvr
spec:
  selector:
    matchLabels:
      app.kubernetes.io/name: mongodb-sharded
      app.kubernetes.io/instance: mongodb-sharded-cluster
      app.kubernetes.io/component: shardsvr
  podManagementPolicy: OrderedReady
  updateStrategy:
    type: RollingUpdate
  serviceName: mongodb-sharded-cluster-headless
  replicas: 2
  template:
    metadata:
      labels:
        app.kubernetes.io/name: mongodb-sharded
        helm.sh/chart: mongodb-sharded-6.0.3
        app.kubernetes.io/instance: mongodb-sharded-cluster
        app.kubernetes.io/managed-by: Helm
        app.kubernetes.io/component: shardsvr
        shard: "1"
    spec:
      affinity:
        podAffinity:
          
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
            - podAffinityTerm:
                labelSelector:
                  matchLabels:
                    app.kubernetes.io/name: mongodb-sharded
                    app.kubernetes.io/instance: mongodb-sharded-cluster
                    app.kubernetes.io/component: shardsvr
                namespaces:
                  - "default"
                topologyKey: kubernetes.io/hostname
              weight: 1
        nodeAffinity:
          
      serviceAccountName: "default"
      securityContext:
        fsGroup: 1001
      
      initContainers:
      containers:
        - name: mongodb
          image: hub.kce.ksyun.com/leoxinyuan/mongodb-sharded:6.0.1-debian-11-r0
          imagePullPolicy: IfNotPresent
          securityContext:
            readOnlyRootFilesystem: false
            runAsNonRoot: true
            runAsUser: 1001
          ports:
            - containerPort: 27017
              name: mongodb
          env:
            - name: MONGODB_ENABLE_NUMACTL
              value: "no"
            - name: BITNAMI_DEBUG
              value: "false"
            - name: MONGODB_SYSTEM_LOG_VERBOSITY
              value: "0"
            - name: MONGODB_MAX_TIMEOUT
              value: "120"
            - name: MONGODB_DISABLE_SYSTEM_LOG
              value: "no"
            - name: MONGODB_PORT_NUMBER
              value: "27017"
            - name: MONGODB_SHARDING_MODE
              value: "shardsvr"
            - name: MONGODB_POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: MONGODB_MONGOS_HOST
              value: mongodb-sharded-cluster
            - name: MONGODB_MONGOS_PORT_NUMBER
              value: "27017"
            - name: MONGODB_INITIAL_PRIMARY_HOST
              value: mongodb-sharded-cluster-shard1-data-0.mongodb-sharded-cluster-headless.default.svc.cluster.local
            - name: MONGODB_REPLICA_SET_NAME
              value: mongodb-sharded-cluster-shard-1
            - name: MONGODB_ADVERTISED_HOSTNAME
              value: $(MONGODB_POD_NAME).mongodb-sharded-cluster-headless.default.svc.cluster.local
            - name: MONGODB_ROOT_USER
              value: "root"
            - name: MONGODB_ROOT_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: mongodb-sharded-cluster
                  key: mongodb-root-password
            - name: MONGODB_REPLICA_SET_KEY
              valueFrom:
                secretKeyRef:
                  name: mongodb-sharded-cluster
                  key: mongodb-replica-set-key
            - name: MONGODB_ENABLE_IPV6
              value: "no"
            - name: MONGODB_ENABLE_DIRECTORY_PER_DB
              value: "no"
          command:
            - /bin/bash
            - /entrypoint/replicaset-entrypoint.sh
          livenessProbe:
            failureThreshold: 2
            initialDelaySeconds: 60
            periodSeconds: 30
            successThreshold: 1
            timeoutSeconds: 20
            exec:
              command:
                - pgrep
                - mongod
          readinessProbe:
            failureThreshold: 6
            initialDelaySeconds: 10
            periodSeconds: 30
            successThreshold: 1
            timeoutSeconds: 20
            exec:
              command:
                - /bin/sh 
                - -c 
                - mongosh --port $MONGODB_PORT_NUMBER --eval "db.adminCommand('ping')"
          volumeMounts:
            - name: replicaset-entrypoint-configmap
              mountPath: /entrypoint
            - name: datadir
              mountPath: /bitnami/mongodb
          resources:
            {}
      volumes:
        - name: replicaset-entrypoint-configmap
          configMap:
            name: mongodb-sharded-cluster-replicaset-entrypoint
  volumeClaimTemplates:
    - metadata:
        name: datadir
      spec:
        accessModes:
          - "ReadWriteOnce"
        resources:
          requests:
            storage: "8Gi"
        storageClassName: gluster-storageclass
---

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: mongodb-sharded-cluster-shard2-data
  namespace: "default"
  labels:
    app.kubernetes.io/name: mongodb-sharded
    helm.sh/chart: mongodb-sharded-6.0.3
    app.kubernetes.io/instance: mongodb-sharded-cluster
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: shardsvr
spec:
  selector:
    matchLabels:
      app.kubernetes.io/name: mongodb-sharded
      app.kubernetes.io/instance: mongodb-sharded-cluster
      app.kubernetes.io/component: shardsvr
  podManagementPolicy: OrderedReady
  updateStrategy:
    type: RollingUpdate
  serviceName: mongodb-sharded-cluster-headless
  replicas: 2
  template:
    metadata:
      labels:
        app.kubernetes.io/name: mongodb-sharded
        helm.sh/chart: mongodb-sharded-6.0.3
        app.kubernetes.io/instance: mongodb-sharded-cluster
        app.kubernetes.io/managed-by: Helm
        app.kubernetes.io/component: shardsvr
        shard: "2"
    spec:
      affinity:
        podAffinity:
          
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
            - podAffinityTerm:
                labelSelector:
                  matchLabels:
                    app.kubernetes.io/name: mongodb-sharded
                    app.kubernetes.io/instance: mongodb-sharded-cluster
                    app.kubernetes.io/component: shardsvr
                namespaces:
                  - "default"
                topologyKey: kubernetes.io/hostname
              weight: 1
        nodeAffinity:
          
      serviceAccountName: "default"
      securityContext:
        fsGroup: 1001
      
      initContainers:
      containers:
        - name: mongodb
          image: hub.kce.ksyun.com/leoxinyuan/mongodb-sharded:6.0.1-debian-11-r0
          imagePullPolicy: IfNotPresent
          securityContext:
            readOnlyRootFilesystem: false
            runAsNonRoot: true
            runAsUser: 1001
          ports:
            - containerPort: 27017
              name: mongodb
          env:
            - name: MONGODB_ENABLE_NUMACTL
              value: "no"
            - name: BITNAMI_DEBUG
              value: "false"
            - name: MONGODB_SYSTEM_LOG_VERBOSITY
              value: "0"
            - name: MONGODB_MAX_TIMEOUT
              value: "120"
            - name: MONGODB_DISABLE_SYSTEM_LOG
              value: "no"
            - name: MONGODB_PORT_NUMBER
              value: "27017"
            - name: MONGODB_SHARDING_MODE
              value: "shardsvr"
            - name: MONGODB_POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: MONGODB_MONGOS_HOST
              value: mongodb-sharded-cluster
            - name: MONGODB_MONGOS_PORT_NUMBER
              value: "27017"
            - name: MONGODB_INITIAL_PRIMARY_HOST
              value: mongodb-sharded-cluster-shard2-data-0.mongodb-sharded-cluster-headless.default.svc.cluster.local
            - name: MONGODB_REPLICA_SET_NAME
              value: mongodb-sharded-cluster-shard-2
            - name: MONGODB_ADVERTISED_HOSTNAME
              value: $(MONGODB_POD_NAME).mongodb-sharded-cluster-headless.default.svc.cluster.local
            - name: MONGODB_ROOT_USER
              value: "root"
            - name: MONGODB_ROOT_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: mongodb-sharded-cluster
                  key: mongodb-root-password
            - name: MONGODB_REPLICA_SET_KEY
              valueFrom:
                secretKeyRef:
                  name: mongodb-sharded-cluster
                  key: mongodb-replica-set-key
            - name: MONGODB_ENABLE_IPV6
              value: "no"
            - name: MONGODB_ENABLE_DIRECTORY_PER_DB
              value: "no"
          command:
            - /bin/bash
            - /entrypoint/replicaset-entrypoint.sh
          livenessProbe:
            failureThreshold: 2
            initialDelaySeconds: 60
            periodSeconds: 30
            successThreshold: 1
            timeoutSeconds: 20
            exec:
              command:
                - pgrep
                - mongod
          readinessProbe:
            failureThreshold: 6
            initialDelaySeconds: 10
            periodSeconds: 30
            successThreshold: 1
            timeoutSeconds: 20
            exec:
              command:
                - /bin/sh 
                - -c 
                - mongosh --port $MONGODB_PORT_NUMBER --eval "db.adminCommand('ping')"
          volumeMounts:
            - name: replicaset-entrypoint-configmap
              mountPath: /entrypoint
            - name: datadir
              mountPath: /bitnami/mongodb
          resources:
            {}
      volumes:
        - name: replicaset-entrypoint-configmap
          configMap:
            name: mongodb-sharded-cluster-replicaset-entrypoint
  volumeClaimTemplates:
    - metadata:
        name: datadir
      spec:
        accessModes:
          - "ReadWriteOnce"
        resources:
          requests:
            storage: "8Gi"
        storageClassName: gluster-storageclass

---

原文链接:K8s-K8S部署MongoDB6.0分片集群

搜集用于学习

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值