node加入的时候出现这个错误:
Failed to connect to API Server "192.168.31.197:6443": Get https://192.168.31.197:6443/api/v1/namespaces/kube-public/configmaps/cluster-info?timeout=10s: dial tcp 192.168.31.197:6443: connect: no route to host
是因为telnet的问题(首先排除下是不是因为token过期的问题,再来看是不是telnet的问题,也就是iptables建立一个防火墙)
解决方案:
$ sudo iptables -L INPUT --line-numbers
找到关于:
11 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
这一条,然后我们这条删除掉就好了
$ sudo iptables -D INPUT 11//注意这个11,就是你的line-numbers
然后,如果遇到你的kubelet起不来的话,
首先:
$ systemctl status kubelet.service
● kubelet.service - kubelet: The Kubernetes Node Agent
Loaded: loaded (/lib/systemd/system/kubelet.service; enabled; vendor preset: enabled)
Drop-In: /etc/systemd/system/kubelet.service.d
└─10-kubeadm.conf
Active: activating (auto-restart)(Result: exit-code) since 四 2020-11-26 19:33:31 CST; 5s ago
Docs: https://kubernetes.io/docs/home/
Process: 20503ExecStart=/usr/bin/kubelet (code=exited, status=255)
Main PID: 20503(code=exited, status=255)11月 2619:33:31 node-virtual-machine systemd[1]: kubelet.service: Unit entered failed state.
11月 2619:33:31 node-virtual-machine systemd[1]: kubelet.service: Failed with result 'exit-code'.
Warning: kubelet.service changed on disk. Run 'systemctl daemon-reload' to reload units.
node@node-virtual-machine:~$ cd /etc/systemd/system/kubelet.service.d/
然后可以用:journalctl -f -u kubelet.service//进行详细的观察错误详情
如果发现了这个错误:
failed to run Kubelet: failed to create kubelet: misconfiguration: kubelet cgroup driver: "cgroupfs" is different from docker cgroup driver: "systemd"
那么第一步:
1./etc/systemd/system/kubelet.service.d/10-kubeadm.conf
查看这个10-kubeadm.conf存不存在,如果不存在,那么直接创建一个:内容是
# Note: This dropin only works with kubeadm and kubelet v1.11+[Service]Environment="KUBELET_KUBECONFIG_ARGS=--bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf"Environment="KUBELET_CONFIG_ARGS=--config=/var/lib/kubelet/config.yaml"# This is a file that "kubeadm init" and "kubeadm join" generates at runtime, populating the KUBELET_KUBEADM_ARGS variable dynamicallyEnvironmentFile=-/var/lib/kubelet/kubeadm-flags.env
# This is a file that the user can use for overrides of the kubelet args as a last resort. Preferably, the user should use# the .NodeRegistration.KubeletExtraArgs object in the configuration files instead. KUBELET_EXTRA_ARGS should be sourced from this file.EnvironmentFile=-/etc/default/kubelet
ExecStart=ExecStart=/usr/bin/kubelet $KUBELET_KUBECONFIG_ARGS$KUBELET_CONFIG_ARGS$KUBELET_KUBEADM_ARGS$KUBELET_EXTRA_ARGS
然后剩下的就是:
kubectl join了
如果这个时候报错,那么就在:
/var/lib/kubelet/下
创建kubeadm-flags.env文件
内容是:
KUBELET_KUBEADM_ARGS="--cgroup-driver=systemd --network-plugin=cni –pod-infra-container-image=k8s.gcr.io/pause:3.1"
那么这样就解决了