将映像类型从container-vm迁移到GKE集群节点的cos后,似乎无法再为pod挂载NFS卷。
问题似乎是缺少NFS客户端库,因为命令行的mount命令在我尝试的所有COS版本上都失败了(cos-stable-58-9334-62-0,cos-beta-59-9460-20- 0,cos-dev-60-9540-0-0)。
sudo mount -t nfs mynfsserver:/myshare /mnt
失败
mount: wrong fs type, bad option, bad superblock on mynfsserver:/myshare,
missing codepage or helper program, or other error
(for several filesystems (e.g. nfs, cifs) you might
need a /sbin/mount.<type> helper program)
但这与此处列出的受支持的卷类型相矛盾: https://cloud.google.com/container-engine/docs/node-image-migration#storage_driver_support
在pod中挂载NFS卷适用于图像类型为container-vm
但不包含cos
的池中。
使用cos,我会收到kubectl describe pod
的以下消息:
MountVolume.SetUp failed for volume "kubernetes.io/nfs/b6e6cf44-41e7-11e7-8b00-42010a840079-nfs-mandant1" (spec.Name: "nfs-mandant1") pod "b6e6cf44-41e7-11e7-8b00-42010a840079" (UID: "b6e6cf44-41e7-11e7-8b00-42010a840079") with: mount failed: exit status 1
Mounting command: /home/kubernetes/containerized_mounter/mounter
Mounting arguments: singlefs-1-vm:/data/mandant1 /var/lib/kubelet/pods/b6e6cf44-41e7-11e7-8b00-42010a840079/volumes/kubernetes.io~nfs/nfs-mandant1 nfs []
Output: Mount failed: Mount failed: exit status 32
Mounting command: chroot
Mounting arguments: [/home/kubernetes/containerized_mounter/rootfs mount -t nfs singlefs-1-vm:/data/mandant1 /var/lib/kubelet/pods/b6e6cf44-41e7-11e7-8b00-42010a840079/volumes/kubernetes.io~nfs/nfs-mandant1]
Output: mount.nfs: Failed to resolve server singlefs-1-vm: Temporary failure in name resolution
答案 0 :(得分:0)
Martin,您是手动设置挂载(自己执行挂载),还是让kubernetes通过引用NFS卷的pod代表您进行挂载?
前者不起作用。后来会。正如您所发现的,COS不附带NFS客户端库,因此GKE通过设置一个chroot(在/ home / kubernetes / containerized_mounter / rootfs)并使用所需的二进制文件并在其中调用mount来解决这个问题。
答案 1 :(得分:0)
我已经从kubernetes项目中删除了上面提到的解决方案@ saad-ali,以便完成这项工作。
具体来说,我已将以下内容添加到我的cloud-config:
# This script creates a chroot environment containing the tools needed to mount an nfs drive
- path: /tmp/mount_config.sh
permissions: 0755
owner: root
content: |
#!/bin/sh
set +x # For debugging
export USER=root
export HOME=/home/dockerrunner
mkdir -p /tmp/mount_chroot
chmod a+x /tmp/mount_chroot
cd /tmp/
echo "Sleeping for 30 seconds because toolbox pull fails otherwise"
sleep 30
toolbox --bind /tmp /google-cloud-sdk/bin/gsutil cp gs://<uploaded-file-bucket>/mounter.tar /tmp/mounter.tar
tar xf /tmp/mounter.tar -C /tmp/mount_chroot/
mount --bind /tmp/mount_chroot /tmp/mount_chroot
mount -o remount, exec /tmp/mount_chroot
mount --rbind /proc /tmp/mount_chroot/proc
mount --rbind /dev /tmp/mount_chroot/dev
mount --rbind /tmp /tmp/mount_chroot/tmp
mount --rbind /mnt /tmp/mount_chroot/mnt
上传文件桶容器,即kube团队创建的chroom图像,从以下网址下载:https://storage.googleapis.com/kubernetes-release/gci-mounter/mounter.tar
然后,cloud-config的runcmd看起来像:
runcmd:
- /tmp/mount_config.sh
- mkdir -p /mnt/disks/nfs_mount
- chroot /tmp/mount_chroot /bin/mount -t nfs -o rw nfsserver:/sftp /mnt/disks/nfs_mount
这很有效。像地狱一样丑陋,但它现在必须做。