Docker 采集器目录映射赢得linux 内核的UnionFs,UnionFs 会形成一层cache 目录,去把容器中的文件,联合挂载到本机文件里,比如说

           "Data": {
                "LowerDir": "/var/lib/docker/overlay2/7b6f5149ec9f25d688fc28a2d9c5ec3ff7ef67132982ce22a21b36770bb70ecb-init/diff:/var/lib/docker/overlay2/be20468ee80699be5df23e99126693a6c275899080753717f7fddf611a37be89/diff:/var/lib/docker/overlay2/fdd64e328eacd51bf4d921f9e87e8d1ae8bfb24b05df1e0271c8b4b283dc2e46/diff:/var/lib/docker/overlay2/d1016c270238242f619bc6f2f7afd2c2bdfc5b72f8997d1be16b9cc151a92ff5/diff:/var/lib/docker/overlay2/d0cffa88ce2d8bf45bdb5274341f818fd77a825dec914d8eb63ab7ad088f8a06/diff:/var/lib/docker/overlay2/99202031d190473d1cbfbab7f44184bda5b8d28eb3e17d13aa94f2734c61c558/diff:/var/lib/docker/overlay2/5efeef14dd632f83976db0396f3d918140de0bd3e099d1e06f8debc84032d173/diff:/var/lib/docker/overlay2/dae540b717650f0f246fe68b38f5060dd22590e0d7593427650826d61dd60ed8/diff",
                "MergedDir": "/var/lib/docker/overlay2/7b6f5149ec9f25d688fc28a2d9c5ec3ff7ef67132982ce22a21b36770bb70ecb/merged",
                "UpperDir": "/var/lib/docker/overlay2/7b6f5149ec9f25d688fc28a2d9c5ec3ff7ef67132982ce22a21b36770bb70ecb/diff",
                "WorkDir": "/var/lib/docker/overlay2/7b6f5149ec9f25d688fc28a2d9c5ec3ff7ef67132982ce22a21b36770bb70ecb/work"
            },

但是当我去采集容器内日志的时候发现nfs 文件并没有,nfs 文件挂载位置在

/var/lib/kubelet/pods/86963ebc-aa4a-4256-98e8-7ee5c608ba9d/volumes/kubernetes.io~nfs/mydir

这个目录并不在UnionFs 路径下,于是我看K8s 源码

pkg/volume/nfs/nfs.go下面

func getPath(uid types.UID, volName string, host volume.VolumeHost) string {
	return host.GetPodVolumeDir(uid, utilstrings.EscapeQualifiedName(nfsPluginName), volName)
}

mount 具体模块:


func (nfsMounter *nfsMounter) SetUpAt(dir string, mounterArgs volume.MounterArgs) error {
	notMnt, err := mount.IsNotMountPoint(nfsMounter.mounter, dir)
	klog.V(4).Infof("NFS mount set up: %s %v %v", dir, !notMnt, err)
	if err != nil && !os.IsNotExist(err) {
		return err
	}
	if !notMnt {
		return nil
	}
	if err := os.MkdirAll(dir, 0750); err != nil {
		return err
	}
	source := fmt.Sprintf("%s:%s", nfsMounter.server, nfsMounter.exportPath)
	options := []string{}
	if nfsMounter.readOnly {
		options = append(options, "ro")
	}
	mountOptions := util.JoinMountOptions(nfsMounter.mountOptions, options)
	err = nfsMounter.mounter.MountSensitiveWithoutSystemd(source, dir, "nfs", mountOptions, nil)
	if err != nil {
		notMnt, mntErr := mount.IsNotMountPoint(nfsMounter.mounter, dir)
		if mntErr != nil {
			klog.Errorf("IsNotMountPoint check failed: %v", mntErr)
			return err
		}
		if !notMnt {
			if mntErr = nfsMounter.mounter.Unmount(dir); mntErr != nil {
				klog.Errorf("Failed to unmount: %v", mntErr)
				return err
			}
			notMnt, mntErr := mount.IsNotMountPoint(nfsMounter.mounter, dir)
			if mntErr != nil {
				klog.Errorf("IsNotMountPoint check failed: %v", mntErr)
				return err
			}
			if !notMnt {
				// This is very odd, we don't expect it.  We'll try again next sync loop.
				klog.Errorf("%s is still mounted, despite call to unmount().  Will try again next sync loop.", dir)
				return err
			}
		}
		os.Remove(dir)
		return err
	}
	return nil
}

nfs 是作为一个单独模块运行的,与hostpath 不一样,所以说需要去

var/lib/kubelet/pods/86963ebc-aa4a-4256-98e8-7ee5c608ba9d/volumes/kubernetes.io~nfs/

下面去采集

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐