启动时常见错误修复

ERROR Swap

完整错误:

[ERROR Swap]: running with swap on is not supported. Please disable swap

解决方案: 关闭 swap, 执行: swapoff -a

ERROR FileContent--proc-sys-net-bridge-bridge-nf-call-iptables

完整错误:

[ERROR FileContent--proc-sys-net-bridge-bridge-nf-call-iptables]

解决方案: 执行 echo 1 > /proc/sys/net/bridge/bridge-nf-call-iptables

ERROR FileContent--proc-sys-net-ipv4-ip_forward

完整错误:

[ERROR FileContent--proc-sys-net-ipv4-ip_forward]

解决方案: 执行 echo 1 > /proc/sys/net/ipv4/ip_forward

ERROR Service-Docker

完整错误

[ERROR Service-Docker]
[ERROR CRI]
[ERROR SystemVerification]: failed to parse kernel config: unable to load kernel module: "configs", output: "modprobe: FATAL: Module configs not found.\n", err: exit status 1
[WARNING Service-Docker]: docker service is not enabled, please run 'systemctl enable docker.service'

解决方案: 启动 Docker, 并设置其开机自启

  • 启动 Docker: systemctl start docker
  • 开机启动 Docker: systemctl enable docker

ERROR DirAvailable--var-lib-etcd

完整错误

[ERROR DirAvailable--var-lib-etcd]: /var/lib/etcd is not empty

解决方案: 删除文件夹, 执行 rm -rf /var/lib/etcd

ERROR FileAvailable--etc-kubernetes-manifests-kube-xxx.yaml

完整错误

[ERROR FileAvailable--etc-kubernetes-manifests-kube-xxx.yaml]

其中 xxx 为具体文件名称

比如:

[ERROR FileAvailable--etc-kubernetes-manifests-kube-apiserver.yaml]: /etc/kubernetes/manifests/kube-apiserver.yaml already exists
[ERROR FileAvailable--etc-kubernetes-manifests-kube-controller-manager.yaml]: /etc/kubernetes/manifests/kube-controller-manager.yaml already exists
[ERROR FileAvailable--etc-kubernetes-manifests-kube-scheduler.yaml]: /etc/kubernetes/manifests/kube-scheduler.yaml already exists
[ERROR FileAvailable--etc-kubernetes-manifests-etcd.yaml]: /etc/kubernetes/manifests/etcd.yaml already exists

解决方案: 删除文件夹: rm -rf /etc/kubernetes/manifests

ERROR NumCPU

完整错误:

[ERROR NumCPU]: the number of available CPUs 1 is less than the required 2

将虚拟机 CPU 增加至 2 核以上

WARNING Firewalld

完整错误

[WARNING Firewalld]: firewalld is active, please ensure ports [6443 10250] are open or your cluster may not function correctly

解决方案: 直接关闭防火墙, 执行 systemctl stop firewalld

WARNING Hostname

完整错误

[WARNING Hostname]: hostname "k8s-master" could not be reached
[WARNING Hostname]: hostname "k8s-master": lookup k8s-master on 192.168.126.2:53: no such host

解决方案:

  1. /etc/hosts 中映射本机域名, 比如 127.0.0.1 k8s-master
  2. 修改本机名称 vim /etc/hostname

WARNING Service-Kubelet

完整错误

[WARNING Service-Kubelet]: kubelet service is not enabled, please run 'systemctl enable kubelet.service'

解决方案: 开机启动 kubelet, 执行 systemctl enable kubelet.service

WARNING IsDockerSystemdCheck

完整错误

[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/
$ vim /etc/docker/daemon.json
{
 "exec-opts":["native.cgroupdriver=systemd"]
}
$ systemctl restart docker

ERROR ImagePull

各种拉取镜像出错, 一般是由于 GFW 的缘故, 解决方案是换源拉取相关镜像, 再重新取 tag

注: 本人使用的是 Kubernetes v1.14.2 版本, 错误详情中会指出需要哪些镜像, 将镜像改为自己对应的镜像版本即可

可以创建一个 pull-images.sh 脚本:

$ touch pull-images.sh && chmod 744 pull-images.sh && vim pull-images.sh
# 从阿里云拉取容器
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.14.2
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.14.2
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.14.2
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.14.2
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.3.10
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.3.1
# 将阿里云拉取的容器打标签
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.14.2 k8s.gcr.io/kube-apiserver:v1.14.2
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.14.2 k8s.gcr.io/kube-controller-manager:v1.14.2
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.14.2 k8s.gcr.io/kube-scheduler:v1.14.2
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.14.2 k8s.gcr.io/kube-proxy:v1.14.2
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1 k8s.gcr.io/pause:3.1
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.3.10 k8s.gcr.io/etcd:3.3.10
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.3.1 k8s.gcr.io/coredns:1.3.1
# 删除阿里云拉取的容器
docker rmi registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.14.2
docker rmi registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.14.2
docker rmi registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.14.2
docker rmi registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.14.2
docker rmi registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1
docker rmi registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.3.10
docker rmi registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.3.1

以上操作的目的是: 先从国内可访问的阿里镜像源中拉取相关的镜像, 然后修改其 tag, 使其骗过 docker 已经拉取了官方镜像。

ERROR Port-10250

[ERROR Port-10250]: Port 10250 is in use

kubeadm 会自动检查当前环境是否有上次命令执行的“残留”。如果有,必须清理后再行执行 init。我们可以通过 kubeadm reset 来清理环境,以备重来。

其实, 上面我们提到的很多问题都可以使用 kubeadm reset 来解决, 比如 ERROR DirAvailable--var-lib-etcdERROR FileAvailable--etc-kubernetes-manifests-kube-xxx.yaml 等。

MIT Licensed | Copyright © 2018-present 滇ICP备16006294号

Design by Quanzaiyu | Power by VuePress