部署服务时镜像拉取过程中出现:ImagePullBackOff
kubectl describe pods kubernetes-dashboard-975499656-krwl7 -n kube-system
查看pod的详细情况
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 4m38s default-scheduler Successfully assigned kube-system/kubernetes-dashboard-975499656-krwl7 to k8s-node2
Normal Pulling 2m32s (x4 over 4m38s) kubelet, k8s-node2 Pulling image "k8s.gcr.io/kubernetes-dashboard-amd64:v1.10.1"
Warning Failed 2m16s (x4 over 4m22s) kubelet, k8s-node2 Failed to pull image "k8s.gcr.io/kubernetes-dashboard-amd64:v1.10.1": rpc error: code = Unknown desc = Error response from daemon: Get https://k8s.gcr.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
Warning Failed 2m16s (x4 over 4m22s) kubelet, k8s-node2 Error: ErrImagePull
Normal BackOff 112s (x6 over 4m22s) kubelet, k8s-node2 Back-off pulling image "k8s.gcr.io/kubernetes-dashboard-amd64:v1.10.1"
Warning Failed 99s (x7 over 4m22s) kubelet, k8s-node2 Error: ImagePullBackOff
分析:这个拉取的国外的镜像源,是有点慢,网络不好的时候经常会出现这种情况,可以提前把需要的镜像下载好
解决办法:
更换国内镜像源,搜索需要下载的镜像
①编辑文件 /etc/docker/daemon.json 加入"registry-mirrors":["https://docker.mirrors.ustc.edu.cn"]
重载配置文件重启docker生效
systemctl daemon-reload
systemctl restart docker
②搜索需要的镜像,如:k8s.gcr.io/kubernetes-dashboard-amd64:v1.10.1
③拉取指定镜像
④tag为配置文件中需要的镜像名k8s.gcr.io/kubernetes-dashboard-amd64:v1.10.1
docker tag loveone/kubernetes-dashboard-amd64:v1.10.1 k8s.gcr.io/kubernetes-dashboard-amd64:v1.10.1
完成后再试一次(注意最好每个节点都做这样的操作,因为调度器随机选择节点部署,简而言之是在被部署的节点上操作)
重新部署
①kubectl delete -f kubernetes-dashboard.yaml
,
②kubectl apply -f kubernetes-dashboard.yaml
或者 kubectl create -f kubernetes-dashboard.yaml --save-config
出现如下报错
kubectl logs kubernetes-dashboard-975499656-xlx5b -n kube-system
- 查看pod日志如下
Error from server: Get https://192.168.40.131:10250/containerLogs/kube-system/kubernetes-dashboard-975499656-xlx5b/kubernetes-dashboard: dial tcp 192.168.40.131:10250: connect: no route to host - 分析:由此可见,部署服务时访问节点131的10250端口连接被拒绝,推测可能是防火墙的原因
- 解决办法:
①查看服务端口是否被占用,!是否已经启起来了;
可以看到,端口启动正常;
②telnet测试一下端口(我这里是master机器上测试的)
果然不通
③查看节点1的防火墙状态
果然是防火墙的原因
再试端口就通了
重新部署试试
成功