本文介绍了DigitalOcean上的Kubernetes&Quot;共享&持久卷的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个永久卷定义为

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的卷中看不到它。我做错了什么?

推荐答案

有权限的pvc

accessModes:
  - ReadWriteOnce

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

如果要在多个副本之间保留共享卷,则可以将NFS访问模式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

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

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

这篇关于DigitalOcean上的Kubernetes&Quot;共享&持久卷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 08:23