fix localport open - iptables part changes
This commit is contained in:
parent
04634cb198
commit
b2f5c8e610
@ -960,32 +960,55 @@ func (proxier *Proxier) syncProxyRules() {
|
|||||||
if svcInfo.NodePort != 0 {
|
if svcInfo.NodePort != 0 {
|
||||||
// Hold the local port open so no other process can open it
|
// Hold the local port open so no other process can open it
|
||||||
// (because the socket might open but it would never work).
|
// (because the socket might open but it would never work).
|
||||||
lp := utilproxy.LocalPort{
|
addresses, err := utilproxy.GetNodeAddresses(proxier.nodePortAddresses, proxier.networkInterfacer)
|
||||||
Description: "nodePort for " + svcNameString,
|
if err != nil {
|
||||||
IP: "",
|
glog.Errorf("Failed to get node ip address matching nodeport cidr")
|
||||||
Port: svcInfo.NodePort,
|
continue
|
||||||
Protocol: protocol,
|
|
||||||
}
|
}
|
||||||
if proxier.portsMap[lp] != nil {
|
|
||||||
glog.V(4).Infof("Port %s was open before and is still needed", lp.String())
|
lps := make([]utilproxy.LocalPort, 0)
|
||||||
replacementPortsMap[lp] = proxier.portsMap[lp]
|
for address := range addresses {
|
||||||
} else {
|
if utilproxy.IsZeroCIDR(address) {
|
||||||
socket, err := proxier.portMapper.OpenLocalPort(&lp)
|
lp := utilproxy.LocalPort{
|
||||||
if err != nil {
|
Description: "nodePort for " + svcNameString,
|
||||||
glog.Errorf("can't open %s, skipping this nodePort: %v", lp.String(), err)
|
IP: "",
|
||||||
continue
|
Port: svcInfo.NodePort,
|
||||||
}
|
Protocol: protocol,
|
||||||
if lp.Protocol == "udp" {
|
|
||||||
// TODO: We might have multiple services using the same port, and this will clear conntrack for all of them.
|
|
||||||
// This is very low impact. The NodePort range is intentionally obscure, and unlikely to actually collide with real Services.
|
|
||||||
// This only affects UDP connections, which are not common.
|
|
||||||
// See issue: https://github.com/kubernetes/kubernetes/issues/49881
|
|
||||||
err := conntrack.ClearEntriesForPort(proxier.exec, lp.Port, isIPv6, v1.ProtocolUDP)
|
|
||||||
if err != nil {
|
|
||||||
glog.Errorf("Failed to clear udp conntrack for port %d, error: %v", lp.Port, err)
|
|
||||||
}
|
}
|
||||||
|
lps = append(lps, lp)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
lp := utilproxy.LocalPort{
|
||||||
|
Description: "nodePort for " + svcNameString,
|
||||||
|
IP: address,
|
||||||
|
Port: svcInfo.NodePort,
|
||||||
|
Protocol: protocol,
|
||||||
|
}
|
||||||
|
lps = append(lps, lp)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, lp := range lps {
|
||||||
|
if proxier.portsMap[lp] != nil {
|
||||||
|
glog.V(4).Infof("Port %s was open before and is still needed", lp.String())
|
||||||
|
replacementPortsMap[lp] = proxier.portsMap[lp]
|
||||||
|
} else {
|
||||||
|
socket, err := proxier.portMapper.OpenLocalPort(&lp)
|
||||||
|
if err != nil {
|
||||||
|
glog.Errorf("can't open %s, skipping this nodePort: %v", lp.String(), err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if lp.Protocol == "udp" {
|
||||||
|
// TODO: We might have multiple services using the same port, and this will clear conntrack for all of them.
|
||||||
|
// This is very low impact. The NodePort range is intentionally obscure, and unlikely to actually collide with real Services.
|
||||||
|
// This only affects UDP connections, which are not common.
|
||||||
|
// See issue: https://github.com/kubernetes/kubernetes/issues/49881
|
||||||
|
err := conntrack.ClearEntriesForPort(proxier.exec, lp.Port, isIPv6, v1.ProtocolUDP)
|
||||||
|
if err != nil {
|
||||||
|
glog.Errorf("Failed to clear udp conntrack for port %d, error: %v", lp.Port, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
replacementPortsMap[lp] = socket
|
||||||
}
|
}
|
||||||
replacementPortsMap[lp] = socket
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if hasEndpoints {
|
if hasEndpoints {
|
||||||
|
Loading…
Reference in New Issue
Block a user