如何找到 kube-proxy 是 运行 中的哪个模式

How to find which mode kube-proxy is running in

默认情况下,当配置中没有指定值时,kube-proxy 在 iptables 或用户空间模式下可能 运行:

--proxy-mode ProxyMode

Which proxy mode to use: 'userspace' (older) or 'iptables' (faster) or 'ipvs' or 'kernelspace' (windows). If blank, use the best-available proxy (currently iptables). If the iptables proxy is selected, regardless of how, but the system's kernel or iptables versions are insufficient, this always falls back to the userspace proxy.

doc

由于用户空间和 iptables 模式似乎都在节点上创建 iptables 规则,是否有任何可靠的方法来找出 kube-proxy 默认使用的代理模式?

kube-proxy 日志文件中提到了 kube-proxy 提出的模式。

W0322 08:09:44.312816       1 server_others.go:578] Unknown proxy mode "", assuming iptables proxy
I0322 08:09:44.313052       1 server_others.go:185] Using iptables Proxier.

签入代码https://github.com/kubernetes/kubernetes/blob/master/cmd/kube-proxy/app/server_others.go


func getProxyMode(proxyMode string, canUseIPVS bool, kcompat iptables.KernelCompatTester) string {
    switch proxyMode {
    case proxyModeUserspace:
        return proxyModeUserspace
    case proxyModeIPTables:
        return tryIPTablesProxy(kcompat)
    case proxyModeIPVS:
        return tryIPVSProxy(canUseIPVS, kcompat)
    }
    klog.Warningf("Unknown proxy mode %q, assuming iptables proxy", proxyMode)
    return tryIPTablesProxy(kcompat)
}

func tryIPTablesProxy(kcompat iptables.KernelCompatTester) string {
    // guaranteed false on error, error only necessary for debugging
    useIPTablesProxy, err := iptables.CanUseIPTablesProxier(kcompat)
    if err != nil {
        utilruntime.HandleError(fmt.Errorf("can't determine whether to use iptables proxy, using userspace proxier: %v", err))
        return proxyModeUserspace
    }
    if useIPTablesProxy {
        return proxyModeIPTables
    }
    // Fallback.
    klog.V(1).Infof("Can't use iptables proxy, using userspace proxier")
    return proxyModeUserspace
}