Kubernetes:NFS与StatefulSets [英] Kubernetes: NFS with StatefulSets
问题描述
我正在尝试将现有的NFS与StateFulSets一起使用.
I'm trying to use existing NFS with StateFulSets.
使用 volumeClaimTemplates
创建 PresistentVolumeClaim
似乎是自动的.
Creation of PresistentVolumeClaim
seems automatic using the volumeClaimTemplates
.
问题:
但是,由于 PresistentVolumeClaim
声明了整个 PresistentVolume
.我必须为所有副本手动创建 PresistentVolume
.有没有办法在Kubernetes中动态设置NFS持久卷?
But, since the PresistentVolumeClaim
claims a entire PresistentVolume
. I have to create PresistentVolume
manually for all the replicas.
Is there a way to dynamically provision NFS persistent volumes in Kubernetes ?
注意:NFS Server本身是静态的,只需要在K8s中动态创建卷即可,而不是NFS Server本身.
Note: NFS Server itself is static, just need to create volumes in K8s dynamically, not the NFS Server itslef.
我正在使用mongo statefulset示例:
I'm using mongo statefulset example:
---
apiVersion: v1
kind: Service
metadata:
name: mongo
labels:
name: mongo
spec:
ports:
- port: 27017
targetPort: 27017
clusterIP: None
selector:
role: mongo
---
apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
name: mongo
spec:
serviceName: "mongo"
replicas: 3
template:
metadata:
labels:
role: mongo
spec:
terminationGracePeriodSeconds: 10
containers:
- name: mongo
image: mongo
command:
- mongod
- "--replSet"
- rs0
- "--smallfiles"
- "--noprealloc"
ports:
- containerPort: 27017
volumeMounts:
- name: mongo-data
mountPath: /data/db
- name: mongo-sidecar
image: cvallance/mongo-k8s-sidecar
env:
- name: MONGO_SIDECAR_POD_LABELS
value: "role=mongo"
volumeClaimTemplates:
- metadata:
name: data
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 5Gi
selector:
matchLabels:
type: nfs
它需要3个 PresistentVolumeClaim
,所以我必须创建3个 PV
才能使用.是否可以像其他动态预配器(如aws-ebs)一样将其动态添加到NFS中?
It needs 3 PresistentVolumeClaim
, so I have to create 3 PV
for it to use. Can this be dynamically added in the NFS like other dynamic provisioners like aws-ebs
这是获取带有NFS持久卷的StatefulSet的正确方法.
Is this the proper way to get a StatefulSet with NFS Persistent Volume.
推荐答案
这是一项正在进行中的工作,我昨天才回来(我的解决方案),但我的建议是否适合您的目的(或以后找到它的任何人)是为了查看GlusterFS和Heketi.
This is a work in progress I came back to just yesterday (my solution) but my advice if it suits your purposes (or anyone finding this later) is to check out GlusterFS and Heketi.
信息包括在下面,但TLDR是GlusterFS是您的NFS,Heketi可以自动设置其余信息.我的github存储库可自动执行设置...丑陋的...但它对我有用,我现在所知道的将使丑陋程度降低.
Information is included below but the TLDR is that GlusterFS is your NFS, Heketi can autoprovision the rest. My github repo automates the setup... it's ugly... but it works for me and I'll be making it less ugly with what I know now.
GlusterFS是一个免费的开源可扩展网络文件系统. https://github.com/gluster/glusterfs https://www.gluster.org/
用于GlusterFS的基于RESTful的卷管理框架 https://github.com/heketi/heketi
RESTful based volume management framework for GlusterFS https://github.com/heketi/heketi
https://github.com/stevenaldinger/gke-glusterfs-heketi
这篇关于Kubernetes:NFS与StatefulSets的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!