1

我有以下PersistentVolumeClaim

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: nginx-pvc
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 256Mi
  storageClassName: fask

部署

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  replicas: 2
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.7.9
        ports:
        - containerPort: 80
        volumeMounts:
        - name: data
          mountPath: "/var/www/html"
      volumes:
      - name: data
        persistentVolumeClaim:
          claimName: nginx-pvc

如果我使用单个副本部署运行,我的 PV 将由 vSphere StorageClass动态创建

但是,如果我有超过2 个副本,它将无法创建第二个 PV:

AttachVolume.Attach failed for volume "pvc-8facf319-6b1a-11e8-935b-00505680b1b8" : Failed to add disk 'scsi0:1'.
Unable to mount volumes for pod "nginx-deployment-7886f48dcd-lzms8_default(b0e38764-6b1a-11e8-935b-00505680b1b8)": timeout expired waiting for volumes to attach or mount for pod "default"/"nginx-deployment-7886f48dcd-lzms8". list of unmounted volumes=[data]. list of unattached volumes=[data default-token-5q7kr]
4

1 回答 1

6

但是,如果我有超过 2 个副本,它将无法创建第二个 PV

然后,您可能应该在其中使用StatefulSetandvolumeClaimTemplates而不是Deploymentand PersistentVolumeClaim

在您的情况下,每个部署都具有相同的PersistentVolumeClaim(即 ReadWriteOnly 并且不能在第二次请求时安装),而 volumeClaimTemplates您会为每个副本配置不同的部署。

于 2018-06-08T14:44:23.603 回答