Change:
What happened: Currently kube-proxy cleanup not work, which will left iptables (and ipvs) rules in host and. What you expected to happen: Kube-proxy cleanup can work and not relay on hostName or ClientConnection config. How to reproduce it (as minimally and precisely as possible):
/sig network /assign
/triage unresolved Comment when the issue is assessed and confirmed. I am a bot run by vllry. ‍
If this issue has been triaged, please comment . If you aren't able to handle this issue, consider unassigning yourself and/or adding the label. I am a bot run by vllry. ‍

Discussion:
return 0, nil } <del> // CleanupAndExit remove iptables rules and exit if success return nil </del> <ins> // CleanupAndExit remove iptables rules and ipset/ipvs rules in ipvs proxy mode // and exit if success return nil </ins> func (s *ProxyServer) CleanupAndExit() error { <del> encounteredError := userspace.CleanupLeftovers(s.IptInterface) encounteredError = iptables.CleanupLeftovers(s.IptInterface) || encounteredError encounteredError = ipvs.CleanupLeftovers(s.IpvsInterface, s.IptInterface, s.IpsetInterface, s.CleanupIPVS) || encounteredError </del> <ins> // cleanup IPv6 and IPv4 iptables rules ipts := []utiliptables.Interface{ utiliptables.New(s.execer, utiliptables.ProtocolIPv4), utiliptables.New(s.execer, utiliptables.ProtocolIPv6), } var encounteredError bool for _, ipt := range ipts { encounteredError = userspace.CleanupLeftovers(ipt) || encounteredError encounteredError = iptables.CleanupLeftovers(ipt) || encounteredError encounteredError = ipvs.CleanupLeftovers(s.IpvsInterface, ipt, s.IpsetInterface, s.CleanupIPVS) || encounteredError } </ins> if encounteredError { return errors.New("encountered an error while tearing down rules") }

return nil, fmt.Errorf("unable to register configz: %s", err) } <del> hostname, err := utilnode.GetHostname(config.HostnameOverride) if err != nil { return nil, err } client, eventClient, err := createClients(config.ClientConnection, master) if err != nil { return nil, err } nodeIP := detectNodeIP(client, hostname, config.BindAddress) protocol := utiliptables.ProtocolIPv4 if utilsnet.IsIPv6(nodeIP) { klog.V(0).Infof("kube-proxy node IP is an IPv6 address (%s), assume IPv6 operation", nodeIP.String()) protocol = utiliptables.ProtocolIPv6 } else { klog.V(0).Infof("kube-proxy node IP is an IPv4 address (%s), assume IPv4 operation", nodeIP.String()) } </del> var iptInterface utiliptables.Interface var ipvsInterface utilipvs.Interface var kernelHandler ipvs.KernelHandler

// Create a iptables utils. execer := exec.New() <del> iptInterface = utiliptables.New(execer, protocol) </del> kernelHandler = ipvs.NewLinuxKernelHandler() ipsetInterface = utilipset.New(execer) canUseIPVS, err := ipvs.CanUseIPVSProxier(kernelHandler, ipsetInterface)

if cleanupAndExit { return &ProxyServer{ execer:         execer, <del> IptInterface:   iptInterface, </del> IpvsInterface:  ipvsInterface, IpsetInterface: ipsetInterface, }, nil

metrics.SetShowHidden() } <ins> hostname, err := utilnode.GetHostname(config.HostnameOverride) if err != nil { return nil, err } client, eventClient, err := createClients(config.ClientConnection, master) if err != nil { return nil, err } nodeIP := detectNodeIP(client, hostname, config.BindAddress) protocol := utiliptables.ProtocolIPv4 if utilsnet.IsIPv6(nodeIP) { klog.V(0).Infof("kube-proxy node IP is an IPv6 address (%s), assume IPv6 operation", nodeIP.String()) protocol = utiliptables.ProtocolIPv6 } else { klog.V(0).Infof("kube-proxy node IP is an IPv4 address (%s), assume IPv4 operation", nodeIP.String()) } iptInterface = utiliptables.New(execer, protocol) </ins> // Create event recorder eventBroadcaster := record.NewBroadcaster() recorder := eventBroadcaster.NewRecorder(proxyconfigscheme.Scheme, v1.EventSource{Component: "kube-proxy", Host: hostname})