StateFulSet如何使用存储class?我必须创建 PVC 吗?

How to use a storage class for StateFulSet? Do I have to create a PVC?

如何为 statefulset 使用存储 class?我已经创建了 StorageClass。我还创建了 PVC,但如果需要创建 PVC,我有点困惑,因为 PVC 已经请求存储,而 volumeClaimTemplates 也请求存储。不管怎样,它不能使用或不使用 pvc。

我收到以下错误:

create Pod dbhost001-0 in StatefulSet dbhost001 failed error: failed to create PVC mysql-dev-dbhost001-0: PersistentVolumeClaim "mysql-dev-dbhost001-0" is invalid: spec.resources[storage]: Required value
create Claim mysql-dev-dbhost001-0 for Pod dbhost001-0 in StatefulSet dbhost001 failed error: PersistentVolumeClaim "mysql-dev-dbhost001-0" is invalid: spec.resources[storage]: Required value

storageClass.yml:

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: ebs-sc
provisioner: kubernetes.io/aws-ebs
parameters:
  type: gp2
reclaimPolicy: Retain
allowVolumeExpansion: true
volumeBindingMode: WaitForFirstConsumer

Statefultset.yml:

apiVersion: apps/v1
kind: StatefulSet
....
....
  volumeClaimTemplates:
  - metadata:
      name: mysql-dev
    spec:
      accessModes:
        - ReadWriteOnce
      storageClassName: ebs-sc
      resources:
        requests:
          stroage: 2Gi

我不确定是否需要pvc?我将其用于正常的复制集部署。但是不确定Statefulset是否需要这个。

PersistentVolumeClaim.yml:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysql-dev
  namespace: test-db-dev
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: ebs-sc
  resources:
    requests:
      storage: 2Gi

想通了。

首先 Statefultset.yml 中有一个错字,应该是 storage 而不是 stroage

其次,不需要 PersistentVolumeClaim,因为 volumeClaimTemplates 与存储 class.

中的内容相同