簡體   English   中英

MongoDB 上 kubernetes 社區運營商。 唯一節點上的 Statefulset pod

[英]MongoDB on kubernetes Community Operator. Statefulset pods on unique nodes

我正在使用MongoDB Community Operator部署 mongodb 集群。 副本集配置。

我按照這個示例進行配置。 不同之處在於我希望每個節點上都有一個 pod,並且他的 pv 在節點上。 在每次部署相同的節點位置 pod/pv。

我已經部署了一個帶有兩個副本的 mongodb statefulset。 我希望 statefulset pod-0pod-1的 pod 位於特定節點上: node-0node-1

對於兩個 pod,我部署了兩個hostpath類型的持久卷。 每個節點一個: pv-0pv-1

一切似乎都很好,但存在問題:有時pod-0的 PVC(在節點 0 上強制)綁定到 pv-1(節點 1 上的焦點),反之亦然。 所以 pod 無法啟動,因為存在節點沖突

有沒有辦法在pv-0的同一節點上強制pod-0 0 ?

也許使用MongoDBCommunity.spec.statefulSet.VolumeClameTemplates ,但我不知道如何。

我在這里閱讀,但我不知道如何申請 statefulset。

跟隨我的 yamls。 滿載而歸:

apiVersion: mongodbcommunity.mongodb.com/v1
kind: MongoDBCommunity
metadata:
  name: my-mongo
  labels:
    app: my-mongo
  namespace: mongo-system
spec:
  members: 2
  statefulSet:
    spec:
      template:
      volumeClaimTemplates:
      - metadata:
          name: data-volume
        spec:
          storageClassName: hostpath
          accessModes: [ "ReadWriteOnce" ]
          resources:
            requests:
              storage: 11Gi
          selector:
            matchLabels:
              type: data

光伏

apiVersion: v1
kind: PersistentVolume
metadata:
  name: data-volume-db-0
  labels:
    type: data
spec:
  storageClassName: hostpath
  persistentVolumeReclaimPolicy: Retain
  capacity:
    storage: 11Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: /data/volumes/db-data
    type: ""
  nodeAffinity:
    required:
      # This is just an example for matchexpression
      # This field is required depends on the specific
      # of the environment the resource is deployed in
      nodeSelectorTerms:
      - matchExpressions:
        - key: kubernetes.io/hostname
          operator: In
          values:
          - node-0

---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: data-volume-db-1
  labels:
    type: data
spec:
  storageClassName: hostpath
  persistentVolumeReclaimPolicy: Retain
  capacity:
    storage: 11Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: /data/volumes/db-data
    type: ""
  nodeAffinity:
    required:
      # This is just an example for matchexpression
      # This field is required depends on the specific
      # of the environment the resource is deployed in
      nodeSelectorTerms:
      - matchExpressions:
        - key: kubernetes.io/hostname
          operator: In
          values:
          - node-1

我在 PV yaml 上使用claimRef解決了

apiVersion: v1
kind: PersistentVolume
metadata:
  name: data-volume-db-1
  labels:
    type: data
spec:
  storageClassName: hostpath
  persistentVolumeReclaimPolicy: Retain
  capacity:
    storage: 11Gi
  claimRef:
    namespace: system-mongo
    name: data-volume-db-0
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: /data/volumes/db-data
    type: ""
  nodeAffinity:
    required:
      # This is just an example for matchexpression
      # This field is required depends on the specific
      # of the environment the resource is deployed in
      nodeSelectorTerms:
      - matchExpressions:
        - key: kubernetes.io/hostname
          operator: In
          values:
          - node-1

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM