【问题标题】:Kubernetes "shared" persistent volume on DigitalOceanKubernetes 在 DigitalOcean 上“共享”持久卷
【发布时间】:2021-10-04 03:35:43
【问题描述】:

我有一个持久卷定义为

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: ghost-cms-content
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 5Gi
  storageClassName: do-block-storage

一个部署定义为

---
kind: Deployment
apiVersion: apps/v1
metadata:
  name: ghost-cms
spec:
  replicas: 4
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
  selector:
    matchLabels:
      app: ghost-cms
      tier: frontend
  template:
    metadata:
      labels:
        app: ghost-cms
        tier: frontend
    spec:
      topologySpreadConstraints:
        - maxSkew: 1
          topologyKey: topology.kubernetes.io/region
          whenUnsatisfiable: ScheduleAnyway
          labelSelector:
            matchLabels:
              app: ghost-cms
              tier: frontend
      containers:
        - name: ghost-cms
          image: ghost:4.6-alpine
          imagePullPolicy: Always
          ports:
            - containerPort: 2368
          volumeMounts:
            - mountPath: /var/lib/ghost/content
              name: content
          env:
            - name: url
              value: https://ghost.site
          resources:
            requests:
              cpu: 100m
              memory: 128Mi
            limits:
              cpu: 250m
              memory: 256Mi
      volumes:
        - name: content
          persistentVolumeClaim:
            claimName: ghost-cms-content

但每个副本似乎都有一个不与其余副本共享的唯一卷。例如,当我在其中一个 pod 中的 /var/lib/ghost/content 内创建一个文本文件时,我在其他 pod 的卷中看不到它。我做错了什么?

【问题讨论】:

    标签: kubernetes digital-ocean kubernetes-pod


    【解决方案1】:

    有权限的PVC

    accessModes:
      - ReadWriteOnce
    

    每个 pod 将获得一个卷或 PVC,因为它是一次读写。

    如果你想跨副本保持共享卷,你可以使用 NFSaccessMode ReadWriteMany

     accessModes:
          - ReadWriteMany
    

    阅读更多:https://kubernetes.io/docs/concepts/storage/persistent-volumes/#access-modes

    例如:https://medium.com/asl19-developers/create-readwritemany-persistentvolumeclaims-on-your-kubernetes-cluster-3a8db51f98e3

    您还可以使用 MinioGlusterFS 来创建 NFS 或任何托管服务(如 GCP 文件存储)提供NFS 并将其附加到 POD。

    GKE 示例:https://medium.com/@Sushil_Kumar/readwritemany-persistent-volumes-in-google-kubernetes-engine-a0b93e203180

    【讨论】:

    • 我可以在/var/lib/ghost/content 中看到文件同步,但我还没有测试过在不同节点上运行的 pod。你是说如果我不使用 NFS 或 GlusterFS,我不会看到跨节点同步的 PVC?
    • 会有一个 PVC,无论节点如何,您的所有 pod 都将附加到它。
    猜你喜欢
    • 2019-09-12
    • 2019-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-23
    • 2020-08-18
    • 1970-01-01
    • 2018-12-09
    相关资源
    最近更新 更多