天天看點

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模式。

繼續閱讀