0/1个节点可用:1个Pod存在未绑定的即时PersistentVolumeClaims。

7
根据文档所述:
对于在StatefulSet中定义的每个VolumeClaimTemplate条目,每个Pod都会收到一个PersistentVolumeClaim。在上面的nginx示例中,每个Pod都会收到一个具有存储类my-storage-class和1 Gib预配存储容量的单个PersistentVolume。如果未指定StorageClass,则将使用默认的StorageClass。当Pod被(重新)调度到节点上时,其volumeMounts会挂载与其PersistentVolume Claims关联的PersistentVolumes。请注意,当Pod或StatefulSet被删除时,与Pod的PersistentVolume Claims关联的PersistentVolumes不会被删除。必须手动删除它们。
我感兴趣的部分是这个:If no StorageClass is specified, then the default StorageClass will be used。 我像这样创建了一个StatefulSet:
apiVersion: apps/v1
kind: StatefulSet
metadata:
  namespace: ches
  name: ches
spec:
  serviceName: ches
  replicas: 1
  selector:
    matchLabels:
      app: ches
  template:
    metadata:
      labels:
        app: ches
    spec:
      serviceAccountName: ches-serviceaccount
      nodeSelector:
        ches-worker: "true"
      volumes:
      - name: data
        hostPath:
          path: /data/test
      containers:
      - name: ches
        image: [here I have the repo]
        imagePullPolicy: Always
        securityContext:
            privileged: true
        args:
        - server
        - --console-address
        - :9011
        - /data
        env:
        - name: MINIO_ACCESS_KEY
          valueFrom:
            secretKeyRef:
              name: ches-keys
              key: access-key
        - name: MINIO_SECRET_KEY
          valueFrom:
            secretKeyRef:
              name: ches-keys
              key: secret-key
        ports:
        - containerPort: 9000
          hostPort: 9011
        resources:
          limits:
            cpu: 100m
            memory: 200Mi
        volumeMounts:
        - name: data
          mountPath: /data
      imagePullSecrets:
        - name: edge-storage-token
  volumeClaimTemplates:
  - metadata:
      name: data
    spec:
      accessModes:
      - ReadWriteOnce
      resources:
        requests:
          storage: 1Gi

当然,我已经创建了secrets、imagePullSecrets等,并将节点标记为ches-worker。
当我应用yaml文件时,pod处于挂起状态,kubectl describe pod ches-0 -n ches给出以下错误:
警告 FailedScheduling 6秒 default-scheduler 0/1个节点可用:1个pod有未绑定的立即PersistentVolumeClaims。抢占:0/1个节点可用:1个抢占对调度没有帮助。
我这里漏掉了什么吗?
3个回答

7

您需要创建一个 PV 以便获得一个 PVC 绑定。如果您想要从 PVC 声明中自动创建 PV,则需要在您的集群中安装 Provisioner。

首先创建一个具有至少与 PVC 所需空间相同的 PV。 然后,您可以应用包含 PVC 声明的部署 yaml。


不是强制性的。另请参考此链接:https://bluexp.netapp.com/blog/cvo-blg-kubernetes-statefulset-a-practical-guide - e7lT2P
没有 PV 或 Provvisoner 是行不通的。在这里也可以看看:https://dev59.com/uLTma4cB1Zd3GeqP4EvJ - Ralle Mc Black

2

K3s安装时,还会下载一个存储类,并将其设置为默认值。

使用kubectl get storageclass命令进行检查:

名称 供应商 回收策略 绑定模式 ALLOWVOLUMEEXPANSION 年龄 local-path rancher.io/local-path 删除 WaitForFirstConsumer false 8秒

另一方面,K8s集群不会下载默认的存储类。

为了解决这个问题:


1
本地路径对节点是通用的。在node2上启动的pod无法绑定在node1上创建的PV。在单节点安装中,这是可以接受的,但在集群中不行。 - Ralle Mc Black
警告: HostPath卷存在许多安全风险,最好的做法是尽量避免使用HostPaths。当必须使用HostPath卷时,应将其范围限定为仅所需的文件或目录,并以只读方式挂载。 如果通过AdmissionPolicy限制HostPath访问特定目录,则必须要求volumeMounts使用只读挂载,以使策略生效。 - undefined

0
我通过以下步骤解决了这个问题。
  1. 检查你拥有的内容

kubectl get pvc

kubectl get pv

  1. 删除所有内容

kubectl delete pv your-name-pv

kubectl delete pvc your-name-pvc

  1. 从头开始创建所有内容

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接