我正在使用Google容器引擎为MongoDB副本集运行StatefulSet(3个副本容器) .
这适用于动态配置持久存储 - 即在创建有状态集时为每个pod配置新存储 .
但是,如果我重新启动StatefulSet,似乎我无法重新绑定旧的持久卷,因为将再次配置新存储 . 这意味着数据丢失 . 理想情况下,持久存储应该在删除Kubernetes集群本身后继续存在,数据保留并准备好在新集群中重新使用 .
有没有办法创建GCE Persistent磁盘并在StatefulSet的持久卷声明中使用它们?
[2017年9月20日更新]
Found the answer: 这是解决方案(归功于@RahulKrishnan R A)
-
创建存储类,指定基础磁盘类型和区域
-
创建一个PersistentVolume,指定上面创建的存储类,并引用您要挂载的永久磁盘
-
创建PersistentVolumeClaim . 将PVC命名为
<pvc template name>-<statefulset name>-<ordinal number>
非常重要 . (正确的名称是诀窍!)将volumeName指定为上面创建的PV和存储类 . -
创建具有正确名称的副本的PV和PVC .
-
使用PVC模板创建statefulSet .
1 回答
Method 1 : Dynamic
You can add volume claim template as follows in statefulset.yaml file along with the deployment definition
volumeClaimTemplates:
名称:存储
注释:
volume.beta.kubernetes.io/storage-class:slow
规格:
accessModes:["ReadWriteOnce"]
资源:
要求:
存储:10Gi
Create storage class storage.yaml file
kind:StorageClass
apiVersion:storage.k8s.io/v1beta1
元数据:
名字:慢
供应者:kubernetes.io/gce-pd
参数:
类型:pd标准
zone:asia-east1-a
Method 2 Static PV:
https://github.com/rahulkrishnanfs/percona-xtradb-statefulset-cluster-k8s/blob/master/percona.yml
注意: persistentVolumeReclaimPolicy: Retain 如果您想保留音量,请使用
持久卷可以由管理员静态配置,也可以基于StorageClass资源动态配置