初学K8s,好好教程不跟着来,非要全部安装最新的docker 和 k8s,经过4小时奋战终于解决!
先说明下docker是最新版的安装,又安装K8s
cat > /etc/yum.repos.d/kubernetes.repo <<EOF [kubernetes] name=Kubernetes baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64 enabled=1 gpgcheck=0 repo_gpgcheck=0 gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg EOF
yum install -y --nogpgcheck kubelet kubeadm kubectl systemctl enable kubelet
这样直接安装成功,得到 1.23.5-0,版本号就是v1.23.5
然后噩梦开始,视频教程人家指定了v1.19.0直接成功安装,我这倒好,报错开始
Initial timeout of 40s passed. [kubelet-check] It seems like the kubelet isn't running or healthy. [kubelet-check] The HTTP call equal to 'curl -sSL http://localhost:10248/healthz' failed with error: Get "http://localhost:10248/healthz": dial tcp [::1]:10248: connect: connection refused. [kubelet-check] It seems like the kubelet isn't running or healthy. .... This error is likely caused by: - The kubelet is not running - The kubelet is unhealthy due to a misconfiguration of the node in some way (required cgroups disabled)
报错如上,首先先把你之前查到的资料见鬼去,反正在我这是不好使的(我这里都是新版,2022-03-18新装的)
1、systemctl start kubelet 这个在只有【主】的时候根本起不来,所以不用折腾看状态了,有就行了
2、/etc/systemd/system/kubelet.service.d/10-kubeadm.conf 文件,我相信你一定查到了,为啥我没有,因为你的在这/usr/lib/systemd/system/kubelet.service.d/10-kubeadm.conf(这个你最好没改过,改过的话改回去,保持默认就好),上面那个文件就该没有的,连那个目录都不该有的(再次强调新版!旧版不知道,v1.23.5我这是),有文章让你新建并添加什么的,删了吧没用的,启动了也是假象
[root@k8s-master ~]# cd /etc/systemd/system/kubelet.service.d/ -bash: cd: /etc/systemd/system/kubelet.service.d/: 没有那个文件或目录
3、echo ‘{“exec-opts”: [“native.cgroupdriver=systemd”]}’ >> /etc/docker/daemon.json,我相信你已经见过这句了,是的!就是这句,这句真是重点!一开始我就对了,但是先往下看吧,真坑
4、还有让你们改docker images tag的,歇了吧,用不到的
开始噩梦安装之旅,注意这里我已经替换为国内的阿里源,所以根本不用改 docker Tag!只要能正常拉回来就没有问题!
kubeadm init \ --image-repository registry.aliyuncs.com/google_containers \ --kubernetes-version=v1.23.5 \ --pod-network-cidr=10.244.0.0/16 \ --service-cidr=10.96.0.0/12 \ --apiserver-advertise-address=192.168.0.2
重点来了
排错,这个也是重点,你知道是错在哪!【重点1】
journalctl -xeu kubelet | grep Failed
定位为毛线在失败(实际是一行,我换行下,这样好看)
3月 18 20:21:04 k8s-master kubelet[36490]: E0318 20:21:04.954990 36490 server.go:302] "Failed to run kubelet" err="failed to run Kubelet: misconfiguration: kubelet cgroup driver: \"systemd\" is different from docker cgroup driver: \"cgroupfs\""
实际你只要在你的/etc/docker/daemon.json 中加入 “exec-opts”: [“native.cgroupdriver=systemd”]
是加入!不是追加,追加的不管用!!!我就是被坑在这了!怕你搞错,看例子!【重点2】
1 { 2 "registry-mirrors": ["https://你的加速地址.mirror.aliyuncs.com"], 3 "log-driver": "json-file", 4 "log-opts": { 5 "max-size": "10m", 6 "max-file": "1" 7 }, 【看这!这加个逗号,下面加这句,结尾没有逗号】 8 "exec-opts": ["native.cgroupdriver=systemd"] 9 }
然后,你就可以
systemctl daemon-reload systemctl restart docker systemctl restart kubelet kubeadm reset #重置了没事的,反正之前也起不来~ y systemctl status kubelet #初始就是启动不了的 #验证cgroupdriver 修改生效 (这两行都是验证的)看到systemd 就对了 docker info -f {{.CgroupDriver}} docker info | grep -i cgroup
最后再执行
kubeadm init \ --image-repository registry.aliyuncs.com/google_containers \ --kubernetes-version=v1.23.5 \ --pod-network-cidr=10.244.0.0/16 \ --service-cidr=10.96.0.0/12 \ --apiserver-advertise-address=192.168.0.2
世界核平!
好了,万马奔腾~