5
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

k8sにflannelを適用した際に、CrashLoopBackOffを解消する

Posted at

背景

kubernetesクラスターを構築する際に、flannelのpodのステータがCrashLoopBackOffになる。

環境

  • kubeadm: v1.19.3
  • kubectl (client): v1.19.3
  • kubectl (server): v1.19.4

flannelのpod作成時、CrashLoopBackOffが発生

flannelインストール

以下、Kubernetesの公式よりFlannelをインストールします。本記事はMasterNodeのみ取り扱うこととします。
https://kubernetes.io/ja/docs/setup/production-environment/tools/kubeadm/create-cluster-kubeadm/

#kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/2140ac876ef134e0ed5af15c65e414cf26827915/Documentation/kube-flannel.yml
Warning: rbac.authorization.k8s.io/v1beta1 ClusterRole is deprecated in v1.17+, unavailable in v1.22+; use rbac.authorization.k8s.io/v1 ClusterRole
clusterrole.rbac.authorization.k8s.io/flannel created
Warning: rbac.authorization.k8s.io/v1beta1 ClusterRoleBinding is deprecated in v1.17+, unavailable in v1.22+; use rbac.authorization.k8s.io/v1 ClusterRoleBinding
clusterrolebinding.rbac.authorization.k8s.io/flannel created
serviceaccount/flannel created
configmap/kube-flannel-cfg created
daemonset.apps/kube-flannel-ds-amd64 created
daemonset.apps/kube-flannel-ds-arm64 created
daemonset.apps/kube-flannel-ds-arm created
daemonset.apps/kube-flannel-ds-ppc64le created
daemonset.apps/kube-flannel-ds-s390x created

CrashLoopBackOffの発生

kubectl get pods -n kube-systemより、Podのステータスを確認します。kube-flannel-ds-arm-vl44mCrashLoopBackOffになっています。

#kubectl get pods -n kube-system
NAME                            READY   STATUS             RESTARTS   AGE
coredns-f9fd979d6-kf625         1/1     Running            0          4m56s
coredns-f9fd979d6-pkmw9         1/1     Running            0          4m56s
etcd-ras01                      1/1     Running            0          5m3s
kube-apiserver-ras01            1/1     Running            0          5m3s
kube-controller-manager-ras01   1/1     Running            0          5m3s
kube-flannel-ds-arm-vl44m       0/1     CrashLoopBackOff   5          103s
kube-proxy-pzsnt                1/1     Running            0          4m56s
kube-scheduler-ras01            1/1     Running            0          5m3s

kube-flannel-ds-arm-vl44mのログを確認します。

# kubectl logs -n kube-system kube-flannel-ds-arm-vl44m
(省略)
E1115 07:34:55.457305       1 main.go:289] Error registering network: failed to configure interface flannel.1: failed to ensure address of interface flannel.1: link has incompatible addresses. Remove additional addresses and try again. &netlink.Vxlan{LinkAttrs:netlink.LinkAttrs{Index:11, MTU:1450, TxQLen:0, Name:"flannel.1", HardwareAddr:net.HardwareAddr{0xca, 0x45, 0x47, 0x6e, 0xa4, 0xb4}, Flags:0x13, RawFlags:0x11043, ParentIndex:0, MasterIndex:0, Namespace:interface {}(nil), Alias:"", Statistics:(*netlink.LinkStatistics)(0x12311104), Promisc:0, Xdp:(*netlink.LinkXdp)(0x1245c180), EncapType:"ether", Protinfo:(*netlink.Protinfo)(nil), OperState:0x0}, VxlanId:1, VtepDevIndex:2, SrcAddr:net.IP{0xc0, 0xa8, 0x64, 0x65}, Group:net.IP(nil), TTL:0, TOS:0, Learning:false, Proxy:false, RSC:false, L2miss:false, L3miss:false, UDPCSum:true, NoAge:false, GBP:false, Age:300, Limit:0, Port:8472, PortLow:0, PortHigh:0}
I1115 07:34:55.457461       1 main.go:366] Stopping shutdownHandler...

以下のエラーより、MasterNodeに互換性がないflannelのネットワークインタフェースが存在していて、それを削除する必要があります。

failed to ensure address of interface flannel.1: link has incompatible addresses. Remove additional addresses and try again.

ip link deleteよりネットワークインタフェースを削除

# ip a
(省略)
11: flannel.1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UNKNOWN group default
    link/ether ca:45:47:6e:a4:b4 brd ff:ff:ff:ff:ff:ff
    inet 10.244.0.0/32 scope global flannel.1
       valid_lft forever preferred_lft forever
    inet 169.254.93.182/16 brd 169.254.255.255 scope global noprefixroute flannel.1
       valid_lft forever preferred_lft forever
    inet6 fe80::81c5:8e58:5563:ca85/64 scope link
       valid_lft forever preferred_lft forever
# flannel.1を削除
# ip link delete flannel.1

Master nodeのflannelのネットワークインタフェースを削除した後、flannelのpodを削除して、podを再作成を行います。

# kubectl delete -n kube-system pods kube-flannel-ds-arm-vl44m
pod "kube-flannel-ds-arm-vl44m" deleted
# kubectl get pods -n kube-system
NAME                            READY   STATUS    RESTARTS   AGE
coredns-f9fd979d6-kf625         1/1     Running   0          18m
coredns-f9fd979d6-pkmw9         1/1     Running   0          18m
etcd-ras01                      1/1     Running   0          18m
kube-apiserver-ras01            1/1     Running   0          18m
kube-controller-manager-ras01   1/1     Running   0          18m
kube-flannel-ds-arm-4g42g       1/1     Running   0          10s
kube-proxy-pzsnt                1/1     Running   0          18m
kube-scheduler-ras01            1/1     Running   0          18m

flannelのpodが正常に作動していることがわかります。

所感

 kubernetes初心者が、クラスター構築の際に何度も作っては壊してを繰り返すと思います。その際に、幾度も生じるエラーだったので、本記事にまとめてみました。本記事では、MasterNodeのみ取り扱いましたが、各WorkerNodeでも同事象が起きた場合は、同様の対処でエラーを解消できるかと思います。

5
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?