初始化 kubeadm 时出现错误。
$: -sudo kubeadm init
[init] Using Kubernetes version: v1.25.0
[preflight] Running pre-flight checks
[WARNING SystemVerification]: missing optional cgroups: blkio
error execution phase preflight: [preflight] Some fatal errors occurred:
[ERROR FileContent--proc-sys-net-ipv4-ip_forward]: /proc/sys/net/ipv4/ip_forward contents are not set to 1
[preflight] If you know what you are doing, you can make a check non-fatal with `--ignore-preflight-errors=...`
To see the stack trace of this error execute with --v=5 or higher
为了解决这个问题,我首先:
sudo rm /etc/containerd/config.toml
sudo systemctl restart containerd
kubeadm init
第二:我编辑了 config.toml 文件并更改了 systemd_cgroup = true
然后我尝试
sudo kubeadm init --v=5
I0824 10:32:04.093515 27017 initconfiguration.go:116] detected and using CRI socket: unix:///var/run/containerd/containerd.sock
I0824 10:32:04.093872 27017 interface.go:432] Looking for default routes with IPv4 addresses
I0824 10:32:04.093890 27017 interface.go:437] Default route transits interface "eth0"
I0824 10:32:04.094018 27017 interface.go:209] Interface eth0 is up
I0824 10:32:04.094084 27017 interface.go:257] Interface "eth0" has 2 addresses :[172.31.37.138/20 fe80::69:d1ff:fea7:79ae/64].
I0824 10:32:04.094113 27017 interface.go:224] Checking addr 172.31.37.138/20.
I0824 10:32:04.094131 27017 interface.go:231] IP found 172.31.37.138
I0824 10:32:04.094147 27017 interface.go:263] Found valid IPv4 address 172.31.37.138 for interface "eth0".
I0824 10:32:04.094162 27017 interface.go:443] Found active IP 172.31.37.138
I0824 10:32:04.094197 27017 kubelet.go:196] the value of KubeletConfiguration.cgroupDriver is empty; setting it to "systemd"
I0824 10:32:04.098681 27017 version.go:187] fetching Kubernetes version from URL: https://dl.k8s.io/release/stable-1.txt
[init] Using Kubernetes version: v1.25.0
[preflight] Running pre-flight checks
I0824 10:32:04.770260 27017 checks.go:568] validating Kubernetes and kubeadm version
I0824 10:32:04.770328 27017 checks.go:168] validating if the firewall is enabled and active
I0824 10:32:04.779958 27017 checks.go:203] validating availability of port 6443
I0824 10:32:04.780157 27017 checks.go:203] validating availability of port 10259
I0824 10:32:04.780197 27017 checks.go:203] validating availability of port 10257
I0824 10:32:04.780232 27017 checks.go:280] validating the existence of file /etc/kubernetes/manifests/kube-apiserver.yaml
I0824 10:32:04.780251 27017 checks.go:280] validating the existence of file /etc/kubernetes/manifests/kube-controller-manager.yaml
I0824 10:32:04.780265 27017 checks.go:280] validating the existence of file /etc/kubernetes/manifests/kube-scheduler.yaml
I0824 10:32:04.780278 27017 checks.go:280] validating the existence of file /etc/kubernetes/manifests/etcd.yaml
I0824 10:32:04.780293 27017 checks.go:430] validating if the connectivity type is via proxy or direct
I0824 10:32:04.780317 27017 checks.go:469] validating http connectivity to first IP address in the CIDR
I0824 10:32:04.780341 27017 checks.go:469] validating http connectivity to first IP address in the CIDR
I0824 10:32:04.780353 27017 checks.go:104] validating the container runtime
I0824 10:32:04.794206 27017 checks.go:329] validating the contents of file /proc/sys/net/bridge/bridge-nf-call-iptables
I0824 10:32:04.794285 27017 checks.go:329] validating the contents of file /proc/sys/net/ipv4/ip_forward
I0824 10:32:04.794384 27017 checks.go:644] validating whether swap is enabled or not
I0824 10:32:04.794436 27017 checks.go:370] validating the presence of executable crictl
I0824 10:32:04.794466 27017 checks.go:370] validating the presence of executable conntrack
I0824 10:32:04.794486 27017 checks.go:370] validating the presence of executable ip
I0824 10:32:04.794506 27017 checks.go:370] validating the presence of executable iptables
I0824 10:32:04.794530 27017 checks.go:370] validating the presence of executable mount
I0824 10:32:04.794552 27017 checks.go:370] validating the presence of executable nsenter
I0824 10:32:04.794571 27017 checks.go:370] validating the presence of executable ebtables
I0824 10:32:04.794591 27017 checks.go:370] validating the presence of executable ethtool
I0824 10:32:04.794608 27017 checks.go:370] validating the presence of executable socat
I0824 10:32:04.794629 27017 checks.go:370] validating the presence of executable tc
I0824 10:32:04.794646 27017 checks.go:370] validating the presence of executable touch
I0824 10:32:04.794666 27017 checks.go:516] running all checks
[WARNING SystemVerification]: missing optional cgroups: blkio
I0824 10:32:04.808265 27017 checks.go:401] checking whether the given node name is valid and reachable using net.LookupHost
I0824 10:32:04.808291 27017 checks.go:610] validating kubelet version
I0824 10:32:04.871023 27017 checks.go:130] validating if the "kubelet" service is enabled and active
I0824 10:32:04.906852 27017 checks.go:203] validating availability of port 10250
I0824 10:32:04.907135 27017 checks.go:203] validating availability of port 2379
I0824 10:32:04.907346 27017 checks.go:203] validating availability of port 2380
I0824 10:32:04.907542 27017 checks.go:243] validating the existence and emptiness of directory /var/lib/etcd
[preflight] Some fatal errors occurred:
[ERROR FileContent--proc-sys-net-ipv4-ip_forward]: /proc/sys/net/ipv4/ip_forward contents are not set to 1
[preflight] If you know what you are doing, you can make a check non-fatal with `--ignore-preflight-errors=...`
error execution phase preflight
k8s.io/kubernetes/cmd/kubeadm/app/cmd/phases/workflow.(*Runner).Run.func1
cmd/kubeadm/app/cmd/phases/workflow/runner.go:235
k8s.io/kubernetes/cmd/kubeadm/app/cmd/phases/workflow.(*Runner).visitAll
cmd/kubeadm/app/cmd/phases/workflow/runner.go:421
k8s.io/kubernetes/cmd/kubeadm/app/cmd/phases/workflow.(*Runner).Run
cmd/kubeadm/app/cmd/phases/workflow/runner.go:207
k8s.io/kubernetes/cmd/kubeadm/app/cmd.newCmdInit.func1
cmd/kubeadm/app/cmd/init.go:154
github.com/spf13/cobra.(*Command).execute
vendor/github.com/spf13/cobra/command.go:856
github.com/spf13/cobra.(*Command).ExecuteC
vendor/github.com/spf13/cobra/command.go:974
github.com/spf13/cobra.(*Command).Execute
vendor/github.com/spf13/cobra/command.go:902
k8s.io/kubernetes/cmd/kubeadm/app.Run
cmd/kubeadm/app/kubeadm.go:50
main.main
cmd/kubeadm/kubeadm.go:25
runtime.main
/usr/local/go/src/runtime/proc.go:250
runtime.goexit
/usr/local/go/src/runtime/asm_amd64.s:1594
收到错误信息:
service kubelet status
kubelet.service - kubelet: The Kubernetes Node Agent
Loaded: loaded (/lib/systemd/system/kubelet.service; enabled; vendor preset: enabled)
Drop-In: /etc/systemd/system/kubelet.service.d
└─10-kubeadm.conf
Active: activating (auto-restart) (Result: exit-code) since Wed 2022-08-24 14:56:42 UTC; 6s ago
Docs: https://kubernetes.io/docs/home/
Process: 2561 ExecStart=/usr/bin/kubelet $KUBELET_KUBECONFIG_ARGS $KUBELET_CONFIG_ARGS $KUBELET_KUBEADM_ARGS $KUBELET_EXTRA_ARGS (code=exited, status=1/FAILURE)
Main PID: 2561 (code=exited, status=1/FAILURE)
答案1
您需要确保 kubernetes 可以进行 IPv4 转发。这是假设您使用iptables
和 而不是ipvs
。运行以下脚本添加网桥(用于 IPv4 和 IPv6 以及 IP 转发):
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.ipv4.ip_forward = 1
EOF
另外,请关闭交换,打开覆盖网络和桥接网络过滤器,例如:
cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
overlay
br_netfilter
EOF
sudo modprobe overlay
sudo modprobe br_netfilter
# immediately turn off swap - until reboot
sudo swapoff -a
# turn off swap after restart
sudo sed -i 's|^/swap.img|#/swap.img|g' /etc/fstab
# reboot sysctl
sudo sysctl --system
答案2
打开 # nano /etc/containerd/config.toml
做评论#disabled_plugins = ["cri"]
然后,执行 sudo systemctl restart containerd
然后执行 kubeadm init