使用 kubeadm 在 CentOS 7 搭建 Kubernetes 集群(8)

执行 kubeadm init ... 时,卡在了 [apiclient] Created API client, waiting for the control plane to become ready 不继续执行了,通过 journalctl -xeu kubelet 查看日志得到报错信息:

... error: failed to run Kubelet: failed to create kubelet: misconfiguration: kubelet cgroup driver: "cgroupfs" is different from docker cgroup driver: "systemd"

原因是 kubelet 的 cgroup 驱动跟 docker 不一致,解决方案是选择一种驱动,将二者改成一致。

方式一:

$ vim /etc/systemd/system/kubelet.service.d/10-kubeadm.conf Environment="KUBELET_CGROUP_ARGS=--cgroup-driver=systemd" $ systemctl daemon-reload $ systemctl restart kubelet

方式二:

$ vim /lib/systemd/system/docker.service 将 --exec-opt native.cgroupdriver=systemd 修改为:--exec-opt native.cgroupdriver=cgroupfs $ systemctl daemon-reload $ systemctl restart docker.service

执行 kubeadm init ... 完成之后,使用 kubectl ... 命令时,提示如下信息:

The connection to the server localhost:8080 was refused - did you specify the right host or port?

原因是没有设置 KUBECONFIG,执行如下两种方式均可:

方式一: sudo cp /etc/kubernetes/admin.conf $HOME/ sudo chown $(id -u):$(id -g) $HOME/admin.conf export KUBECONFIG=$HOME/admin.conf 方式二: export KUBECONFIG=/etc/kubernetes/admin.conf source ~/.bash_profile

安装完 Flannel 网络组件之后,发现 pod kube-flannel 的状态为 CrashLoopBackOff,执行命令查看日志,提示如下信息:

Error from server (BadRequest): a container name must be specified for pod kube-flannel-ds-hl9xd, choose one of: [kube-flannel install-cni]

出现这个是因为 pod kube-flannel 启动了两个容器 kube-flannel 和 install-cni,查看日志时需要指定查看那个容器,可通过命令 -c <container_name> 指定,例如: kubectl logs -f pods/kube-flannel-ds-vkdzw -c install-cni -n kube-system。通过命令可以看到报错信息如下:

+ cp -f /etc/kube-flannel/cni-conf.json /etc/cni/net.d/10-flannel.conf cp: can't create '/etc/cni/net.d/10-flannel.conf': Permission denied

这个是因为容器跟主机文件系统有交互操作,需要关闭 SELinux,执行如下命令即可:

$ setenforce 0 $ systemctl daemon-reload

Dashboard 集成 Heapster 插件时,执行完 $ kubectl create -f deploy/kube-config/influxdb/ 操作后,发现 pod heapster 状态非 Running,通过日志可以看到如下报错信息:

... E1027 07:36:16.951175 1 reflector.go:190] k8s.io/heapster/metrics/heapster.go:322: Failed to list *v1.Pod: User "system:serviceaccount:kube-system:heapster" cannot list pods at the cluster scope. (get pods) E1027 07:39:18.383356 1 reflector.go:190] k8s.io/heapster/metrics/processors/namespace_based_enricher.go:84: Failed to list *v1.Namespace: User "system:serviceaccount:kube-system:heapster" cannot list namespaces at the cluster scope. (get namespaces) ...

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/ccf09e871e52b67aa2845e9bffbb28ef.html