【问题标题】:Can I run k8s master INSIDE a docker container? Getting errors about k8s looking for host's kernel details我可以在 docker 容器内运行 k8s master 吗?获取有关 k8s 查找主机内核详细信息的错误
【发布时间】: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


【解决方案1】:

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

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

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

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

【讨论】:

  • 谢谢,直到现在我还不知道kind。它看起来很有希望,我现在试图了解在我的 molecule 测试中运行容器时是否应该使用它的基础镜像而不是“标准”Linux 镜像
  • 这真的取决于您的“分子测试”的依赖关系,我通常从 alpine 应用程序映像开始,但您可能希望使用基于操作系统的映像。
【解决方案2】:

FATAL 错误部分似乎有点误导。

我的测试环境格式错误(全部在一行中。 当 k8s 失败时,我看到了 FATAL 并假设(错误地)这是根本原因。

当我很好地格式化日志时,我看到...

kubeadm join 172.17.0.2:6443 --token 21e8ab.1e1666a25fd37338 --discovery-token-unsafe-skip-ca-verification --experimental-control-plane --ignore-preflight-errors=all --node-name 172.17.0.3
[preflight] Running pre-flight checks
    [WARNING FileContent--proc-sys-net-bridge-bridge-nf-call-iptables]: /proc/sys/net/bridge/bridge-nf-call-iptables does not exist
[preflight] The system verification failed. Printing the output from the verification:
KERNEL_VERSION: 4.4.0-142-generic
DOCKER_VERSION: 18.09.3
OS: Linux
CGROUPS_CPU: enabled
CGROUPS_CPUACCT: enabled
CGROUPS_CPUSET: enabled
CGROUPS_DEVICES: enabled
CGROUPS_FREEZER: enabled
CGROUPS_MEMORY: enabled
    [WARNING SystemVerification]: this Docker version is not on the list of validated versions: 18.09.3. Latest validated version: 18.06
    [WARNING SystemVerification]: failed to parse kernel config: unable to load kernel module: "configs", output: "modprobe: ERROR: ../libkmod/libkmod.c:586 kmod_search_moddep() could not open moddep file '/lib/modules/4.4.0-142-generic/modules.dep.bin'\nmodprobe: FATAL: Module configs not found in directory /lib/modules/4.4.0-142-generic\n", err: exit status 1
[discovery] Trying to connect to API Server "172.17.0.2:6443"
[discovery] Created cluster-info discovery client, requesting info from "https://172.17.0.2:6443"



[discovery] Failed to request cluster info, will try again: [the server was unable to return a response in the time allotted, but may still be processing the request (get configmaps cluster-info)]

后来还有其他错误,我最初认为这是令人讨厌的致命错误的副作用,例如.... "[util/etcd] Attempt timed out"]} 但我现在认为根本原因是 Etcd 有时会超时。

添加此答案以防其他人像我一样感到困惑。

【讨论】:

    猜你喜欢
    • 2015-07-05
    • 1970-01-01
    • 2018-06-14
    • 2019-06-17
    • 2019-04-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多