首页 > 解决方案 > 带有 xfs 的 Kubernetes PVC 挂载失败,代码为 32

问题描述

我有一个PodPersistentVolumeClaim. PVC 使用StorageClass带有文件系统的配置 EBS 卷xfs。设置如下:

        volumeMounts:
        - mountPath: "/opt/st1"
          name: opt-st1
      volumes:
      - name: opt-st1
        persistentVolumeClaim:
          claimName: st1-xfs-pvc
kind: PersistentVolumeClaim
metadata:
  name: st1-xfs-pvc
  labels:
    app: st1-xfs-pvc
spec:
  storageClassName: st1-xfs-sc
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 500Gi
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: st1-xfs-sc
provisioner: kubernetes.io/aws-ebs
parameters:
  type: st1
  fsType: xfs
reclaimPolicy: Retain
mountOptions:
  - debug
allowVolumeExpansion: true
volumeBindingMode: WaitForFirstConsumer
allowedTopologies:
- matchLabelExpressions:
  - key: failure-domain.beta.kubernetes.io/zone
    values:
    - us-east-1a

当我在基于 EKS 的集群(版本 1.13)上运行此设置时,我收到以下错误:

Events:
  Type     Reason                  Age                From                                    Message
  ----     ------                  ----               ----                                    -------
  Normal   Scheduled               45s                default-scheduler                       Successfully assigned jira-node-deployment-5f4f59c44d-jbc4c to ip-10-237-86-124.ec2.internal
  Warning  FailedAttachVolume      40s (x4 over 44s)  attachdetach-controller                 AttachVolume.Attach failed for volume "pvc-50996814-bf53-11e9-848f-0ec61103f6e0" : "Error attaching EBS volume \"vol-077709885f54252c7\"" to instance "i-0fe9867c4129f058e" since volume is in "creating" state
  Normal   SuccessfulAttachVolume  33s                attachdetach-controller                 AttachVolume.Attach succeeded for volume "pvc-50996814-bf53-11e9-848f-0ec61103f6e0"
  Warning  FailedMount             24s                kubelet, ip-10-237-86-124.ec2.internal  MountVolume.MountDevice failed for volume "pvc-50996814-bf53-11e9-848f-0ec61103f6e0" : mount failed: exit status 32
Mounting command: systemd-run
Mounting arguments: --description=Kubernetes transient mount for /var/lib/kubelet/plugins/kubernetes.io/aws-ebs/mounts/aws/us-east-1a/vol-077709885f54252c7 --scope -- mount -t xfs -o debug,defaults /dev/xvdbp /var/lib/kubelet/plugins/kubernetes.io/aws-ebs/mounts/aws/us-east-1a/vol-077709885f54252c7
Output: Running scope as unit run-979548.scope.
mount: /var/lib/kubelet/plugins/kubernetes.io/aws-ebs/mounts/aws/us-east-1a/vol-077709885f54252c7: wrong fs type, bad option, bad superblock on /dev/xvdbp, missing codepage or helper program, or other error.
  Warning  FailedMount  22s  kubelet, ip-10-237-86-124.ec2.internal  MountVolume.MountDevice failed for volume "pvc-50996814-bf53-11e9-848f-0ec61103f6e0" : mount failed: exit status 32

如果我连接到 Kubernetes 工作者,并手动运行相同的命令,我能够重现错误:

$ systemd-run --description='Kubernetes transient mount for /var/lib/kubelet/plugins/kubernetes.io/aws-ebs/mounts/aws/us-east-1a/vol-068d85e415249b896' --scope -- mount -t xfs -o debug,defaults /dev/xvdcg /var/lib/kubelet/plugins/kubernetes.io/aws-ebs/mounts/aws/us-east-1a/vol-068d85e415249b896
Running scope as unit run-982245.scope.
mount: /var/lib/kubelet/plugins/kubernetes.io/aws-ebs/mounts/aws/us-east-1a/vol-077709885f54252c7: mount point does not exist.

$ mkdir /var/lib/kubelet/plugins/kubernetes.io/aws-ebs/mounts/aws/us-east-1a/vol-077709885f54252c7

$ systemd-run --description='Kubernetes transient mount for /var/lib/kubelet/plugins/kubernetes.io/aws-ebs/mounts/aws/us-east-1a/vol-068d85e415249b896' --scope -- mount -t xfs -o debug,defaults /dev/xvdcg /var/lib/kubelet/plugins/kubernetes.io/aws-ebs/mounts/aws/us-east-1a/vol-068d85e415249b896
Running scope as unit run-982245.scope.
mount: /var/lib/kubelet/plugins/kubernetes.io/aws-ebs/mounts/aws/us-east-1a/vol-077709885f54252c7: wrong fs type, bad option, bad superblock on /dev/xvdbp, missing codepage or helper program, or other error.

$ echo $?
32

我注意到通过debug从命令中删除该选项并再次运行它,然后卷安装得很好......

$ systemd-run --description='Kubernetes transient mount for /var/lib/kubelet/plugins/kubernetes.io/aws-ebs/mounts/aws/us-east-1a/vol-077709885f54252c7' --scope -- mount -t xfs -o defaults /dev/xvdbp /var/lib/kubelet/plugins/kubernetes.io/aws-ebs/mounts/aws/us-east-1a/vol-077709885f54252c7
Running scope as unit run-986177.scope.

...然后Pod几秒钟后运行良好:

  Normal   Pulled       50s                  kubelet, ip-10-237-86-124.ec2.internal  Container image "nginx:alpine" already present on machine
  Normal   Created      49s                  kubelet, ip-10-237-86-124.ec2.internal  Created container
  Normal   Started      46s                  kubelet, ip-10-237-86-124.ec2.internal  Started container

我还注意到,如果我使用ext4而不是xfs,上述设置工作正常。

标签: linuxkubernetesamazon-eks

解决方案


过了一会儿,我意识到这个debug动作是我自己在StorageClass配置中添加的:

mountOptions:
  - debug

在我删除这两行之后,一切都按预期工作。


推荐阅读