卷已经专门附加到一个节点,不能附加到另一个节点

Volume is already exclusively attached to one node and can't be attached to another

我有一个非常简单的 Kubernetes pod。我想要一个有状态的集合并想要以下过程:

  1. 我想要一个 initcontainer 下载并将 tarball 从 s3 解压缩到安装到 initcontainer 的卷中
  2. 我想将该卷挂载到我的主容器中以供使用

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: app
  namespace: test
  labels:
    name: app
spec:
  serviceName: app
  replicas: 1
  selector:
    matchLabels:
      app: app
  template:
    metadata:
      labels:
        app: app
    spec:
      initContainers:
      - name: preparing
        image: alpine:3.8
        imagePullPolicy: IfNotPresent
        command:
          - "sh"
          - "-c"
          - |
            echo "Downloading data"
            wget https://s3.amazonaws.com/.........
            tar -xvzf xxxx-........ -C /root/
        volumeMounts:
        - name: node-volume
          mountPath: /root/data/

      containers:
      - name: main-container
        image: ecr.us-west-2.amazonaws.com/image/:latest
        imagePullPolicy: Always

        volumeMounts:
        - name: node-volume
          mountPath: /root/data/

  volumeClaimTemplates:
  - metadata:
      name: node-volume
    spec:
      accessModes: [ "ReadWriteOnce" ]
      storageClassName: gp2-b
      resources:
        requests:
          storage: 80Gi

我继续收到以下错误:

起初我 运行 这个我可以看到 initcontainer 下载我的 tarball 的日志流。大约完成一半它终止并给我以下错误:

Multi-Attach error for volume "pvc-faedc8" Volume is 
already exclusively attached to one node and can't be 
attached to another

看起来您有一个悬挂的 PVC and/or PV 连接到您的一个节点。您可以通过 ssh 进入节点并 运行 a dfmount 进行检查。

如果您查看 this,StatefulSet 中的 PVC 总是映射到它们的 pod 名称,因此您可能仍然有一个悬挂的 pod(?)

如果你有一个吊舱:

$ kubectl -n test delete pod <pod-name>

您可能需要强制执行它:

$ kubectl -n test delete pod <pod-name> --grace-period=0 --force

那你可以尝试删除PVC及其对应的PV:

$ kubectl delete pvc pvc-faedc8
$ kubectl delete pv <pv-name>

我现在遇到了同样的问题,问题是,pod 通常 运行 所在的节点已关闭,另一个接管了(无论出于何种原因,它都没有按预期工作).之前已经出现过几次“节点关闭”的情况,但从未引起任何问题。在没有备份节点的情况下,无法备份 StatefulSet 和 Deployment 和 运行。

我有一个类似的错误:

 The volume pvc-2885ea01-f4fb-11eb-9528-00505698bd8b 
   cannot be attached to the node node1 since it is already attached to the node node2*

我使用 longhorn 作为存储供应商和管理器。所以我只是在错误中分离了这个 pv 并重新启动了有状态集。这次它自动能够正确附加到 pv。