[英]Can I run k8s master INSIDE a docker container? Getting errors about k8s looking for host's kernel details
在 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
因為(我認為)我的容器沒有預期的 kernel header 文件。
我意識到容器根據運行容器的主機報告其 kernel ; 並查看我看到的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 的最簡單方法是什么,以至於它一直通過這個獲取 kernel 信息。
我注意到在 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 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 在容器中運行良好。 真正的問題是奇怪/誤導性的日志。 我添加了一個答案來澄清。
鑒於容器的性質,我認為這是不可能的。
您應該改為在 docker 容器中測試您的應用程序,然后使用 minikube 在雲中或本地將該映像部署到 k8s。
另一種解決方案是在使用 docker 驅動程序而不是 VirtualBox 的種類下運行它
致命錯誤部分似乎有點誤導。
它被我的測試環境嚴重格式化(全部在一條線上。當 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 有時會部分超時.
添加此答案以防其他人像我一樣感到困惑。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.