💨

flannelをデプロイすると「Error registering network: failed to acquire lease」が出る

2025/01/19に公開

エラー内容

E0119 10:10:25.747676       1 main.go:359] Error registering network: failed to acquire lease: subnet "10.244.0.0/16" specified in the flannel net config doesn't contain "172.17.1.0/24" PodCIDR of the "k8s-worker-1" node

エラー全文

root@k8s-manager:~# kubectl logs -f kube-flannel-ds-mjbdf
error: error from server (NotFound): pods "kube-flannel-ds-mjbdf" not found in namespace "default"
root@k8s-manager:~# kubectl logs -n kube-flannel kube-flannel-ds-mjbdf
Defaulted container "kube-flannel" out of: kube-flannel, install-cni-plugin (init), install-cni (init)
I0119 10:10:24.704308       1 main.go:211] 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}
W0119 10:10:24.704428       1 client_config.go:618] Neither --kubeconfig nor --master was specified.  Using the inClusterConfig.  This might not work.
I0119 10:10:24.731484       1 kube.go:139] Waiting 10m0s for node controller to sync
I0119 10:10:24.731585       1 kube.go:469] Starting kube subnet manager
I0119 10:10:24.737007       1 kube.go:490] Creating the node lease for IPv4. This is the n.Spec.PodCIDRs: [172.17.0.0/24]
I0119 10:10:24.737335       1 kube.go:490] Creating the node lease for IPv4. This is the n.Spec.PodCIDRs: [172.17.1.0/24]
I0119 10:10:24.737368       1 kube.go:490] Creating the node lease for IPv4. This is the n.Spec.PodCIDRs: [172.17.2.0/24]
I0119 10:10:25.731853       1 kube.go:146] Node controller sync successful
I0119 10:10:25.731924       1 main.go:231] Created subnet manager: Kubernetes Subnet Manager - k8s-worker-1
I0119 10:10:25.731943       1 main.go:234] Installing signal handlers
I0119 10:10:25.732252       1 main.go:468] Found network config - Backend type: vxlan
I0119 10:10:25.738834       1 kube.go:669] List of node(k8s-worker-1) annotations: map[string]string{"flannel.alpha.coreos.com/backend-data":"{\"VNI\":1,\"VtepMAC\":\"f2:27:d5:18:97:8b\"}", "flannel.alpha.coreos.com/backend-type":"vxlan", "flannel.alpha.coreos.com/kube-subnet-manager":"true", "flannel.alpha.coreos.com/public-ip":"192.168.1.33", "kubeadm.alpha.kubernetes.io/cri-socket":"unix:///var/run/containerd/containerd.sock", "node.alpha.kubernetes.io/ttl":"0", "projectcalico.org/IPv4Address":"192.168.1.33/24", "projectcalico.org/IPv4IPIPTunnelAddr":"172.17.230.0", "volumes.kubernetes.io/controller-managed-attach-detach":"true"}
I0119 10:10:25.738963       1 match.go:211] Determining IP address of default interface
I0119 10:10:25.740844       1 match.go:264] Using interface with name ens18 and address 192.168.1.33
I0119 10:10:25.740900       1 match.go:286] Defaulting external address to interface address (192.168.1.33)
I0119 10:10:25.741026       1 vxlan.go:141] VXLAN config: VNI=1 Port=0 GBP=false Learning=false DirectRouting=false
I0119 10:10:25.746627       1 kube.go:636] List of node(k8s-worker-1) annotations: map[string]string{"flannel.alpha.coreos.com/backend-data":"{\"VNI\":1,\"VtepMAC\":\"f2:27:d5:18:97:8b\"}", "flannel.alpha.coreos.com/backend-type":"vxlan", "flannel.alpha.coreos.com/kube-subnet-manager":"true", "flannel.alpha.coreos.com/public-ip":"192.168.1.33", "kubeadm.alpha.kubernetes.io/cri-socket":"unix:///var/run/containerd/containerd.sock", "node.alpha.kubernetes.io/ttl":"0", "projectcalico.org/IPv4Address":"192.168.1.33/24", "projectcalico.org/IPv4IPIPTunnelAddr":"172.17.230.0", "volumes.kubernetes.io/controller-managed-attach-detach":"true"}
I0119 10:10:25.746714       1 vxlan.go:155] Interface flannel.1 mac address set to: f2:27:d5:18:97:8b
E0119 10:10:25.747676       1 main.go:359] Error registering network: failed to acquire lease: subnet "10.244.0.0/16" specified in the flannel net config doesn't contain "172.17.1.0/24" PodCIDR of the "k8s-worker-1" node
I0119 10:10:25.747763       1 main.go:448] Stopping shutdownHandler...

kubeadmでクラスタ作成したときには、--pod-network-cidr=172.17.0.0/16を指定して作っていた。

kubeadm init --control-plane-endpoint=192.168.1.31 --apiserver-advertise-address=192.168.1.32 --pod-network-cidr=172.17.0.0/16 --cri-socket=unix:///run/containerd/containerd.sock

以下コマンドでデプロイをしていると思う(またはhelm chart)

kubectl apply -f https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml

対応策

エラー内容としては、172.17.1.0/24に含まれないというようなエラーなので含むように変えてあげればいいはず。

yamlファイルを以下のように変えて再度デプロイした。

  net-conf.json: |
    {
      "Network": "172.17.0.0/16",
      "EnableNFTables": false,
      "Backend": {
        "Type": "vxlan"
      }
    }

起動した

root@k8s-manager:~# kubectl get pod -n kube-flannel
NAME                    READY   STATUS    RESTARTS   AGE
kube-flannel-ds-dbdvv   1/1     Running   0          22s
kube-flannel-ds-f897p   1/1     Running   0          22s
kube-flannel-ds-w4xnw   1/1     Running   0          22s

Discussion