kubeadm 初始化遇到问题总结

操作系统:ubuntu 18.04.3 server(虚拟机)

用户:root

宿主机:macOS Catalina

kubernetes版本:1.16.1

docker版本:18.09.7

 

在使用kubeadm init命令遇到了一些问题

1.[WARNING IsDockerSystemdCheck]: detected "cgroupfs" as the Docker cgroup driver.

解决办法:在/etc/docker的daemon.json文件中添加配置,文件不存在则新建一个

{"exec-opts":["native.cgroupdriver=systemd"]}

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

意思是运行时不支持swap分区,需要禁用swap。

我记得已经用命令

swapoff -a

关掉了swap,但还是提示这个。

使用命令

free

查看内存使用情况,发现还在使用swap分区

解决办法:修改fstab分区配置,把swap的分区注释

编辑fstab

vi /etc/fstab

注释swap分区,保存,重启

查看内存使用情况

 

3. [ERROR SystemVerification]: failed executing "docker info --format '{{json .}}'"\noutput: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

意思是连不上 docker daemon,。我也是记得刚配置过了docker的deamon.json文件并执行。

systemctl daemon-reload
systemctl restart docker

 

 

看这问题,大概是解析json内容出错。

回过头一想,是不是daemon.json哪里写错了。仔细检查,发现是少了个逗号。

解决办法:每个键值对要用逗号隔开

kubeadm 初始化遇到问题总结_第1张图片

 

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

解决办法:删除 /var/lib/etcd 下的文件

 

5.

error execution phase preflight: [preflight] Some fatal errors occurred:
    [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

解决办法:重置kubeadm

命令

kubeadm reset

6.在执行kubeadm reset时候报错

Unmounting mounted directories in "/var/lib/kubelet"
W1017 10:24:37.615881   38550 cleanupnode.go:81] [reset] Failed to remove containers: [failed to remove running container 11c904cc28f9: output: Error response from daemon: Could not kill running container 11c904cc28f91b0b79c88b8c68acdf6d213f3bf7708b4735749bc74fd93499b0, cannot remove - Cannot kill container 11c904cc28f91b0b79c88b8c68acdf6d213f3bf7708b4735749bc74fd93499b0: unknown error after kill: runc did not terminate sucessfully: container_linux.go:388: signaling init process caused "permission denied"
: unknown

看起来是reset时候要把container干掉然后移除 ,然后没权限。

我发现手动 docker stop 也报这个权限问题。可是我用的是root,按理说应该不会这样。

在Stack Overflow上找到解决方法,

参考资料AppArmor,AppArmor GitHub

大概是因为AppAmor会拒绝源于AppAmor Porfile之外的信号。

解决办法:使用命令

aa-remove-unknown

命令解释

 aa-remove-unknown will inventory all profiles in /etc/apparmor.d/, compare that list to
       the profiles currently loaded into the kernel, and then remove all of the loaded profiles
       that were not found in /etc/apparmor.d/. It will also report the name of each profile that
       it removes on standard out.

7.Unable to fetch the kubeadm-config ConfigMap from cluster: failed to get config map: Get https://192.168.138.131:6443/api/v1/namespaces/kube-system/configmaps/kubeadm-config: dial tcp 192.168.138.131:6443: i/o timeout

解决办法:kubeadm init时候 apiserver-advertise-address的ip地址写错了,本机作为master节点,也作为apiserver,本机ip是

192.168.139.131,应该把这个ip填入。

kubeadm init --apiserver-advertise-address 192.168.139.131 --pod-network-cidr=10.244.0.0/16 --image-repository registry.aliyuncs.com/google_containers --kubernetes-version v1.16.1

 

你可能感兴趣的:(k8s,kubernetes,kubeadm)