一、报错信息如下

[root@master ~]# kubeadm init \
> --apiserver-advertise-address=192.168.153.144 \
> --image-repository registry.aliyuncs.com/google_containers \
> --service-cidr=10.1.0.0/16 \
> --pod-network-cidr=10.244.0.0/16

W0512 19:52:12.388569 8202 version.go:103] could not fetch a Kubernetes version from the internet: unable to get URL “https://dl.k8s.io/release/stable-1.txt”: Get “https://dl.k8s.io/release/stable-1.txt”: context deadline exceeded (Client.Timeout exceeded while awaiting headers)
W0512 19:52:12.388656 8202 version.go:104] falling back to the local client version: v1.24.0
[init] Using Kubernetes version: v1.24.0
[preflight] Running pre-flight checks
[WARNING Service-Kubelet]: kubelet service is not enabled, please run 'systemctl enable kubelet.service’kubelet未开启
error execution phase preflight: [preflight] Some fatal errors occurred:
[ERROR CRI]: container runtime is not running: output: time=“2022-05-12T19:52:12+08:00” level=fatal msg=“getting status of runtime: rpc error: code = Unimplemented desc = unknown service runtime.v1alpha2.RuntimeService”
, error: exit status 1
[ERROR FileContent–proc-sys-net-bridge-bridge-nf-call-iptables]: /proc/sys/net/bridge/bridge-nf-call-iptables 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

二、查看报错信息可知安装完K8s组件时,kubelet未设置开机自启

#设置开机自启,kubelet是K8s在node节点上的代理,必须开机运行
systemctl enable  kubelet.service

三、还是报错,信息如下

[root@master ~]# kubeadm init --apiserver-advertise-address=192.168.153.144 --image-repository registry.aliyuncs.com/google_containers --service-cidr=10.1.0.0/16 --pod-network-cidr=10.244.0.0/16

W0512 19:56:08.781216 8244 version.go:103] could not fetch a Kubernetes version from the internet: unable to get URL “https://dl.k8s.io/release/stable-1.txt”: Get “https://dl.k8s.io/release/stable-1.txt”: context deadline exceeded (Client.Timeout exceeded while awaiting headers)
W0512 19:56:08.781296 8244 version.go:104] falling back to the local client version: v1.24.0
[init] Using Kubernetes version: v1.24.0
[preflight] Running pre-flight checks
error execution phase preflight: [preflight] Some fatal errors occurred:
[ERROR CRI]: container runtime is not running: output: time=“2022-05-12T19:56:08+08:00” level=fatal msg=“getting status of runtime: rpc error: code = Unimplemented desc = unknown service runtime.v1alpha2.RuntimeService”
, error: exit status 1
[ERROR FileContent–proc-sys-net-bridge-bridge-nf-call-iptables]: /proc/sys/net/bridge/bridge-nf-call-iptables 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

无法从互联网获取Kubernetes版本:无法获取URL“https://dl.k8s.io/release/stable-1.txt”:获取“https://dl.k8s.io/release/stable-1.txt”:上下文截止日期超过(客户端。等待报头时超时)

四、解决方法

#提前准备coredns:1.8.4的镜像,后面需要使用,需要在每台机器上下载镜像
#不提前拉取的话,初始化的时候会报错!!!
#默认在谷歌上拉取,我们改为国内地址
[root@master ~]# docker pull  coredns/coredns:1.8.4
[root@master ~]# docker tag coredns/coredns:1.8.4 registry.aliyuncs.com/google_containers/coredns:v1.8.4

五、还是报错,不急这次一定能解决

[root@master ~]# kubeadm init \
> --apiserver-advertise-address=192.168.153.144 \
> --image-repository registry.aliyuncs.com/google_containers \
> --service-cidr=10.1.0.0/16 \
> --pod-network-cidr=10.244.0.0/16

[init] Using Kubernetes version: v1.24.0
[preflight] Running pre-flight checks
error execution phase preflight: [preflight] Some fatal errors occurred:
[ERROR CRI]: container runtime is not running: output: time=“2022-05-12T20:18:23+08:00” level=fatal msg=“getting status of runtime: rpc error: code = Unimplemented desc = unknown service runtime.v1alpha2.RuntimeService”
, error: exit status 1
[ERROR FileContent–proc-sys-net-bridge-bridge-nf-call-iptables]: /proc/sys/net/bridge/bridge-nf-call-iptables 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

六、最后一次,一定解决

echo 1 >/proc/sys/net/bridge/bridge-nf-call-iptables

终于初始化成功!!!
在这里插入图片描述

Logo

华为云1024程序员节送福利,参与活动赢单人4000元礼包,更有热门技术干货免费学习

更多推荐