Skip to content

Commit

Permalink
Support for advertising service external IP to be configured BGP peers (
Browse files Browse the repository at this point in the history
#203)

introduces new flag `--advertise-external-ip`

Fixes #161
  • Loading branch information
murali-reddy authored Oct 16, 2017
1 parent ba7697b commit 4ca0afa
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Documentation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ Also you can choose to run kube-router as agent running on each cluster node. Al

```
Usage of ./kube-router:
--advertise-cluster-ip Add Cluster IP to the RIB and advertise to peers.
--advertise-cluster-ip Add Cluster IP of the service to the RIB so that it gets advertises to the BGP peers.
--advertise-external-ip Add External IP of service to the RIB so that it gets advertised to the BGP peers.
--cleanup-config Cleanup iptables rules, ipvs, ipset configuration and exit.
--cluster-asn uint ASN number under which cluster nodes will run iBGP.
--cluster-cidr string CIDR range of pods in the cluster. It is used to identify traffic originating from and destinated to pods.
Expand Down
39 changes: 38 additions & 1 deletion app/controllers/network_routes_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type NetworkRoutingController struct {
enablePodEgress bool
hostnameOverride string
advertiseClusterIp bool
advertiseExternalIp bool
defaultNodeAsnNumber uint32
nodeAsnNumber uint32
globalPeerRouters []*config.NeighborConfig
Expand Down Expand Up @@ -207,7 +208,7 @@ func (nrc *NetworkRoutingController) Run(stopCh <-chan struct{}, wg *sync.WaitGr

// advertise cluster IP for the service to be reachable via host
if nrc.advertiseClusterIp {
glog.Infof("Advertising cluster ips")
glog.Infof("Advertising cluster ips of services to the external BGP peers")
for _, svc := range watchers.ServiceWatcher.List() {
if svc.Spec.Type == "ClusterIP" || svc.Spec.Type == "NodePort" || svc.Spec.Type == "LoadBalancer" {

Expand All @@ -222,6 +223,22 @@ func (nrc *NetworkRoutingController) Run(stopCh <-chan struct{}, wg *sync.WaitGr
}
}

// advertise cluster IP for the service to be reachable via host
if nrc.advertiseExternalIp {
glog.Infof("Advertising external ips of the services to the external BGP peers")
for _, svc := range watchers.ServiceWatcher.List() {
if svc.Spec.Type == "ClusterIP" || svc.Spec.Type == "NodePort" {
// skip headless services
if svc.Spec.ClusterIP == "None" || svc.Spec.ClusterIP == "" {
continue
}
for _, externalIP := range svc.Spec.ExternalIPs {
nrc.AdvertiseClusterIp(externalIP)
}
}
}
}

glog.Infof("Performing periodic syn of the routes")
err = nrc.advertiseRoute()
if err != nil {
Expand Down Expand Up @@ -370,6 +387,21 @@ func (nrc *NetworkRoutingController) getClusterIps() ([]string, error) {
return clusterIpList, nil
}

func (nrc *NetworkRoutingController) getExternalIps() ([]string, error) {
externalIpList := make([]string, 0)
for _, svc := range watchers.ServiceWatcher.List() {
if svc.Spec.Type == "ClusterIP" || svc.Spec.Type == "NodePort" {

// skip headless services
if svc.Spec.ClusterIP == "None" || svc.Spec.ClusterIP == "" {
continue
}
externalIpList = append(externalIpList, svc.Spec.ExternalIPs...)
}
}
return externalIpList, nil
}

// Used for processing Annotations that may contain multiple items
// Pass this the string and the delimiter
func stringToSlice(s, d string) []string {
Expand Down Expand Up @@ -525,6 +557,10 @@ func (nrc *NetworkRoutingController) addExportPolicies() error {
for _, ip := range clusterIps {
clusterIpPrefixList = append(clusterIpPrefixList, config.Prefix{IpPrefix: ip + "/32"})
}
externalIps, _ := nrc.getExternalIps()
for _, ip := range externalIps {
clusterIpPrefixList = append(clusterIpPrefixList, config.Prefix{IpPrefix: ip + "/32"})
}
clusterIpPrefixSet, err := table.NewPrefixSet(config.PrefixSet{
PrefixSetName: "clusteripprefixset",
PrefixList: clusterIpPrefixList,
Expand Down Expand Up @@ -1307,6 +1343,7 @@ func NewNetworkRoutingController(clientset *kubernetes.Clientset,
}

nrc.advertiseClusterIp = kubeRouterConfig.AdvertiseClusterIp
nrc.advertiseExternalIp = kubeRouterConfig.AdvertiseExternalIp

nrc.enableOverlays = kubeRouterConfig.EnableOverlay

Expand Down
5 changes: 4 additions & 1 deletion app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type KubeRouterConfig struct {
EnablePodEgress bool
HostnameOverride string
AdvertiseClusterIp bool
AdvertiseExternalIp bool
PeerRouters []net.IP
PeerASNs []uint
ClusterAsn uint
Expand Down Expand Up @@ -74,7 +75,9 @@ func (s *KubeRouterConfig) AddFlags(fs *pflag.FlagSet) {
fs.DurationVar(&s.RoutesSyncPeriod, "routes-sync-period", s.RoutesSyncPeriod,
"The delay between route updates and advertisements (e.g. '5s', '1m', '2h22m'). Must be greater than 0.")
fs.BoolVar(&s.AdvertiseClusterIp, "advertise-cluster-ip", false,
"Add Cluster IP to the RIB and advertise to peers.")
"Add Cluster IP of the service to the RIB so that it gets advertises to the BGP peers.")
fs.BoolVar(&s.AdvertiseExternalIp, "advertise-external-ip", false,
"Add External IP of service to the RIB so that it gets advertised to the BGP peers.")
fs.IPSliceVar(&s.PeerRouters, "peer-router-ips", s.PeerRouters,
"The ip address of the external router to which all nodes will peer and advertise the cluster ip and pod cidr's.")
fs.UintVar(&s.ClusterAsn, "cluster-asn", s.ClusterAsn,
Expand Down

0 comments on commit 4ca0afa

Please sign in to comment.