@@ -67,16 +67,17 @@ var (
6767
6868// NetworkServicesController struct stores information needed by the controller
6969type NetworkServicesController struct {
70- nodeIP net.IP
71- nodeHostName string
72- syncPeriod time.Duration
73- mu sync.Mutex
74- serviceMap serviceInfoMap
75- endpointsMap endpointsInfoMap
76- podCidr string
77- masqueradeAll bool
78- globalHairpin bool
79- client * kubernetes.Clientset
70+ nodeIP net.IP
71+ nodeHostName string
72+ syncPeriod time.Duration
73+ mu sync.Mutex
74+ serviceMap serviceInfoMap
75+ endpointsMap endpointsInfoMap
76+ podCidr string
77+ masqueradeAll bool
78+ globalHairpin bool
79+ client * kubernetes.Clientset
80+ nodeportBindOnAllIp bool
8081}
8182
8283// internal representation of kubernetes service
@@ -262,12 +263,20 @@ func (nsc *NetworkServicesController) syncIpvsServices(serviceInfoMap serviceInf
262263 var ipvsNodeportSvc * ipvs.Service
263264 var nodeServiceId string
264265 if svc .nodePort != 0 {
265- ipvsNodeportSvc , err = ipvsAddService (nsc .nodeIP , protocol , uint16 (svc .nodePort ), svc .sessionAffinity )
266+ var vip net.IP
267+ if vip = nsc .nodeIP ; nsc .nodeportBindOnAllIp {
268+ vip = net .ParseIP ("127.0.0.1" )
269+ }
270+ ipvsNodeportSvc , err = ipvsAddService (vip , protocol , uint16 (svc .nodePort ), svc .sessionAffinity )
266271 if err != nil {
267272 glog .Errorf ("Failed to create ipvs service for node port" )
268273 continue
269274 }
270- nodeServiceId = generateIpPortId (nsc .nodeIP .String (), svc .protocol , strconv .Itoa (svc .nodePort ))
275+ if nsc .nodeportBindOnAllIp {
276+ nodeServiceId = generateIpPortId ("127.0.0.1" , svc .protocol , strconv .Itoa (svc .nodePort ))
277+ } else {
278+ nodeServiceId = generateIpPortId (nsc .nodeIP .String (), svc .protocol , strconv .Itoa (svc .nodePort ))
279+ }
271280 activeServiceEndpointMap [nodeServiceId ] = make ([]string , 0 )
272281 }
273282
@@ -845,6 +854,10 @@ func NewNetworkServicesController(clientset *kubernetes.Clientset, config *optio
845854 nsc .masqueradeAll = true
846855 }
847856
857+ if config .NodePortBindOnAllIp {
858+ nsc .nodeportBindOnAllIp = true
859+ }
860+
848861 if config .RunRouter {
849862 cidr , err := utils .GetPodCidrFromNodeSpec (nsc .client , config .HostnameOverride )
850863 if err != nil {
0 commit comments