【发布时间】:2020-03-16 10:31:26
【问题描述】:
我想在 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 code我明白了
// 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 的最简单方法是什么,以便它始终如一地通过此获取内核信息。
我注意到在我看到的 macOS 主机上运行 docker run -it solita/centos-systemd:7 /bin/bash:
# 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 虚拟机上运行完全相同:
# 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 在容器中运行良好。真正的问题是奇怪/误导性的日志。我添加了一个答案来澄清。
【问题讨论】:
-
您是否有任何具体原因要在 Docker 容器中部署 Kubernetes 主服务器?您想在 Docker 容器或其他物理机中部署工作节点吗?
-
@DawidKruk 这仅用于测试目的。我有一个 ansible-molecule 设置,允许我测试 ansible 安装,并且我想确保我可以一致且正确地安装多主 k8s 集群。我不会在生产环境中使用这些容器来运行 k8s。
-
@DawidKruk 我查看了 KIND github.com/kubernetes-sigs/kind/blob/master/images/base/… 中的 docker 容器,正如 thepilot 的回答所提到的,但它看起来有点复杂,我不清楚 docker 中的 k8s 需要添加哪些内容。跨度>
标签: docker kubernetes