Kubernetes 使用容器操作系统(COS)在Google容器引擎中装载NFS卷
在为GKE集群的节点将映像类型从容器vm迁移到cos之后,似乎不再可能为pod装载NFS卷 问题似乎是缺少NFS客户端库,因为命令行中的mount命令在我尝试的所有COS版本(COS-stable-58-9334-62-0、COS-beta-59-9460-20-0、COS-dev-60-9540-0-0)上都失败 失败于Kubernetes 使用容器操作系统(COS)在Google容器引擎中装载NFS卷,kubernetes,nfs,google-kubernetes-engine,google-container-os,Kubernetes,Nfs,Google Kubernetes Engine,Google Container Os,在为GKE集群的节点将映像类型从容器vm迁移到cos之后,似乎不再可能为pod装载NFS卷 问题似乎是缺少NFS客户端库,因为命令行中的mount命令在我尝试的所有COS版本(COS-stable-58-9334-62-0、COS-beta-59-9460-20-0、COS-dev-60-9540-0-0)上都失败 失败于 mount: wrong fs type, bad option, bad superblock on mynfsserver:/myshare, missin
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)
Martin,您是手动设置挂载(自己执行挂载),还是让kubernetes通过引用NFS卷的pod代表您执行挂载
前者行不通。后者会。正如您发现的那样,COS并不随NFS客户端库一起提供,因此GKE通过使用所需的二进制文件设置一个chroot(at/home/kubernetes/containerized_mounter/rootfs)并在其中调用mount来解决这个问题。我从kubernetes项目中获得了上面提到的解决方案@saad ali,以实现这一点 具体来说,我在云配置中添加了以下内容:
# 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
这很有效。难看极了,但现在只能这样了。Saad,感谢您解释了安装pod NFS卷的机制。“cos”上似乎存在DNS问题。如果我在定义持久卷时使用NFS服务器的IP地址,它会在上工作。我也有同样的问题,使用直接IP定义卷会工作,但使用DNS名称不会(尝试过的主机名、内部DNS名称以及公共DNS)。
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
# 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
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