在Kubernetes中,可以在Statefulset中添加hostPath存储。如果是这样,有人可以帮我举例吗?
最佳答案
是的,但绝对是出于测试目的。
首先,您需要创建尽可能多的持久卷
kind: PersistentVolume
apiVersion: v1
metadata:
name: hp-pv-001
labels:
type: local
spec:
storageClassName: manual
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/tmp/data01"
kind: PersistentVolume
apiVersion: v1
metadata:
name: hp-pv-002
labels:
type: local
spec:
storageClassName: manual
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/tmp/data02"
...
然后,将此VolumeClaimsTemplate添加到您的Statefulset
volumeClaimTemplates:
- metadata:
name: my-hostpath-volume
spec:
storageClassName: manual
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 5Gi
selector:
matchLabels:
type: local
另一种解决方案是使用hostpath dynamic provisioner。您不必创建PV Bin Advance,但这仍然是一个“概念验证解决方案”,并且您将必须在群集中构建和部署预配器。