Kubernetes集羣中flannel因網卡名啓動失敗問題

Kubernetes集羣中flannel因網卡名啓動失敗問題

[TOC]html

1. 問題

個人環境是使用kubeadm安裝的kubernetes1.11,flannel網絡。今天新加入一節點到k8s中,發現新節點的守護容器kube-flannel-ds啓動失敗。node

到該節點中使用docker logs xxxxx查看,日誌報錯以下:docker

I0815 00:25:37.646559       1 main.go:201] Could not find valid interface matching ens32: error looking up interface ens32: route ip+net: no such network interface
E0815 00:25:37.646628       1 main.go:225] Failed to find interface to use that matches the interfaces and/or regexes provided

2. 解決過程

由於是flannel容器報錯,那就找到建立flannel網絡時使用的yaml配置,發現以下段的影響:express

containers:
      - name: kube-flannel
        image: registry.cn-shanghai.aliyuncs.com/gcr-k8s/flannel:v0.10.0-amd64
        command:
        - /opt/bin/flanneld
        args:
        - --ip-masq
        - --kube-subnet-mgr
        - --iface=ens32

上面只有名爲ens32的網卡名才支持。由於我新節點網卡名爲eth0,因此怎麼才能兼容各類網卡名呢?上面顯示這個是由命令flanneld控制的,那就進入正常的kube-flannel-ds容器,查看命令幫助。api

/opt/bin/flanneld --help
Usage: /opt/bin/flanneld [OPTION]...
  -etcd-cafile string
        SSL Certificate Authority file used to secure etcd communication
  -etcd-certfile string
        SSL certification file used to secure etcd communication
  -etcd-endpoints string
        a comma-delimited list of etcd endpoints (default "http://127.0.0.1:4001,http://127.0.0.1:2379")
  -etcd-keyfile string
        SSL key file used to secure etcd communication
  -etcd-password string
        password for BasicAuth to etcd
  -etcd-prefix string
        etcd prefix (default "/coreos.com/network")
  -etcd-username string
        username for BasicAuth to etcd
  -healthz-ip string
        the IP address for healthz server to listen (default "0.0.0.0")
  -healthz-port int
        the port for healthz server to listen(0 to disable)
  -iface value
        interface to use (IP or name) for inter-host communication. Can be specified multiple times to check each option in order. Returns the first match found.
  -iface-regex value
        regex expression to match the first interface to use (IP or name) for inter-host communication. Can be specified multiple times to check each regex in order. Returns the first match found. Regexes are checked after specific interfaces specified by the iface option have already been checked.
  -ip-masq
        setup IP masquerade rule for traffic destined outside of overlay network
  -kube-api-url string
        Kubernetes API server URL. Does not need to be specified if flannel is running in a pod.
  -kube-subnet-mgr
        contact the Kubernetes API for subnet assignment instead of etcd.
  -kubeconfig-file string
        kubeconfig file location. Does not need to be specified if flannel is running in a pod.
  -log_backtrace_at value
        when logging hits line file:N, emit a stack trace
  -public-ip string
        IP accessible by other nodes for inter-host communication
  -subnet-file string
        filename where env variables (subnet, MTU, ... ) will be written to (default "/run/flannel/subnet.env")
  -subnet-lease-renew-margin int
        subnet lease renewal margin, in minutes, ranging from 1 to 1439 (default 60)
  -v value
        log level for V logs
  -version
        print version and exit
  -vmodule value
        comma-separated list of pattern=N settings for file-filtered logging

咱們能夠看到,-iface value-iface-regex value能夠指定網卡。爲了兼容2種網卡yaml配置中這段我修改爲了網絡

containers:
      - name: kube-flannel
        image: registry.cn-shanghai.aliyuncs.com/gcr-k8s/flannel:v0.10.0-amd64
        command:
        - /opt/bin/flanneld
        args:
        - --ip-masq
        - --kube-subnet-mgr
        - --iface=ens32
        - --iface=eth0
        #- --iface-regex=eth*|ens*

問題解決。若是有多網卡網絡,flannel最好是指定通訊網卡,越精確越好,不然不指定它則使用默認路由的網卡通訊。ide

參考資料:
[1] https://coreos.com/flannel/docs/latest/flannel-config.htmlurl

相關文章
相關標籤/搜索