Kubernetes:创建动态本地卷以自动为PVC分配PV的最佳实践是什么? [英] Kubernetes: What is the best practice for create dynamic local volume to auto assign PVs for PVCs?
问题描述
最近,我通过kubeadm init
在我的CentOS7集群上安装了k8.不幸的是,我遇到了很多问题.最大的问题是如何创建动态本地存储/卷以自动为PVC分配PV?"
Recently, I installed the k8s via kubeadm init
on my CentOS7 clusters. Unfortunately, I suffered a lots of problems. The biggest problem is "How to create a dynamic local storage/volume for automatically assign PVs for PVCs?"
问:为什么本地存储不是云存储服务?
Q: Why local storage not cloud storage service?
A:这是我大学新实验室的局限性.
A: This is a limitation of new lab of my university.
问题描述:
在成功完成安装过程之后,k8s(v1.18.0)没有为我创建默认存储类.我不确定这种情况是否正常.但是,当我安装第一个应用程序时, JupyterHub ,在k8s上,我得到了一个错误,因为它可以找到适合PVC hub-db-dir
的合适PV.然后,我尝试手动手动创建一个本地存储类和一个PV,如下所示:
The k8s(v1.18.0) did not create a default storage class for me after the installing process successfully. I not sure about that whether the situation normally. However, when I install my first application, JupyterHub, on k8s, I got error from it because it could found a suitable PV to fit a PVC hub-db-dir
. And then I attempt to manually a local storage class and a PV such below:
local-storage.yaml
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: local-storage
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer
hub-db-pv.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: hub-db-pv
namespace: jhub
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
storageClassName: local-storage
local:
path: /home/k8s_data_dir/jhub_dir
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- node1
- node2
- node3
- node4
我应用了这些yaml
文件之后,JupyterHub便开始工作.我认为使用JupyterHub将成功.但是我太天真了.我进入JupyterHub的主页,然后无法运行,因为JupyterHub为我创建了一个新的PVC,但无法绑定合适的PV.
我猜这是我的本地存储类导致的错误,该类无法自动创建PV以适合PVC.然后,我尝试使用外部供应商 sig-storage-lib-external-provisioner
但它不能解决我的本地存储问题. (我是按照sig-storage-lib-external-provisioner
的教程来做的.)
The JupyterHub work after I apply these yaml
files. I thought that will success to use JupyterHub. But I so naive. I enter the main page of JupyterHub then failure to running, because the JupyterHub create a new PVC for me but it could not bound a suitable PV.
I guess that the error cause by my local storage class which unable to auto create a PV to fit a PVC. Then I try to use an external provisioner sig-storage-lib-external-provisioner
but it can not fix my problem of local storage. (I according to the tutorial of sig-storage-lib-external-provisioner
to do.)
所以,我的问题是:
- 解决本地存储问题的最佳实践是什么?
- 如果您有妥协的方法来做同样的事情,请帮助我!
最后,我很感谢您的帮助!
Finally, I honest to thank you for your help!
推荐答案
使用local-storage
StorageClass
从文档 此处介绍如何在Kubernetes集群中管理本地卷.
From the docs here on how to manage local volumes in your Kubernetes cluster.
- 创建供供应商发现的目录
- 在发现目录中准备并设置本地卷