Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Documentation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ Usage of ./kube-router:
--run-firewall Enables Network Policy -- sets up iptables to provide ingress firewall for pods. (default true)
--run-router Enables Pod Networking -- Advertises and learns the routes to Pods via iBGP. (default true)
--run-service-proxy Enables Service Proxy -- sets up IPVS for Kubernetes Services. (default true)
--nodeport-bindon-all-ip For service of NodePort type create IPVS service that listens on all IP's of the node. (default false)
```

### requirements
Expand Down
37 changes: 25 additions & 12 deletions app/controllers/network_services_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,17 @@ var (

// NetworkServicesController struct stores information needed by the controller
type NetworkServicesController struct {
nodeIP net.IP
nodeHostName string
syncPeriod time.Duration
mu sync.Mutex
serviceMap serviceInfoMap
endpointsMap endpointsInfoMap
podCidr string
masqueradeAll bool
globalHairpin bool
client *kubernetes.Clientset
nodeIP net.IP
nodeHostName string
syncPeriod time.Duration
mu sync.Mutex
serviceMap serviceInfoMap
endpointsMap endpointsInfoMap
podCidr string
masqueradeAll bool
globalHairpin bool
client *kubernetes.Clientset
nodeportBindOnAllIp bool
}

// internal representation of kubernetes service
Expand Down Expand Up @@ -262,12 +263,20 @@ func (nsc *NetworkServicesController) syncIpvsServices(serviceInfoMap serviceInf
var ipvsNodeportSvc *ipvs.Service
var nodeServiceId string
if svc.nodePort != 0 {
ipvsNodeportSvc, err = ipvsAddService(nsc.nodeIP, protocol, uint16(svc.nodePort), svc.sessionAffinity)
var vip net.IP
if vip = nsc.nodeIP; nsc.nodeportBindOnAllIp {
vip = net.ParseIP("127.0.0.1")
}
ipvsNodeportSvc, err = ipvsAddService(vip, protocol, uint16(svc.nodePort), svc.sessionAffinity)
if err != nil {
glog.Errorf("Failed to create ipvs service for node port")
continue
}
nodeServiceId = generateIpPortId(nsc.nodeIP.String(), svc.protocol, strconv.Itoa(svc.nodePort))
if nsc.nodeportBindOnAllIp {
nodeServiceId = generateIpPortId("127.0.0.1", svc.protocol, strconv.Itoa(svc.nodePort))
} else {
nodeServiceId = generateIpPortId(nsc.nodeIP.String(), svc.protocol, strconv.Itoa(svc.nodePort))
}
activeServiceEndpointMap[nodeServiceId] = make([]string, 0)
}

Expand Down Expand Up @@ -845,6 +854,10 @@ func NewNetworkServicesController(clientset *kubernetes.Clientset, config *optio
nsc.masqueradeAll = true
}

if config.NodePortBindOnAllIp {
nsc.nodeportBindOnAllIp = true
}

if config.RunRouter {
cidr, err := utils.GetPodCidrFromNodeSpec(nsc.client, config.HostnameOverride)
if err != nil {
Expand Down
45 changes: 24 additions & 21 deletions app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,28 @@ import (
)

type KubeRouterConfig struct {
HelpRequested bool
Kubeconfig string
Master string
ConfigSyncPeriod time.Duration
CleanupConfig bool
IPTablesSyncPeriod time.Duration
IpvsSyncPeriod time.Duration
RoutesSyncPeriod time.Duration
RunServiceProxy bool
RunFirewall bool
RunRouter bool
MasqueradeAll bool
ClusterCIDR string
EnablePodEgress bool
HostnameOverride string
AdvertiseClusterIp bool
PeerRouter string
ClusterAsn string
PeerAsn string
FullMeshMode bool
GlobalHairpinMode bool
HelpRequested bool
Kubeconfig string
Master string
ConfigSyncPeriod time.Duration
CleanupConfig bool
IPTablesSyncPeriod time.Duration
IpvsSyncPeriod time.Duration
RoutesSyncPeriod time.Duration
RunServiceProxy bool
RunFirewall bool
RunRouter bool
MasqueradeAll bool
ClusterCIDR string
EnablePodEgress bool
HostnameOverride string
AdvertiseClusterIp bool
PeerRouter string
ClusterAsn string
PeerAsn string
FullMeshMode bool
GlobalHairpinMode bool
NodePortBindOnAllIp bool
}

func NewKubeRouterConfig() *KubeRouterConfig {
Expand Down Expand Up @@ -81,4 +82,6 @@ func (s *KubeRouterConfig) AddFlags(fs *pflag.FlagSet) {
"Overrides the NodeName of the node. Set this if kube-router is unable to determine your NodeName automatically.")
fs.BoolVar(&s.GlobalHairpinMode, "hairpin-mode", false,
"Add iptable rules for every Service Endpoint to support hairpin traffic.")
fs.BoolVar(&s.NodePortBindOnAllIp, "nodeport-bindon-all-ip", false,
"For service of NodePort type create IPVS service that listens on all IP's of the node.")
}