首页 > 解决方案 > 我可以在 docker 容器内运行 k8s master 吗?获取有关 k8s 查找主机内核详细信息的错误

问题描述

在 docker 容器中,我想运行 k8s。

当我运行kubeadm join ...kubeadm init命令时,我有时会看到错误,例如

\"modprobe: 错误: ../libkmod/libkmod.c:586 kmod_search_moddep() 无法打开 moddep 文件 '/lib/modules/3.10.0-1062.1.2.el7.x86_64/modules.dep.bin'。nmodprobe :
致命:在目录 /lib/modules/3.10.0-1062.1.2.el7.x86_64" 中找不到模块配置,错误:退出状态 1

因为(我认为)我的容器没有预期的内核头文件。

我意识到容器根据运行容器的主机报告其内核;并查看 我看到的k8s 代码

// getKernelConfigReader search kernel config file in a predefined list. Once the kernel config
// file is found it will read the configurations into a byte buffer and return. If the kernel
// config file is not found, it will try to load kernel config module and retry again.
func (k *KernelValidator) getKernelConfigReader() (io.Reader, error) {
    possibePaths := []string{
        "/proc/config.gz",
        "/boot/config-" + k.kernelRelease,
        "/usr/src/linux-" + k.kernelRelease + "/.config",
        "/usr/src/linux/.config",
    }

所以我有点困惑在容器中运行 k8s 的最简单方法是什么,以便它始终通过获取内核信息。

我注意到docker run -it solita/centos-systemd:7 /bin/bash在我看到的 macOS 主机上运行:

# uname -r
4.9.184-linuxkit
# ls -l /proc/config.gz 
-r--r--r-- 1 root root 23834 Nov 20 16:40 /proc/config.gz

但在我看到的 Ubuntu VM 上运行完全相同:

#  uname -r
4.4.0-142-generic
# ls -l /proc/config.gz 
ls: cannot access /proc/config.gz

[奇怪的是我不是FATAL: Module configs not found in directory每次都看到这个错误,但我想这是一个单独的问题!]

2019 年 11 月 22 日更新。我现在看到 k8s 在容器中运行良好。真正的问题是奇怪/误导性的日志。我添加了一个答案来澄清。

标签: dockerkubernetes

解决方案


鉴于容器的性质,我认为这是不可能的。

相反,您应该在 docker 容器中测试您的应用程序,然后将该映像部署到云端或本地使用 minikube 的 k8s。

另一种解决方案是在使用 docker 驱动程序而不是 VirtualBox 的种类下运行它

https://kind.sigs.k8s.io/docs/user/quick-start/


推荐阅读