Entry
https://kubernetes.io/docs/concepts/storage/volumes/#nfs
这个demo很有意思,从之前来看,如果需要为K8s设置NFS,则我们需要一个physical NFS server,然后create PV based on that NFS server then PVC claim from PV. 这样需要自己去维护NFS的健康保证high availability.
这个例子完全将NFS交给了K8s来管理,它先提供一块存储去构造PVC(这块存储可能来自provisioner或者其他PV),然后用这个PVC构造了一个NFS server pod以及给这个pod绑定了一个cluster IP,这样就相当于一个虚拟的physical NFS server node了。当我们需要PV的时候,就从这个NFS server pod中取(本质就是从一个PV中构造另一些PV)。
当然为了满足NFS的特性,这个NFS server的镜像必须要特别的构造,安装了NFS的组件,暴露相关端口,以及在初始化启动程序中配置好/etc/export
的相关参数。以及当NFS server pod被重新构造时,保证之前的share不受影响。
这样的好处就是完全交给K8s去管理,不用担心NFS高可用性的问题,也不用自己去搭建物理的NFS cluster了,只要提供一块存储,就可以构造成NFS。
Demo
写这个blog的时候这个demo yaml中有一些错误参数,以我的blog准,这是demo git repository: https://github.com/kubernetes/examples/tree/master/staging/volumes/nfs
Under provisioner folder, it uses storageclass (internal provisioner) to create a PV, for example, in GCE:
1 | apiVersion: v1 |
If no internal provisioner is available, you can create an external provisioner (for example: NFS), or just create a PV with hostPath:
1 | kind: PersistentVolume |
This /nfs-server-pv
folder will be created on the host where nfs server pod reside.
Then it creates a replicationController
for NFS server (just like a physical NFS server):
1 | apiVersion: v1 |
Notice that the image is dedicated with nfs-utils pre-installed, and it expose some nfs dedicated ports, see the dockerfile:
1 | FROM centos |
Then create a service with cluster IP to expose the NFS server pod.
1 |
|
Then we can create application PV and PVC from this service: refer to DNS for service and pod.
1 |
|
Then you can create PVC bind this PV for other use.