Skip to content

Commit

Permalink
NodePorts understand OnlyLocal
Browse files Browse the repository at this point in the history
  • Loading branch information
bprashanth committed Sep 30, 2016
1 parent 5f4c8c2 commit 93f9b54
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions pkg/proxy/iptables/proxier.go
Original file line number Diff line number Diff line change
Expand Up @@ -1070,10 +1070,14 @@ func (proxier *Proxier) syncProxyRules() {
"-m", protocol, "-p", protocol,
"--dport", fmt.Sprintf("%d", svcInfo.nodePort),
}
// Nodeports need SNAT.
writeLine(natRules, append(args, "-j", string(KubeMarkMasqChain))...)
// Jump to the service chain.
writeLine(natRules, append(args, "-j", string(svcChain))...)
if !svcInfo.onlyNodeLocalEndpoints {
// Nodeports need SNAT, unless they're local.
writeLine(natRules, append(args, "-j", string(KubeMarkMasqChain))...)
// Jump to the service chain.
writeLine(natRules, append(args, "-j", string(svcChain))...)
} else {
writeLine(natRules, append(args, "-j", string(svcXlbChain))...)
}
}

// If the service has no endpoints then reject packets.
Expand Down Expand Up @@ -1173,6 +1177,16 @@ func (proxier *Proxier) syncProxyRules() {
localEndpointChains = append(localEndpointChains, endpointChains[i])
}
}
// First rule in the chain redirects all pod -> external vip traffic to the
// Service's ClusterIP instead. This happens whether or not we have local
// endpoints.
args = []string{
"-A", string(svcXlbChain),
"-m", "comment", "--comment",
fmt.Sprintf(`"Redirect pods trying to reach external loadbalancer VIP to clusterIP"`),
}
writeLine(natRules, append(args, "-s", proxier.clusterCIDR, "-j", string(svcChain))...)

This comment has been minimized.

Copy link
@mandarjog

mandarjog Nov 14, 2016

Contributor

when proxier.clusterCIDR is empty, this produces bad iptables rules.

This happens when cluster-cidr is not provided.

see: #36652


numLocalEndpoints := len(localEndpointChains)
if numLocalEndpoints == 0 {
// Blackhole all traffic since there are no local endpoints
Expand Down

0 comments on commit 93f9b54

Please sign in to comment.