kubeadm初始化kubernetes报错以及解决
Posted 江神神神神
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了kubeadm初始化kubernetes报错以及解决相关的知识,希望对你有一定的参考价值。
1、报错
[root@master ~]# kubeadm init --kubernetes-version=v1.21.0 --pod-network-cidr=172.16.0.0/16 --service-cidr=172.18.0.0/16
[init] Using Kubernetes version: v1.21.0
[preflight] Running pre-flight checks
[WARNING IsDockerSystemdCheck]: detected "cgroupfs" as the Docker cgroup driver. The recommended driver is "systemd". Please follow the guide at https://kubernetes.io/docs/setup/cri/
[WARNING Hostname]: hostname "master" could not be reached
[WARNING Hostname]: hostname "master": lookup master on 172.16.0.2:53: no such host
error execution phase preflight: [preflight] Some fatal errors occurred:
[ERROR NumCPU]: the number of available CPUs 1 is less than the required 2
[ERROR Swap]: running with swap on is not supported. Please disable swap
[ERROR KubeletVersion]: the kubelet version is higher than the control plane version. This is not a supported version skew and may lead to a malfunctional cluster. Kubelet version: "1.22.2" Control plane version: "1.21.0"
[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
2、解决方法
错误一:
[WARNING IsDockerSystemdCheck]: detected "cgroupfs" as the Docker cgroup driver. The recommended driver is "systemd". Please follow the guide at https://kubernetes.io/docs/setup/cri/
解决方法:"exec-opts": ["native.cgroupdriver=systemd"]
加入下面一行
[root@master ~]# vim /etc/docker/daemon.json
"registry-mirrors": ["https://q2hy3fzi.mirror.aliyuncs.com"],
"exec-opts": ["native.cgroupdriver=systemd"]
}
错误二:
[WARNING Hostname]: hostname "master" could not be reached
解决方法:
所有节点修改host文件
[root@master ~]# vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
172.16.128.12 master
172.16.128.0 node1
172.16.128.13 node2
错误三:
[ERROR NumCPU]: the number of available CPUs 1 is less than the required 2
解决方法:
其一: 虚拟机话,可以提升虚拟机的cpu资源
其二: 忽视这条告警错误,加上 --ignore-preflight-errors=all 参数即可。
错误四:
[ERROR Swap]: running with swap on is not supported. Please disable swap
解决方法:
关闭swap并且修改fstab文件
[root@master ~]# swapoff -a
[root@master ~]# vim /etc/fstab
# /etc/fstab
# Created by anaconda on Thu Sep 23 17:45:45 2021
# Accessible filesystems, by reference, are maintained under \'/dev/disk\'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=be2920b0-9460-45c5-ab99-25f875fe44ce / xfs defaults 0 0
UUID=5b946178-29ba-4e71-80fa-168971ee2d3f /boot xfs defaults 0 0
UUID=ebbb0118-c740-4025-87a2-ed4e073d2b03 /data ext4 defaults 1 2
#UUID=fcb0ec3c-731d-44a6-86dd-ae284fe407ac swap swap defaults 0 0
错误五:
[ERROR KubeletVersion]: the kubelet version is higher than the control plane version.
解决方法:
忽略这条报错,这是因为kubelet版本太新导致的
[root@master ~]# vim /etc/sysconfig/kubelet
KUBELET_EXTRA_ARGS="--fail-swap-on=false"
3、kubeadm初始化kubernetes
[root@master ~]# kubeadm init --kubernetes-version=v1.21.0 --pod-network-cidr=172.16.0.0/16 --service-cidr=172.18.0.0/16 --ignore-preflight-errors=all
以上是关于kubeadm初始化kubernetes报错以及解决的主要内容,如果未能解决你的问题,请参考以下文章
关于使用kubeadm reset命令对kubeadm init与kubeadm join操作后遇到报错的情况-进行恢复还原