在部署jenkins的时候,布完了通过外网能够访问,但是jenkins无法访问官网以加载插件,登录容器,发现Ping ip和域名都不通,于是判断是网络问题
去查看flannel,结果发现都寄了

root@iZ0jl23h85dco8du531om7Z ~]# kubectl get pods --all-namespaces
NAMESPACE      NAME                                              READY   STATUS             RESTARTS          AGE
devops-tools   jenkins-597c5679df-gxtzd                          1/1     Running            0                 3h47m
kube-flannel   kube-flannel-ds-p924c                             0/1     CrashLoopBackOff   650 (2m16s ago)   2d7h
kube-flannel   kube-flannel-ds-xvxns                             0/1     CrashLoopBackOff   50 (58s ago)      3h53m

查看flannel的日志

[root@iZ0jl23h85dco8du531om7Z ~]# kubectl logs pod/kube-flannel-ds-p924c -n kube-flannel
I0111 09:10:40.142875       1 main.go:204] CLI flags config: {etcdEndpoints:http://127.0.0.1:4001,http://127.0.0.1:2379 etcdPrefix:/coreos.com/network etcdKeyfile: etcdCertfile: etcdCAFile: etcdUsername: etcdPassword: version:false kubeSubnetMgr:true kubeApiUrl: kubeAnnotationPrefix:flannel.alpha.coreos.com kubeConfigFile: iface:[] ifaceRegex:[] ipMasq:true ifaceCanReach: subnetFile:/run/flannel/subnet.env publicIP: publicIPv6: subnetLeaseRenewMargin:60 healthzIP:0.0.0.0 healthzPort:0 iptablesResyncSeconds:5 iptablesForwardRules:true netConfPath:/etc/kube-flannel/net-conf.json setNodeNetworkUnavailable:true}
W0111 09:10:40.142952       1 client_config.go:617] Neither --kubeconfig nor --master was specified.  Using the inClusterConfig.  This might not work.
I0111 09:10:40.157983       1 kube.go:126] Waiting 10m0s for node controller to sync
I0111 09:10:40.158186       1 kube.go:431] Starting kube subnet manager
I0111 09:10:41.158774       1 kube.go:133] Node controller sync successful
I0111 09:10:41.158799       1 main.go:224] Created subnet manager: Kubernetes Subnet Manager - iz0jl23h85dco8du531om7z
I0111 09:10:41.158805       1 main.go:227] Installing signal handlers
I0111 09:10:41.158986       1 main.go:467] Found network config - Backend type: vxlan
I0111 09:10:41.159019       1 match.go:206] Determining IP address of default interface
I0111 09:10:41.159448       1 match.go:259] Using interface with name eth0 and address 172.30.254.89
I0111 09:10:41.159500       1 match.go:281] Defaulting external address to interface address (172.30.254.89)
I0111 09:10:41.159577       1 vxlan.go:138] VXLAN config: VNI=1 Port=0 GBP=false Learning=false DirectRouting=false
E0111 09:10:41.159891       1 main.go:327] Error registering network: failed to acquire lease: node "iz0jl23h85dco8du531om7z" pod cidr not assigned
I0111 09:10:41.159950       1 main.go:447] Stopping shutdownHandler...


[root@iZ0jl23h85dco8du531om7Z ~]# kubectl logs pod/kube-flannel-ds-xvxns -n kube-flannel
I0111 09:11:58.477079       1 main.go:204] CLI flags config: {etcdEndpoints:http://127.0.0.1:4001,http://127.0.0.1:2379 etcdPrefix:/coreos.com/network etcdKeyfile: etcdCertfile: etcdCAFile: etcdUsername: etcdPassword: version:false kubeSubnetMgr:true kubeApiUrl: kubeAnnotationPrefix:flannel.alpha.coreos.com kubeConfigFile: iface:[] ifaceRegex:[] ipMasq:true ifaceCanReach: subnetFile:/run/flannel/subnet.env publicIP: publicIPv6: subnetLeaseRenewMargin:60 healthzIP:0.0.0.0 healthzPort:0 iptablesResyncSeconds:5 iptablesForwardRules:true netConfPath:/etc/kube-flannel/net-conf.json setNodeNetworkUnavailable:true}
W0111 09:11:58.477143       1 client_config.go:617] Neither --kubeconfig nor --master was specified.  Using the inClusterConfig.  This might not work.
I0111 09:11:58.490684       1 kube.go:126] Waiting 10m0s for node controller to sync
I0111 09:11:58.490829       1 kube.go:431] Starting kube subnet manager
I0111 09:11:59.490979       1 kube.go:133] Node controller sync successful
I0111 09:11:59.491024       1 main.go:224] Created subnet manager: Kubernetes Subnet Manager - worker-node01
I0111 09:11:59.491039       1 main.go:227] Installing signal handlers
I0111 09:11:59.491118       1 main.go:467] Found network config - Backend type: vxlan
I0111 09:11:59.491139       1 match.go:206] Determining IP address of default interface
I0111 09:11:59.491491       1 match.go:259] Using interface with name eth0 and address 172.30.254.88
I0111 09:11:59.491512       1 match.go:281] Defaulting external address to interface address (172.30.254.88)
I0111 09:11:59.491574       1 vxlan.go:138] VXLAN config: VNI=1 Port=0 GBP=false Learning=false DirectRouting=false
E0111 09:11:59.491826       1 main.go:327] Error registering network: failed to acquire lease: node "worker-node01" pod cidr not assigned
W0111 09:11:59.491932       1 reflector.go:347] github.com/flannel-io/flannel/subnet/kube/kube.go:432: watch of *v1.Node ended with: an error on the server ("unable to decode an event from the watch stream: context canceled") has prevented the request from succeeding
I0111 09:11:59.492064       1 main.go:447] Stopping shutdownHandler...

谷歌一下 Error registering network: failed to acquire lease: node "worker-node01" pod cidr not assigned
查到这个帖子
https://www.talkwithtrend.com/Article/251751
解决方法

编辑 master 机器上的 /etc/kubernetes/manifests/kube-controller-manager.yaml
启动文件加上下面两句话,下面这个cluster-cidr要和kube-flannel.yml里面的地址一致,要和kube-proxy.config.yaml里面的clusterCIDR一致

- --allocate-node-cidrs=true
- --cluster-cidr=10.244.0.0/16

出现这个问题的原因是kubeadm初始化的时候没有指定cidr

标签: none

评论已关闭