简体   繁体   English

Kubernetes:使用 NFS 的动态持久卷配置

[英]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你可以

  • Put an NFS volume on a Pod directly:直接将 NFS 卷放在 Pod 上:
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
  • Manually create a Persistent Volume backed by NFS, and mount it with a Persistent Volume Claim (PV spec shown below):手动创建一个由 NFS 支持的 Persistent Volume,并使用 Persistent Volume Claim 挂载它(PV 规范如下所示):
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
  • Use the (now deprecated) NFS PV provisioner from external-storage .使用external-storage的(现已弃用) NFS PV 配置external-storage This was last updated two years ago, and has been officially EOL'd, so good luck.这是两年前最后一次更新,并已正式停产,祝你好运。 With this route, you can make a Storage Class such as the one below to fulfill PVCs from your NFS server.通过这条路线,您可以创建一个如下所示的存储类来满足您的 NFS 服务器的 PVC。
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: example-nfs
provisioner: example.com/nfs
mountOptions:
  - vers=4.1
  • Evidently, CSI is the future, and there is a NFS CSI driver.显然,CSI 是未来,并且有一个 NFS CSI 驱动程序。 However, it doesn't support dynamic provisioning yet, so it's not really terribly useful.然而,它还不支持动态配置,所以它并不是非常有用。
    • Update (December 2020): Dynamic provisioning is apparently in the works (on master , but not released) for the CSI driver.更新(2020 年 12 月): CSI 驱动程序的动态配置显然正在进行中(在master ,但尚未发布)。
  • You might be able to replace 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.例如,在研究这个问题时,我偶然发现了某人在 GitHub 上编写的配置程序 Whether such provisioners perform well, are secure, or work at all is beyond me, but they do exist.这些供应商是否表现良好,是否安全,或者根本无法工作,我无法理解,但它们确实存在。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM