kube-proxy ipvs踩坑(一)

環境

  • Kubernetes version:
    v1.16.2

  • OS:
    NAME=“CentOS Linux”
    VERSION=“7 (Core)”
    ID=“centos”
    ID_LIKE=“rhel fedora”
    VERSION_ID=“7”
    PRETTY_NAME=“CentOS Linux 7 (Core)”
    ANSI_COLOR=“0;31”
    CPE_NAME=“cpe:/o:centos:centos:7”
    HOME_URL=“https://www.centos.org/”
    BUG_REPORT_URL=“https://bugs.centos.org/”

    CENTOS_MANTISBT_PROJECT=“CentOS-7”
    CENTOS_MANTISBT_PROJECT_VERSION=“7”
    REDHAT_SUPPORT_PRODUCT=“centos”
    REDHAT_SUPPORT_PRODUCT_VERSION=“7”

  • 部署方式
    kubeadm

操作以及遇到的問題

kubeadm正常的部署完成之後,由於我沒有設置proxy的mode, 所以kube-proxy會在啓動的時候自行的去判斷到底使用哪種模式,kube-proxy支持的模式有三種

  • user-space,
  • iptabels,
  • ipvs

每種類型的詳細介紹,請參考官網kube-proxy mode,所以在啓動的時候默認是iptabels模式,集羣正常起來後,我想更改爲ipvs模式,所以我只需要更改對於的啓動參數:proxy-mode=ipvs即可,但是在更改完成之後,kube-proxy daemonset新建的pod還是使用iptables模式,其中錯誤種有錯誤信息提示找不到:ip_vs, ip_vs_rr, ip_vs_wrr, ip_vs_sh模塊,但是我主機上是已經正常的安裝了對應得ipvs需要的這幾個模塊(在主機上未使用modprobe加載對應ipvs模塊),並且通過掛在宿主機的/lib/modules 到容器中的/lib/modules。而且在kube-proxy的代碼,在判斷能否使用ipvs模塊的時候,明確的調用了modprobe – [ip_vs, ip_vs_rr, ip_vs_wrr, ip_vs_sh]去加載了,但是始終會報錯,找不到對應的ipvs模塊。錯誤信息如下

1121 10:21:08.420967       1 proxier.go:597] Failed to load kernel module ip_vs_rr with modprobe. You can ignore this message when kube-proxy is running inside container without mounting /lib/modules, err: exit status 1,out:modprobe: ERROR: could not insert 'ip_vs_rr': Exec format error
W1121 10:21:08.421825       1 proxier.go:597] Failed to load kernel module ip_vs_wrr with modprobe. You can ignore this message when kube-proxy is running inside container without mounting /lib/modules, err: exit status 1,out:modprobe: ERROR: could not insert 'ip_vs_wrr': Exec format error
W1121 10:21:08.422624       1 proxier.go:597] Failed to load kernel module ip_vs_sh with modprobe. You can ignore this message when kube-proxy is running inside container without mounting /lib/modules, err: exit status 1,out:modprobe: ERROR: could not insert 'ip_vs_sh': Exec format error
E1121 10:21:08.423949       1 server_others.go:339] can't determine whether to use ipvs proxy, error: IPVS proxier will not be used because the following required kernel modules are not loaded: [ip_vs ip_vs_rr ip_vs_wrr ip_vs_sh]

後面的詳細錯誤error是我自己編譯代碼種加的信息,原來的方法是調用cmd.run,只返回錯誤,只有exit status 1,沒有詳細的錯誤信息,所以我更改了他的方法,調用cmd.CompileOutPut方法。獲取詳細的錯誤信息。看了相關部分的proxy的代碼邏輯,邏輯是沒有任何問題的,檢查ipvs模塊的順序如下:

  • /lib/modules/$(uname -a)/modules.builtin
  • modprobe – [ip_vs, ip_vs_rr, ip_vs_wrr, ip_vs_sh]
  • /proc/modules

最後,我手動的在主機上去執行modprobe – [ip_vs, ip_vs_rr, ip_vs_wrr, ip_vs_sh] 然後刪除掉就的kube-proxy pod,然後查看日誌,正常使用ipvs模式。

總結:

當使用容器部署kube-proxy的時候,使用ipvs模式,需要在宿主機上手動的去吧所有的ipvs模塊都掛載到內核種去。否則kube-proxy在啓動的時候,如果配置爲ipvs模式,在去檢查掛載ipvs以及其依賴模的時候不會成功,從而導致使用ipvs模式失敗,轉而使用iptabels模式。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章