[英]Kubernetes : Dynamic Persistent Volume provisioning using NFS
I have multi node kubernetes setup.我有多节点 kubernetes 设置。 I am trying to allocate a Persistent volume dynamically using storage classes with NFS volume plugin.
我正在尝试使用带有 NFS 卷插件的存储类动态分配持久卷。 I found storage classes examples for glusterfs, aws-ebs, etc.but, I didn't find any example for NFS.
我找到了 glusterfs、aws-ebs 等的存储类示例,但是我没有找到 NFS 的任何示例。 If I create PV and PVC only then NFS works very well(Without storage class).
如果我只创建 PV 和 PVC,那么 NFS 工作得很好(没有存储类)。 I tried to write storage class file for NFS, by referring other plugins.
我尝试通过引用其他插件为 NFS 编写存储类文件。 please refer it below,
请参考以下,
nfs-storage-class.yaml nfs-storage-class.yaml
kind: StorageClass
apiVersion: storage.k8s.io/v1beta1
metadata:
namespace: kube-system
name: my-storage
annotations:
storageclass.beta.kubernetes.io/is-default-class: "true"
labels:
kubernetes.io/cluster-service: "true"
provisioner: kubernetes.io/nfs
parameters:
path: /nfsfileshare
server: <nfs-server-ip>
nfs-pv-claim.yaml nfs-pv-claim.yaml
apiVersion: v1
metadata:
name: demo-claim
annotations:
volume.beta.kubernetes.io/storage-class: my-storage
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 3Gi
It didn't worked.它没有用。 So, my question is, Can we write a storage class for NFS?
所以,我的问题是,我们可以为 NFS 编写一个存储类吗? Does it support dynamic provisioing?
它是否支持动态配置?
As of August 2020, here's how things look for NFS persistence on Kubernetes:截至 2020 年 8 月,以下是在 Kubernetes 上寻找 NFS 持久性的方式:
You can你可以
apiVersion: v1
kind: Pod
metadata:
name: test-pd
spec:
containers:
- image: k8s.gcr.io/test-webserver
name: test-container
volumeMounts:
- mountPath: /test-pd
name: test-volume
volumes:
- name: test-volume
nfs:
path: /foo/bar
server: wherever.dns
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv0003
spec:
capacity:
storage: 5Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Recycle
storageClassName: slow
mountOptions:
- hard
- nfsvers=4.1
nfs:
path: /tmp
server: 172.17.0.2
external-storage
.external-storage
的(现已弃用) NFS PV 配置external-storage
。 This was last updated two years ago, and has been officially EOL'd, so good luck.kubernetes-sigs/nfs-subdir-external-provisioner
!kubernetes-sigs/nfs-subdir-external-provisioner
! It seems to work in a similar way to the old nfs-client
provisioner, but is much more up-to-date.nfs-client
配置程序类似,但要最新得多。 Huzzah!kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: example-nfs
provisioner: example.com/nfs
mountOptions:
- vers=4.1
master
, but not released) for the CSI driver.master
,但尚未发布)。external-storage
's NFS provisioner with something from the community, or something you write.external-storage
的 NFS 配置程序。 In researching this problem, I stumbled on a provisioner written by someone on GitHub, for example.I'm looking into doing the same thing.我正在考虑做同样的事情。 I found https://github.com/kubernetes-incubator/external-storage/tree/master/nfs , which I think you based your provisioner on?
我找到了https://github.com/kubernetes-incubator/external-storage/tree/master/nfs ,我认为您的配置器基于它?
I think an nfs provider would need to create a unique directory under the path defined.我认为 nfs 提供程序需要在定义的路径下创建一个唯一的目录。 I'm not really sure how this could be done.
我不确定如何做到这一点。
Maybe this is better of as an github issue on the kubernetes repo.也许这作为 kubernetes 存储库上的 github 问题更好。
Dynamic storage provisioning using NFS doesn't work, better use glusterfs.使用 NFS 的动态存储配置不起作用,最好使用 glusterfs。 There's a good tutorial with fixed to common problems while setting up.
有一个很好的教程,可以解决设置时的常见问题。 http://blog.lwolf.org/post/how-i-deployed-glusterfs-cluster-to-kubernetes/
http://blog.lwolf.org/post/how-i-deployed-glusterfs-cluster-to-kubernetes/
I also tried to enable the NFS provisioner on my kubernetes cluster and at first it didn't work, because the quickstart guide does not mention that you need to apply the rbac.yaml as well (I opened a PR to fix this).我还尝试在我的 kubernetes 集群上启用 NFS 配置器,但起初它不起作用,因为快速入门指南没有提到您还需要应用 rbac.yaml(我打开了一个PR来解决这个问题)。
The nfs provisioner works fine for me if I follow these steps on my cluster: https://github.com/kubernetes-incubator/external-storage/tree/master/nfs#quickstart如果我在集群上遵循以下步骤,nfs 配置程序对我来说很好用: https : //github.com/kubernetes-incubator/external-storage/tree/master/nfs#quickstart
$ kubectl create -f deploy/kubernetes/deployment.yaml
$ kubectl create -f deploy/kubernetes/rbac.yaml
$ kubectl create -f deploy/kubernetes/class.yaml
Then you should be able to create PVCs like this:然后你应该能够像这样创建 PVC:
$ kubectl create -f deploy/kubernetes/claim.yaml
You might want to change the folders used for the volume mounts in deployment.yaml
to match it with your cluster.您可能希望更改
deployment.yaml
用于卷挂载的文件夹,以使其与您的集群相匹配。
The purpose of StorageClass
is to create storage, eg from cloud providers (or "Provisioner" as they call it in the kubernetes docs). StorageClass
的目的是创建存储,例如从云提供商(或在 kubernetes 文档中称之为“供应商”)。 In case of NFS you only want to get access to existing storage and there is no creation involved.在 NFS 的情况下,您只想访问现有存储,不涉及创建。 Thus you don't need a
StorageClass
.因此您不需要
StorageClass
。 Please refer to this blog .请参阅此博客。
You can directly create pv, pvc shown below. 您可以直接创建如下所示的pv,pvc。 This is an example PV and PVC for private registry, it should work for most of the apps.
这是私有注册表的PV和PVC示例,它应该适用于大多数应用程序。 Make sure to install nfs server and configure the mount entries in nfs server's /etc/exports for access.
确保安装nfs服务器并在nfs服务器的/ etc / exports中配置安装条目以进行访问。
example:
/mnt/disks/vol1 <IP ADDRESS OF THE NODE>(rw,sync,no_root_squash,no_all_squash)
registry-pv.yml - registry-pv.yml -
apiVersion: v1
kind: PersistentVolume
metadata:
name: registry-pv
namespace: kube-system
spec:
accessModes:
- ReadWriteMany
capacity:
storage: 50Gi
nfs:
path: /mnt/disks/vol1
server: <IP-Address of NFS SERVER>
persistentVolumeReclaimPolicy: Retain
storageClassName: registry-storage
registry-pvc.yml - registry-pvc.yml -
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: registry-pvc
namespace: kube-system
labels:
kubernetes.io/cluster-service: "true"
addonmanager.kubernetes.io/mode: Reconcile
spec:
accessModes:
- ReadWriteMany
storageClassName: registry-storage
volumeName: registry-pv
resources:
requests:
storage: 50Gi
create pvc, pv - 创建pvc,pv -
kubectl create -f registry-pv.yml
kubectl create -f registry-pvc.yml
Once created you should see the pv bound to the pvc - 一旦创建,你应该看到pv绑定到pvc -
If you are using AWS, I believe you can use this image to create a NFS server:如果您使用的是 AWS,我相信您可以使用此映像来创建 NFS 服务器:
https://hub.docker.com/r/alphayax/docker-volume-nfs https://hub.docker.com/r/alphayax/docker-volume-nfs
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.