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

时间:2024-01-10 01:01:54 标签:  虚拟化  云计算  linux系统运维  MongoDB  kubernetes  数据库  


#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分片集群

搜集用于学习

来源:https://blоg.сsdn.nеt/qq_34777982/аrtiсlе/dеtаils/127933655

智能推荐

1. 可视化展示K8s的rbac权限 https://github.com/te

标签:虚拟化  云计算  linux系统运维  kubernetes  容器  云原生  

每日一句Medalist dont grow on trees, you have to nurture them with love, with hard work, with dedication.金牌选手不会从天而降,你必须用热爱、刻苦和投入来浇灌他们。概述分片(sharding)是一种垮多台机器分布数据的方法,MongoDB使用分片来支持具有非常大的数据集和高吞吐量操作的部署。分片(sharding)是指将数据拆分,将其分散存在不同的机器上的过程。有时也用分区(partitioning)来表示这个概念。将数据分散到不同的机器上,不需要功能强大的大型计算机就可以

标签:集群  分片  MongoDB  

JAVA技术广泛用于各行各业,而云原生的流行,越来越多的企业将java应

标签:云计算  虚拟化  Java技术  kubernetes  java  容器  

kubernetes部署单节点redis: https://www.cnblogs.com/zisefeizhu/p/14282299.htmlRedis 介绍• Redis代表REmote DIctionary Server是一种开源的内存中数据存储,通常用作数据库,缓存或消息代理。它可以存储和操作高级数据类型,例如列表,地图,集合和排序集合。• 由于Redis接受多种格式的密钥,因此可以在服务器上执行操作,从而减少了客户端的工作量。• 它仅将磁盘用于持久性,而将数据完全保存在内存中。• Red

标签:集群  k8s  redis  cluster  

1、Zookeeper简介zookeeper是一个开源的分布式协调服务,由知名互联网公司Yahoo创建,它是Chubby的开源实现;换句话讲,zookeeper是一个典型的分布式数据一致性解决方案,分布式应用程序可以基于它实现数据的发布/订阅、负载均衡、名称服务、分布式协调/通知、集群管理、Master选举、分布式锁和分布式队列;2、PV/PVC及zookeeper

标签:集群  实战  案例  k8s  zookeeper  

一、前言 本篇,我们将基于k8s集群,模拟一个比较接近实际业务的使用场景,使用k

标签:k8s  linux与容器实战  springboot 入门到精通  k8s集群部署java应用  k8s部署springboot  k8s部署java应用  k8s部署微服务项目  k8s部署微服务  

1、部署k8s的两种方式:

标签:k8s  运维  kubernetes  

之前整理了一下各种资源长时间无法回收,解决处理的命令行 k8s 各种资

标签:云计算  虚拟化  linux系统运维  kubernetes  docker  容器  

FROM 基础镜像 可以选择现有的镜像,比如centos、debi

标签:虚拟化  云计算  linux系统运维  linux  运维  服务器  

猜你喜欢

 1、简介K8s部署主要有两种方式:1、Kubeadm  Kubeadm是一个K8s部署工具,提供kubeadm init和kubeadm join,用于快速部署Kubernetes集群。2、二进制   从github下载发行版的二进制包,手动部署每个组件,组成Kubernetes集群。本文通过kudeadm的方式在centos7上安装kubernetes集群。2、环境准备(1)初始化配置#关

标签:集群  手册  详细  k8s  kubeadm  

官方网站:GoEdge CDN - 制作自己的CDN - GoEdge CDN | 自

标签:缓存技术  linux系统运维  开源  

作者:老Z,云原生爱好者,目前专注于云原生运维,KubeSphere Ambassador。前言知识点定级:入门级RabbitMQ 单节点安装部署RabbitMQ 集群安装部署GitOps 运维思想演示服务器配置

标签:集群  实战  k8s  RabbitMQ  

1.部署ansible集群 使用python脚本一个简单的搭建ansible集群

标签:ansible  ansible  kubernetes  java  容器  docker  k8s  

引文 本篇对mongodb分片集群的机制和原理进行讲解,但是如果不

标签:mongodb系列  MongoDB  数据库  nosql  

  前文我们聊到了mongodb的副本集以及配置副本集,回顾请参考https://www.cnblogs.com/qiuhom-1874/p/13953598.html;今天我们来聊下mongodb的分片;  1、什么是分片?为什么要分片?  我们知道数据库服务器一般出现瓶颈是在磁盘io上,或者高并发网络io,又或者单台server的cpu、内存等等一系列原因;于是,为了解决这些瓶颈问题,我们就必须扩展服务器性能;通常扩展服务器有向上扩展和向外扩展;所谓向上扩展就是给服务器加更大的磁盘,使用更大更好的内存,更换更好的cpu;这种扩展在一定程度上是可以解决性能瓶颈问题,但随着数据量大增大,瓶颈会再次出现;所以通常这种向上扩展的方式不推荐;向外扩展是指一台服

标签:分布式  集群  分片  文档  数据库  

 一、安装HBase集群 1.下载HBase

标签:hbase  数据库  大数据  

部署说明资源说明最低配置Master节点:2C 4G 50GBNode节点:2C 4GB 50GB部署说明为兼容更多场景的部署,所有组件均采用二进制部署或源码部署linux内核版本 ≥ 3.8linux内核必须支持一种适合的存储驱动(storage driver),默认的存储驱动通常是De

标签:离线  集群  k8s  

  前文我们了解了Ceph的基础架构和相关组件的介绍,回顾请参考https://www.cnblogs.com/qiuhom-1874/p/16720234.html;今天我们来部署一个ceph集群;  部署工具介绍  1、ceph-deploy:该部署工具是ceph官方的部署工具,它只依赖SSH访问服务器,不需要额外的agent;它可以完全运行在自己的工作站上(比如admin host),不需要服务器,数据库类似的东西;该工具不是一个通用的部署工具,只针对ceph;相比ansible,puppet,功能相对单一;该工具可以推送配置文件,但它不处理客户端配置,以及客户端部署相关依赖等;  2、ceph-ansible:该工具是用ansib

标签:分布式  集群  存储系统  Ceph  

源码下载地址: https://www.openssl.org/sou

标签:linux系统运维  centos  linux  openssl3  

相关问题

相关文章

热门文章

推荐文章

相关标签