gpt4 book ai didi

kubernetes - 如何为 StatefulSet 静态配置卷?

转载 作者:行者123 更新时间:2023-12-04 14:39:06 25 4
gpt4 key购买 nike

我正在使用 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

最佳答案

StatefulSet将创建它自己的PersistentVolumeClaim对于每个 pod,因此您不必自己创建一个。一个 PersistentVolumePersistentVolumeClaim将独占绑定(bind)one to one .您的 PVC 绑定(bind)到您的卷,因此 StatefulSet 创建的任何 PVC无法绑定(bind)到您的卷,因此不会被使用。

在您的情况下,您的 PersistentVolumeStatefulSet下面应该可以解决问题。确保删除 PersistentVolumeClaim您创建它是为了不绑定(bind)到您的 PersistentVolume .另外,请确保在您的 PV 下方和 volumeClaimTemplates 中正确设置了存储类名称。在您的 StatefulSet 上下面或 StatefulSet 制造的 PVC可能无法绑定(bind)到您的卷。
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

关于kubernetes - 如何为 StatefulSet 静态配置卷?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48270971/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com