错误一:coredns的状态是pending
原因1:master上的flannel镜像拉取失败,导致获取不到解析的IP
解决方法:
[root@master ~]# kubectl delete -f kube-flannel.yml #先删除安装的CNI插件
[root@master ~]# docker load --input flannel-0.11.0-amd64.tar #导入镜像
[root@master ~]# kubectl apply -f kube-flannel.yml #再次安装
[root@master ~]# kubectl get pods -n kube-system -o wide
原因2:没有本地解析,所以coredns才是pending
[root@master ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
解决方法:本地解析
[root@master ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.13.141 master
192.168.13.142 node1
192.168.13.143 node2
错误二:集群测试pod状态pending
[root@master ~]# kubectl get pods -n kube-system -o wide 查看状态
原因:发现两个node节点上的flannel镜像自动拉取失败
解决方法:我们需要去手动导入镜像
[root@node1 ~]# docker load --input flannel-0.11.0-amd64.tar
7bff100f35cb: Loading layer [==================================================>] 4.672MB/4.672MB
5d3f68f6da8f: Loading layer [==================================================>] 9.526MB/9.526MB
9b48060f404d: Loading layer [==================================================>] 5.912MB/5.912MB
3f3a4ce2b719: Loading layer [==================================================>] 35.25MB/35.25MB
9ce0bb155166: Loading layer [==================================================>] 5.12kB/5.12kB
Loaded image: quay.io/coreos/flannel:v0.11.0-amd64
[root@node2 ~]# docker load --input flannel-0.11.0-amd64.tar
7bff100f35cb: Loading layer [==================================================>] 4.672MB/4.672MB
5d3f68f6da8f: Loading layer [==================================================>] 9.526MB/9.526MB
9b48060f404d: Loading layer [==================================================>] 5.912MB/5.912MB
3f3a4ce2b719: Loading layer [==================================================>] 35.25MB/35.25MB
9ce0bb155166: Loading layer [==================================================>] 5.12kB/5.12kB
Loaded image: quay.io/coreos/flannel:v0.11.0-amd64
然后删除pod重新进行集群测试
[root@master ~]# kubectl get deployment
NAME READY UP-TO-DATE AVAILABLE AGE
nginx 0/1 1 0 16m
[root@master ~]# kubectl delete deployment nginx #删除
deployment.extensions "nginx" deleted
[root@master ~]# kubectl get pods -n kube-system -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
coredns-8686dcc4fd-p56rf 1/1 Running 0 36m 10.244.0.3 master <none> <none>
coredns-8686dcc4fd-qnhjv 1/1 Running 0 36m 10.244.0.2 master <none> <none>
etcd-master 1/1 Running 0 35m 192.168.13.141 master <none> <none>
kube-apiserver-master 1/1 Running 0 35m 192.168.13.141 master <none> <none>
kube-controller-manager-master 1/1 Running 0 35m 192.168.13.141 master <none> <none>
kube-flannel-ds-amd64-j9mlk 1/1 Running 0 25m 192.168.13.141 master <none> <none>
kube-flannel-ds-amd64-p89mh 1/1 Running 0 19m 192.168.13.143 node2 <none> <none>
kube-flannel-ds-amd64-rsln6 1/1 Running 0 19m 192.168.13.142 node1 <none> <none>
kube-proxy-2pfmm 1/1 Running 0 36m 192.168.13.141 master <none> <none>
kube-proxy-tmd2c 1/1 Running 0 19m 192.168.13.142 node1 <none> <none>
kube-proxy-tvn54 1/1 Running 0 19m 192.168.13.143 node2 <none> <none>
kube-scheduler-master 1/1 Running 0 35m 192.168.13.141 master <none> <none>
[root@master ~]# kubectl get pod,svc
NAME READY STATUS RESTARTS AGE
pod/nginx-5f965696dd-2wcfn 1/1 Running 0 2m52s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.1.0.1 <none> 443/TCP 39m
service/nginx NodePort 10.1.113.89 <none> 80:32439/TCP 21m
此时pod状态就是Running了
[root@master ~]# curl 192.168.13.142:32439 #访问页面也是能成功
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>