库伯内斯 : node(s) didn't find available persistent volumes to bind

标签 kubernetes

我正尝试按照此处 (https://kubernetes.io/blog/2018/04/13/local-persistent-volumes-beta/) 的概述设置本地存储。我收到以下错误,调度程序无法安排 pod。本地存储映射到工作节点之一。我尝试在主节点上设置本地存储,但出现了同样的错误。我哪里出错了?

警告 FailedScheduling 24s(x2 超过 24s)默认调度程序 0/3 节点可用:1 个节点与节点选择器不匹配,2 个节点未找到可用的持久卷来绑定(bind)。

-------------------------------------------------------------------

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

最佳答案

正如您从警告中看到的那样 1 node(s) didn't match node selector, 2 node(s) didn't find available persistent volumes to bind.,您设置了一个 nodeSelector 在 deployment-ghost 中,因此您的工作节点之一与此选择器不匹配。如果您从该 .yaml 文件中删除 nodeSelector 字段。通过这种方式,pod 将部署到创建 PV 的节点。 AFAIK,不可能将 pod 部署到 PV 曾经声称位于另一个工作节点中的工作节点。 最后,在其他节点中,没有创建任何 PV。您可以通过以下方式检查创建的 PVPVC:

kubectl get pv
kubectl get pvc -n <namespace>

并通过以下方式检查它们的详细信息:

kubectl describe pv <pv_name> 
kubectl describe pv <pv_name> -n <namespace>

您的问题在 her 中的官方文档中进行了解释上面写着:

Claims can specify a label selector to further filter the set of volumes. Only the volumes whose labels match the selector can be bound to the claim. The selector can consist of two fields:

1- matchLabels - the volume must have a label with this value

2- matchExpressions - a list of requirements made by specifying key, list of values, and operator that relates the key and values. Valid operators include In, NotIn, Exists, and DoesNotExist

因此,编辑 PersistentVolume 文件并添加如下所示的标签字段:

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 绑定(bind)是排他的,并且 PersistentVolumeClaims 是命名空间对象。

我对其进行了测试,它对我有用。

关于库伯内斯 : node(s) didn't find available persistent volumes to bind,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58671234/

相关文章:

kubernetes - 如何通过 Helm 图表从 json 中读取值

docker - 挂载错误(13):权限被拒绝-在docker/kubernetes中

kubernetes - 将文件注入(inject) Pod 的最佳方式是什么?

kubernetes - k8s 中的 cpu 限制大小应该确定为多少?

kubernetes - Grafana Helm 通知配置

kubernetes - 部署nginx入口 Controller 时错误创建资源 “configmaps”

kubernetes - 将所有 secret 作为环境变量插入 kubernetes 部署中

java - 控制通过 Kubernetes 部署的 POD 的主机名

kubernetes - Istio Mesh Federation位置感知

ubuntu - 如何在 Ubuntu 14 中安装最新的生产级 Kubernetes