我正在使用Google Kubernetes Engine并希望我的StatefulSet
使用我之前创建的磁盘my-app-disk
,而不是为集合中的每个副本动态创建新的永久磁盘。我的配置如下:
PersistentVolume
yaml:
apiVersion: v1
kind: PersistentVolume
metadata:
name: my-app-data
labels:
app: my-app
spec:
capacity:
storage: 60Gi
accessModes:
- ReadWriteOnce
gcePersistentDisk:
pdName: my-app-disk
fsType: ext4
PersistentVolumeClaim
yaml:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: my-app-data
labels:
app: my-app
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 60Gi
selector:
matchLabels:
app: my-app
StatefulSet
yaml:
apiVersion: apps/v1beta2
kind: StatefulSet
metadata:
name: my-stateful-set
spec:
serviceName: my-stateful-set
replicas: 1
selector:
matchLabels:
app: my-app
updateStrategy:
type: RollingUpdate
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: my-app
image: gcr.io/projectname/my-app:0.0.3
ports:
- containerPort: 80
name: http
volumeMounts:
- name: my-app-data
mountPath: /data
volumeClaimTemplates:
- metadata:
name: my-app-data
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 50Gi
答案 0 :(得分:5)
StatefulSet
会为每个广告单元创建自己的PersistentVolumeClaim
,因此您不必自己创建一个。 PersistentVolume
和PersistentVolumeClaim
将仅one to one绑定。您的PVC与您的卷绑定,因此StatefulSet
创建的任何PVC都无法绑定到您的卷,因此无法使用它。
在您的情况下,您的PersistentVolume
和StatefulSet
应该可以解决问题。请务必删除您创建的PersistentVolumeClaim
,以便它不会绑定到您的PersistentVolume
。另外,请确保您的PV和下面的volumeClaimTemplates
上的StatefulSet
下的存储类名称设置正确,或者StatefulSet
生成的PVC可能不会绑定到您的卷。
PersistentVolume.yaml
:
apiVersion: v1
kind: PersistentVolume
metadata:
name: my-app-data
labels:
app: my-app
spec:
capacity:
storage: 60Gi
storageClassName: standard
accessModes:
- ReadWriteOnce
gcePersistentDisk:
pdName: my-app-disk
fsType: ext4
StatefulSet.yaml
:
apiVersion: apps/v1beta2
kind: StatefulSet
metadata:
name: my-stateful-set
spec:
serviceName: my-stateful-set
replicas: 1
selector:
matchLabels:
app: my-app
updateStrategy:
type: RollingUpdate
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: my-app
image: gcr.io/projectname/my-app:0.0.3
ports:
- containerPort: 80
name: http
volumeMounts:
- name: my-app-data
mountPath: /data
volumeClaimTemplates:
- metadata:
name: my-app-data
spec:
selector:
matchLabels:
app: my-app
storageClassName: standard
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 50Gi