目录
1、jupyter-notebook未指定存储位置,缺少存储空间
2、手动为Jupyter创建PV和PVC
?3、自动创建PV
问题1: pod has unbound immediate PersistentVolumeClaims
1、jupyter-notebook未指定存储位置,缺少存储空间
刚开始使用jupyter notebook,点击【+NEW SERVER】按钮,弹出的页面会出现如下报错:
No default Storage Class is set. Can’t create new Disks for the new Notebook
简单说明一下该页面的内容
我们使用过jupyter-notebook的都知道,jupyter的代码文件,数据在本地需要一个存储位置,所以在创建一个新的jupyter任务,即创建一个pod之前,要为其准备好一个pv及其pvc,我们先手动创建一下。
2、手动为Jupyter创建PV和PVC
创建PV(前提:nfs挂载已经配置成功)
jupyter-pv.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: jupyter-pv
spec:
capacity:
storage: 5Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Delete
storageClassName: local-storage #指定存储类型名称,在创建PVC时可以指定这个名称
local:
path: /nfs/data/myfilesystem/ #改成你的目录地址
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname #使用hostname指定pv挂载的节点
operator: In
values:
- k8snode02 #pv挂载的节点
执行yaml文件
[root@k8snode01 ~]# kubectl apply -f jupyter-pv.yaml
persistentvolume/jupyter-pv created
[root@k8snode01 ~]# kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
jupyter-pv 5Gi RWO Delete Available local-storage 109s
创建PVC
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: jupyter-pvc
namespace: machinelearning #指定pvc所属的命名空间
spec:
accessModes:
- ReadWriteOnce
volumeMode: Filesystem
resources:
requests:
storage: 5Gi
storageClassName: local-storage #指定存储类型名称,即指向我们刚刚创建的PV
执行yaml文件
[root@k8snode01 jupyter3]# kubectl apply -f jupyter-pvc.yaml
persistentvolumeclaim/jupyter-pvc created
[root@k8snode01 jupyter3]# kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
jupyter-pvc 5Gi RWO Delete Bound machinelearning/jupyter-pvc local-storage 8m42s
至此,PV和PVC都已经创建并挂载成功,可以在页面中创建Jupyter任务喽~
拉取官方的jupyter镜像,下载源为阿里云
docker pull registry.aliyuncs.com/kubeflow-images-public/tensorflow-1.15.2-notebook-cpu:1.0.0
点击【Launch】,出现下图。
?创建成功,点击【CONNECT】查看是否可以正常使用。
?一切正常。
?3、自动创建PV
上文介绍了如何手动为Jupyter创建PV和PVC,但这样稍显麻烦,因为每次想要创建Jupyter任务就必须手动创建一个PV和一个PVC,还要在创建Jupyter任务时指定PVC名称。因此我们这里介绍如何为Jupyter自动创建PV(jupyter可以自己创建PVC)。
自动创建PV,在kubernetes的官方文档中被称为StorageClass,官方文档链接如下,想要了解可以去看
https://kubernetes.io/zh/docs/concepts/storage/storage-classes/
?我们这里简单提一下这个概念
StorageClass 为管理员提供了描述存储 "类" 的方法。 不同的类型可能会映射到不同的服务质量等级或备份策略,或是由集群管理员制定的任意策略,这一句话有点难以理解,通俗的说,storageClass提供了一个创建PV的模板,在storageClass的这个模板中,可以指定PV的创建策略(动态or静态?),大小,读写策略,绑定策略等等,有了这些信息,Kubernetes就能够根据用户提交的PVC,找到对应的StorageClass,然后Kubernetes就会调用 StorageClass声明的存储插件,创建出需要的PV。
我们现在要做的,就是在k8s集群中创建一个能够动态创建PV的storageClass,但首先,我们需要制备器,k8s也提供了一些内置的制备器,但没有提供nfs制备器,因此要创建一个nfs存储制备器,拉取nfs-client-provisioner镜像来创建。
??serviceAccount.yaml(服务账户,供nfs存储制备器使用)
apiVersion: v1
kind: ServiceAccount
metadata:
name: nfs-client-provisioner
namespace: kubeflow
nfs-provisioner.yaml
kind: Deployment
apiVersion: apps/v1
metadata:
name: nfs-client-provisioner
namespace: kubeflow
labels:
app: nfs-client-provisioner
spec:
replicas: 1
selector:
matchLabels:
app: nfs-client-provisioner
strategy:
type: Recreate
template:
metadata:
labels:
app: nfs-client-provisioner
spec:
serviceAccount: nfs-client-provisioner #需要指定serviceAccount
containers:
- name: nfs-client-provisioner
image: registry.cn-hangzhou.aliyuncs.com/open-ali/nfs-client-provisioner
volumeMounts:
- name: nfs-client-root
mountPath: persistentvolumes
env:
- name: PROVISIONER_NAME
value: kubeflow/nfs #nfs制备器的名称,很重要
value: 192.168.52.11
- name: NFS_PATH
value: /nfs/data/jupyter-system/ #改成你自己的目录
volumes:
- name: nfs-client-root
nfs:
server: 192.168.52.11
path: /nfs/data/jupyter-system/ #改成你自己的目录
storageClass.yaml
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: kubeflow-nfs-storage
provisioner: kubeflow/nfs #这里很重要,指定了存储制备器的名称
?此时我们在页面里新创建一个jupyter任务test8,看看能否创建成功
没有创建成功,在后台我们describe test8的pod,提示为:?pod has unbound immediate PersistentVolumeClaims,再describe这个pvc,提示为:
waiting for a volume to be created, either by external provisioner "kubeflow/nfs" or manually created by system administrator 。
可见,k8s集群已经识别到了我们创建的制备器kubeflow/nfs,但是kubeflow/nfs制备器却没有创建出PV供test8的pod使用,那我们再去看看kubeflow/nfs制备器输出的日志是什么,日志报错如下:
E0803 12:12:29.638859?????? 1 leaderelection.go:240] error retrieving resource lock to provision for pvc machinelearning/workspace-test8: Unauthorized E0803 12:12:29.854807?????? 1 reflector.go:201] github.com/kubernetes-incubator/external-storage/lib/controller/controller.go:412: Failed to list *v1.PersistentVolume: Unauthorized E0803 12:12:29.858120?????? 1 reflector.go:201] github.com/kubernetes-incubator/external-storage/lib/controller/controller.go:384: Failed to list *v1.StorageClass: Unauthorized E0803 12:12:30.260233?????? 1 reflector.go:201] github.com/kubernetes-incubator/external-storage/lib/controller/controller.go:411: Failed to list *v1.PersistentVolumeClaim: Unauthorized E0803 12:12:30.864208?????? 1 reflector.go:201] github.com/kubernetes-incubator/external-storage/lib/controller/controller.go:384: Failed to list *v1.StorageClass: Unauthorized E0803 12:12:30.864208?????? 1 reflector.go:201] github.com/kubernetes-incubator/external-storage/lib/controller/controller.go:412: Failed to list *v1.PersistentVolume: Unauthorized E0803 12:12:31.265828?????? 1 reflector.go:201] github.com/kubernetes-incubator/external-storage/lib/controller/controller.go:411: Failed to list *v1.PersistentVolumeClaim: Unauthorized E0803 12:12:31.870389?????? 1 reflector.go:201] github.com/kubernetes-incubator/external-storage/lib/controller/controller.go:412: Failed to list *v1.PersistentVolume: Unauthorized E0803 12:12:31.871317?????? 1 reflector.go:201] github.com/kubernetes-incubator/external-storage/lib/controller/controller.go:384: Failed to list *v1.StorageClass: Unauthorized E0803 12:12:32.270119?????? 1 reflector.go:201] github.com/kubernetes-incubator/external-storage/lib/controller/controller.go:411: Failed to list *v1.PersistentVolumeClaim: Unauthorized E0803 12:12:32.876115?????? 1 reflector.go:201] github.com/kubernetes-incubator/external-storage/lib/controller/controller.go:412: Failed to list *v1.PersistentVolume: Unauthorized E0803 12:12:32.877442?????? 1 reflector.go:201] github.com/kubernetes-incubator/external-storage/lib/controller/controller.go:384: Failed to list *v1.StorageClass: Unauthorized E0803 12:12:33.275154?????? 1 reflector.go:201] github.com/kubernetes-incubator/external-storage/lib/controller/controller.go:411: Failed to list *v1.PersistentVolumeClaim: Unauthorized
?
|