diff --git a/pkg/proxy/iptables/proxier.go b/pkg/proxy/iptables/proxier.go index 4eebe6cc738..e423acc6edb 100644 --- a/pkg/proxy/iptables/proxier.go +++ b/pkg/proxy/iptables/proxier.go @@ -619,6 +619,12 @@ func (proxier *Proxier) deleteEndpointConnections(connectionMap []proxy.ServiceE klog.Errorf("Failed to delete %s endpoint connections for externalIP %s, error: %v", epSvcPair.ServicePortName.String(), extIP, err) } } + for _, lbIP := range svcInfo.LoadBalancerIPStrings() { + err := conntrack.ClearEntriesForNAT(proxier.exec, lbIP, endpointIP, v1.ProtocolUDP) + if err != nil { + klog.Errorf("Failed to delete %s endpoint connections for LoabBalancerIP %s, error: %v", epSvcPair.ServicePortName.String(), lbIP, err) + } + } } } } diff --git a/pkg/proxy/ipvs/proxier.go b/pkg/proxy/ipvs/proxier.go index 94fabbb0215..92062168ebd 100644 --- a/pkg/proxy/ipvs/proxier.go +++ b/pkg/proxy/ipvs/proxier.go @@ -1499,6 +1499,12 @@ func (proxier *Proxier) deleteEndpointConnections(connectionMap []proxy.ServiceE klog.Errorf("Failed to delete %s endpoint connections for externalIP %s, error: %v", epSvcPair.ServicePortName.String(), extIP, err) } } + for _, lbIP := range svcInfo.LoadBalancerIPStrings() { + err := conntrack.ClearEntriesForNAT(proxier.exec, lbIP, endpointIP, v1.ProtocolUDP) + if err != nil { + klog.Errorf("Failed to delete %s endpoint connections for LoabBalancerIP %s, error: %v", epSvcPair.ServicePortName.String(), lbIP, err) + } + } } } } diff --git a/pkg/proxy/service.go b/pkg/proxy/service.go index 9135312cd73..1cb2f425d24 100644 --- a/pkg/proxy/service.go +++ b/pkg/proxy/service.go @@ -78,11 +78,21 @@ func (info *BaseServiceInfo) GetHealthCheckNodePort() int { func (info *BaseServiceInfo) GetNodePort() int { return info.NodePort } + // ExternalIPStrings is part of ServicePort interface. func (info *BaseServiceInfo) ExternalIPStrings() []string { return info.ExternalIPs } +// LoadBalancerIPStrings is part of ServicePort interface. +func (info *BaseServiceInfo) LoadBalancerIPStrings() []string { + var ips []string + for _, ing := range info.LoadBalancerStatus.Ingress { + ips = append(ips, ing.IP) + } + return ips +} + func (sct *ServiceChangeTracker) newBaseServiceInfo(port *v1.ServicePort, service *v1.Service) *BaseServiceInfo { onlyNodeLocalEndpoints := false if apiservice.RequestsOnlyLocalTraffic(service) { diff --git a/pkg/proxy/types.go b/pkg/proxy/types.go index c8b2ee18770..b7d8b1654a9 100644 --- a/pkg/proxy/types.go +++ b/pkg/proxy/types.go @@ -52,6 +52,8 @@ type ServicePort interface { ClusterIPString() string // ExternalIPStrings returns service ExternalIPs as a string array. ExternalIPStrings() []string + // LoadBalancerIPStrings returns service LoadBalancerIPs as a string array. + LoadBalancerIPStrings() []string // GetProtocol returns service protocol. GetProtocol() v1.Protocol // GetHealthCheckNodePort returns service health check node port if present. If return 0, it means not present.