我正在尝试设置此处(https://kubernetes.io/blog/2018/04/13/local-persistent-volumes-beta/)概述的本地存储。我收到以下错误消息,即调度程序无法调度Pod。本地存储映射到工作节点之一。我尝试在主节点上设置本地存储,但遇到了同样的错误。我在哪里错?
警告失败调度24秒(x2超过24秒)默认调度程序0/3节点可用:1个节点与节点选择器不匹配,2个节点未找到要绑定的可用持久卷。
-------------------------------------------------------------------
kubectl get nodes -o wide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
rpi-k8-workernode-2 Ready <none> 92d v1.15.0 192.168.100.50 <none> Raspbian GNU/Linux 9 (stretch) 4.19.42-v7+ docker://18.9.0
rpi-mon-k8-worker Ready <none> 91d v1.15.0 192.168.100.22 <none> Raspbian GNU/Linux 9 (stretch) 4.19.42-v7+ docker://18.9.0
udubuntu Ready master 92d v1.15.1 192.168.100.24 <none> Ubuntu 18.04.3 LTS 4.15.0-55-generic docker://19.3.4
-------------------------------------------------------------------
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: local-storage
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer
------------------------------------------------------------------------
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-ghost
namespace: ghost
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
storageClassName: local-storage
local:
path: /mnt/mydrive/ghost-data/
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- rpi-mon-k8-worker
------------------------------------------------------------------------
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-ghost
namespace: ghost
labels:
pv: pv-ghost
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
storageClassName: local-storage
selector:
matchLabels:
name: pv-ghost
------------------------------------------------------------------------
apiVersion: apps/v1
kind: Deployment
metadata:
name:
deployment-ghost
namespace: ghost
labels:
env: prod
app: ghost-app
spec:
template:
metadata:
name: ghost-app-pod
labels:
app: ghost-app
env: production
spec:
containers:
- name: ghost
image: arm32v7/ghost
imagePullPolicy: IfNotPresent
volumeMounts:
- mountPath: /var/lib/ghost/content
name: ghost-blog-data
securityContext:
privileged: True
volumes:
- name: ghost-blog-data
persistentVolumeClaim:
claimName: pvc-ghost
nodeSelector:
beta.kubernetes.io/arch: arm
replicas: 2
selector:
matchLabels:
app: ghost-app
kubectl get nodes --show-labels
NAME STATUS ROLES AGE VERSION LABELS
rpi-k8-workernode-2 Ready <none> 93d v1.15.0 beta.kubernetes.io/arch=arm,beta.kubernetes.io/os=linux,kubernetes.io/arch=arm,kubernetes.io/hostname=rpi-k8-workernode-2,kubernetes.io/os=linux
rpi-mon-k8-worker Ready <none> 93d v1.15.0 beta.kubernetes.io/arch=arm,beta.kubernetes.io/os=linux,kubernetes.io/arch=arm,kubernetes.io/hostname=rpi-mon-k8-worker,kubernetes.io/os=linux
udubuntu Ready master 93d v1.15.1 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=udubuntu,kubernetes.io/os=linux,node-role.kubernetes.io/master=
-----------------------------------------------------------
ud@udubuntu:~/kube-files$ kubectl describe pvc pvc-ghost -n ghost
Name: pvc-ghost
Namespace: ghost
StorageClass: manual
Status: Pending
Volume:
Labels: pv=pv-ghost
Annotations: kubectl.kubernetes.io/last-applied-configuration:
{"apiVersion":"v1","kind":"PersistentVolumeClaim","metadata":{"annotations":{},"labels":{"pv":"pv-ghost"},"name":"pvc-ghost","namespace":"...
Finalizers: [kubernetes.io/pvc-protection]
Capacity:
Access Modes:
VolumeMode: Filesystem
Mounted By: <none>
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal WaitForFirstConsumer 6s (x2 over 21s) persistentvolume-controller waiting for first consumer to be created before binding
答案 0 :(得分:1)
从警告1 node(s) didn't match node selector, 2 node(s) didn't find available persistent volumes to bind.
中可以看到,您在Deployment-ghost中设置了nodeSelector
,因此您的一个工作节点与此选择器不匹配。如果删除{{ 1}}字段。这样,吊舱将被部署到创建nodeSelector
的节点上。 AFAIK,无法将吊舱部署到PV
曾经声明在另一个工作程序节点中的工作程序中。
最后,在其他节点中,没有创建PV
。您可以通过以下方式检查创建的PV
和PV
:
PVC
,并通过以下方法检查它们的详细信息:
kubectl get pv
kubectl get pvc -n <namespace>
您的问题在her的官方文档中进行了说明:
索赔可以指定标签选择器来进一步过滤 卷。只能绑定标签与选择器匹配的卷 索赔。选择器可以包含两个字段:
1- matchLabels-卷必须具有带有该值的标签
2- matchExpressions-通过指定键,值列表以及与键和值相关的运算符制成的要求列表。有效的运算符包括In,NotIn,Exists和DidNotExist
因此,编辑PersistentVolume文件并添加标签字段,如下所示:
kubectl describe pv <pv_name>
kubectl describe pv <pv_name> -n <namespace>
没有必要向apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-ghost
labels:
name: pv-ghost
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
storageClassName: local-storage
local:
path: /mnt/mydrive/ghost-data/
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- rpi-mon-k8-worker
添加 namespace 字段,因为kind: persistantVolume
绑定是排他的,而PersistentVolumes
是命名空间的对象。
我测试了它,对我有用。