【问题标题】:Pod can't mount to NFS pod on Docker Desktop local test environmentPod 无法挂载到 Docker Desktop 本地测试环境上的 NFS pod
【发布时间】:2021-12-04 09:46:29
【问题描述】:

我的远程工作设置如下:

PersistentVolume 挂载到gcePersistentDisk。 Pod “Lagg” 对整个永久性磁盘进行声明。 “Lagg”是一个谷歌容器volume-nfs 图像,它充当ReadWriteOnce 卷和我所有其他pod 都可以访问的NFS ReadWriteMany 之间的中间人。下面是 Lagg NFS 持久卷 YAML:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: lagg-volume
spec:
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteMany
  nfs:
    # kustomize does not add prefixes here, so they're placed ahead of time
    server: test-lagg.test-project.svc.cluster.local
    path: "/"

---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: lagg-claim
spec:
  accessModes:
    - ReadWriteMany
  storageClassName: ""
  resources:
    requests:
      storage: 5Gi

第二个PersistentVolume 通过 NFS 挂载到 pod,其他 pod 可以声明。其中一个 pod 是“Digit”,您可以在下面看到音量定义部分:

spec:
  template:
    spec:
      containers:
      - name: digit
        volumeMounts:
          - name: lagg-connection
            mountPath: "/cache"
      volumes:
      - name: lagg-connection
        persistentVolumeClaim:
          claimName: lagg-claim

因为我没有用于本地测试的 gcePersistentDisk,所以我的这个集群的本地版本使用另一个名为“Lagg-local”的持久卷,它只是取代了 gcePersistentDisk,看起来像这样:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: lagg-local-volume
  labels:
    type: local
spec:
  storageClassName: manual
  persistentVolumeReclaimPolicy: Delete
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteOnce
  local:
    path: /run/desktop/mnt/host/c/project/cache
  nodeAffinity:
    required:
      nodeSelectorTerms:
        - matchExpressions:
            - key: kubernetes.io/hostname
              operator: In
              values:
                - docker-desktop
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: lagg-local-claim
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 5Gi

当我尝试在本地运行它时,我只收到一个错误,它在 Digit pod 中,使用 describe,它说:

Events:
  Type     Reason       Age                From               Message
  ----     ------       ----               ----               -------
  Normal   Scheduled    47s                default-scheduler  Successfully assigned test-project/test-digit-cff6bd9c6-gz2sn to docker-desktop
  Warning  FailedMount  11s (x7 over 43s)  kubelet            MountVolume.SetUp failed for volume "test-lagg-volume" : mount failed: exit status 32
Mounting command: mount
Mounting arguments: -t nfs test-lagg.test-project.svc.cluster.local:/ /var/lib/kubelet/pods/80f686cf-47bb-478b-a581-c179794e2182/volumes/kubernetes.io~nfs/test-lagg-volume
Output: mount.nfs: Failed to resolve server test-lagg.test-project.svc.cluster.local: Name or service not known

据我所知,Pod 根本无法联系 NFS 服务器,或者可能无法解析 DNS。 test-lagg 存在并且正在运行,并且 test-project 是 test-lagg (指向 lagg NFS pod 的服务)和 test-digit 所在的命名空间。所以我不完全确定这里发生了什么。

我相信 NFS 服务器工作正常,因为在卷的根目录中创建了一个文件“index.html”,其中仅包含“Hello from NFS!”

如果我使用cpuguy83/nfs-server 图像而不是google_containers/volume-nfs,也会发生同样的错误

如果我定义 clusterIP 而不是 DNS 名称,则会发生不同的错误,说明它没有权限。

我也不认为与服务的连接存在问题,因为在数字 pod 上运行 nslookup 会返回以下内容:

root@test-digit-7c6dc66659-q4trw:/var/www/static# nslookup test-lagg.test-project.svc.cluster.local
Server:         10.96.0.10
Address:        10.96.0.10#53

Name:   test-lagg.test-project.svc.cluster.local
Address: 10.105.85.125

NFS pod 本身也正确安装了卷:

On GKE:
PS C:\Users\ral\Documents\Projects\Project\Kubernetes> kubectl exec next-lagg-69884bf49b-fn544 -- bash -c "findmnt /exports -o TARGET,SOURCE,FSTYPE"
TARGET   SOURCE   FSTYPE
/exports /dev/sdb ext4

On local:
PS C:\Users\ral\Documents\Projects\Project\Kubernetes> kubectl exec test-lagg-547cbb779-4qgbl -- bash -c "findmnt /exports -o TARGET,SOURCE,FSTYPE"
TARGET   SOURCE             FSTYPE
/exports C:\[/Project/cache] 9p

【问题讨论】:

    标签: kubernetes kubernetes-pod docker-desktop persistent-volumes


    【解决方案1】:

    google_containers/volume-nfs 在非 GKE 集群上的 DNS 解析问题是一个已知问题:

    基本上,NFS 服务器不支持主机名,只支持 IP。

    您也可以使用csi-driver-nfs

    【讨论】:

      猜你喜欢
      • 2020-12-07
      • 2021-12-22
      • 2021-10-30
      • 2021-11-26
      • 2019-10-19
      • 1970-01-01
      • 2021-06-14
      • 1970-01-01
      • 2021-12-14
      相关资源
      最近更新 更多