Kube-Router: The Complete Guide to the Kubernetes Network Plugin

Shingai Zivuku
8 min readOct 26, 2023

Kube-router is an open-source Kubernetes network plug-in designed to provide high-performance, low-latency network services. It uses Layer 3 Routing to achieve network communication in the Kubernetes cluster.

Photo by Fernand De Canne on Unsplash

The key concepts of Kube-router include:

BGP router: Kube-router uses BGP (Border Gateway Protocol) to implement routing, which means it can dynamically adapt to node changes in the cluster. Each node is configured as a BGP router and they share network information to ensure that communication between containers can occur efficiently and reliably.

IPVS load balancing: Kube-router uses IPVS (IP Virtual Server) to implement load balancing to ensure that traffic is evenly distributed among containers. This provides high performance and scalability, especially for large-scale Kubernetes clusters.

Network policies: Kube-router supports Kubernetes network policies, allowing administrators to define and control which containers can communicate with each other. This enhances the security of the cluster.

Layer 3 routing

Kube-router uses Layer 3 Routing to implement network communication in the Kubernetes cluster. This method is different from the traditional two-layer (Layer 2) network model and has some unique advantages and characteristics. The following is a detailed introduction to the three-layer routing method of kube-router:

  1. IP layer routing: The core idea of ​​Kube-router is to route at the IP level. In Kubernetes, each container is assigned a unique IP address, which makes routing at the IP layer more intuitive and efficient. kube-router uses these IP addresses to implement communication and flow control between containers.
  2. BGP (Border Gateway Protocol) routing protocol: Kube-router uses BGP as its main routing protocol. BGP is a protocol widely used for Internet routing and is highly scalable and resilient. Each Kubernetes node is configured as a BGP router, and they exchange routing information through the BGP protocol. This means that when a new node joins the cluster or an existing node leaves the cluster, the routing information is automatically updated, eliminating the need to manually configure the routing table.
  3. Dynamic routing: Due to the characteristics of BGP, Kube-router implements dynamic routing. This means that when new containers are created or deleted, the routing table is updated accordingly to reflect the actual network topology in the cluster. This automated route management makes it easier to maintain and scale Kubernetes clusters without manual intervention.
  4. High performance and load balancing: Kube-router utilizes IPVS (IP Virtual Server) in the Linux kernel to achieve load balancing. IPVS is a high-performance load-balancing technology that can effectively distribute traffic among multiple containers, thereby providing high throughput and low-latency network performance. This is important for handling large volumes of container traffic, especially in large-scale Kubernetes clusters.
  5. Network policy support: Kube-router also supports Kubernetes network policies. Network policies allow administrators to define which containers can communicate with which other containers and how traffic is allowed or denied. This provides additional security and fine-grained traffic control to meet the needs of different applications.

In short, Kube-router’s three-layer routing method is a flexible and high-performance method for managing network communication in Kubernetes clusters.

It uses IP layer routing, BGP protocol, dynamic routing, and load balancing to provide reliable network connections for containers, and has good scalability and automation features, making it easier and more reliable to manage and maintain the Kubernetes network.

Advantages of Kube-router

  1. High performance: Kube-router adopts high-performance technologies such as IPVS and BGP, so it has excellent network performance and is suitable for large-scale Kubernetes clusters.
  2. Scalability: Due to the use of the BGP routing protocol, Kube-router performs well in the dynamic expansion and contraction of nodes without the need to manually configure routing information.
  3. Network policy support: Kube-router supports Kubernetes network policy, allowing fine-grained traffic control and improved security.
  4. Open-source community support: Kube-router is an open-source project with an active community that provides timely technical support and updates.

Disadvantages of Kube-router

  1. Complexity: The configuration and deployment of Kube-router is relatively complex and requires certain Kubernetes network knowledge.
  2. Maintenance cost: Due to its highly automated nature, Kube-router requires professional maintenance to ensure smooth operation.

Usage scenarios

Kube-router is suitable for Kubernetes clusters that require high performance and scalability, especially those running production environments with large numbers of containers.

The following are some applicable scenarios:

  1. Large-scale clusters: For large Kubernetes clusters, the performance and automation features of Kube-router are very useful for managing the network communication of a large number of containers.
  2. Multi-cloud and cross-data center deployment: Kube-router supports multi-cloud and cross-data center deployment, making communication between Kubernetes clusters across multiple geographical locations simple.
  3. Security-sensitive environments: Because it supports Kubernetes network policies, Kube-router is suitable for environments that need to strengthen network security and can precisely control traffic through network policies.

Installation

Installing Kube-router requires certain Kubernetes cluster knowledge. The following are brief installation steps:

  1. Create a Kubernetes cluster
  2. Install Kube-router
  3. Configure BGP router
  4. Enable network policy
  5. Verify installation

Step 1: Create a Kubernetes cluster

There are different methods you can choose to create a Kubernetes cluster, here is an example using kubeadm:

  1. Install kubeadm, kubelet, and kubectl tools, as well as Docker (or other container runtime).
  2. Initialize the Kubernetes control plane node (Master node):
sudo kubeadm init --pod-network-cidr=10.244.0.0/16

Install the network plug-in, Kube-router will be used here. But at this step, you only need to install kubeadm and kubelet, and no specific network plug-ins are required.

Step 2: Install Kube-router

Next, you need to install Kube-router into your Kubernetes cluster. Typically you can do this using a Helm Chart or YAML manifest file. The following is an example of using a YAML manifest file:

Get the latest manifest file from the Kube-router GitHub repository:

git clone https://github.com/cloudnativelabs/kube-router.git
cd kube-router

Deploy Kube-router to the cluster:

kubectl apply -f kube-router-all-in-one.yaml

This will create Kube-router Pods and related Services.

Step 3: Configure BGP Router

Kube-router uses the BGP routing protocol for routing management by default. You need to configure the relevant information of the BGP router, including the AS number, etc. This configuration information is usually included in a YAML manifest file for use by Kube-router.

You can edit the ConfigMap of Kube-router and add the BGP router configuration information to it. For example, open a ConfigMap file:

kubectl edit configmap kube-router-config -n kube-system

Then, add or modify BGP configuration information as follows:

apiVersion: v1
data:
kubeconfig: |
<kubeconfig-data>
bgpConfig: |
<bgp-config-data>

Step 4: Enable network policy (optional)

If you need to enable Kubernetes network policy, you can create a network policy object. Here’s a simple example:

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-internal-traffic
spec:
podSelector:
matchLabels:
role: internal
ingress:
- from:
- podSelector:
matchLabels:
role: internal

Use kubectl applynetwork policy objects to apply to the cluster.

Step 5: Verify installation

Finally, use the following command to verify that the installation of Kube-router was successful and make sure it is running properly:

kubectl get pods -n kube-system

You should see the pods of Kube-router running. If everything goes well, Kube-router has now been successfully integrated into the Kubernetes cluster and is responsible for network routing and communication.

Expand

Now, I will thoroughly introduce you to what the Border Gateway Protocol (BGP) is. BGP is a routing protocol widely used on the Internet.

BGP is a path vector protocol, mainly used to exchange routing information between different autonomous systems (AS, Autonomous Systems) to determine how data packets should be transmitted across the Internet.

The following is a detailed introduction to the BGP routing protocol:

Autonomous System (AS)

  • An autonomous system is a collection of networks, routers, and IP addresses that are treated as a single administrative unit. Routers within an AS use internal protocols to decide how to route internal traffic, while BGP is primarily used for routing decisions between ASs.

BGP router:

  • A BGP router is a network device configured with the BGP protocol and is used to exchange routing information and determine the best path. Typically, large Internet service providers and large enterprise networks run BGP routers.

Routing information exchange:

  • Routing information is exchanged between BGP routers through TCP connections. BGP routers regularly send routing update information to neighboring routers, including reachable IP prefixes and related attributes.

BGP path selection :

  • BGP uses a complex path selection algorithm to determine the best path for packets. It takes into account a variety of factors, including AS path length, prefix attributes (such as prefix length, AS-PATH, NEXT-HOP, etc.), as well as various policies, filtering conditions, etc.

BGP attributes :

Each route in the BGP routing table is accompanied by a set of attributes that describe the characteristics of the route.

Common BGP attributes include:

  • AS-PATH: Describes the path of the data packet from the source AS to the destination AS.
  • NEXT-HOP: Indicates the IP address of the next hop of the data packet.
  • Prefix length: Specifies the subnet mask length of the reachable prefix.
  • LOCAL-PREF: used to select the best path within the AS.
  • MED (Multi-Exit Discriminator): used to select paths between different exit routes of the same AS.

BGP policy :

  • BGP allows network administrators to define various policies to control the dissemination and selection of routing information. These policies can be used for route filtering, route aggregation, route redistribution, and other operations to meet the specific needs of the network.

Purpose of BGP :

  • BGP is mainly used to connect different autonomous systems, so it plays a key role in the Internet. It allows different network providers to work together to ensure global Internet reachability and stability.

BGP security :

  • Due to the open nature of the BGP protocol, it is vulnerable to different types of attacks, such as route hijacking and route spoofing. In order to enhance the security of BGP, the network community is actively promoting the improvement of BGP and enhanced security mechanisms, such as BGPsec (BGP Security).

In short, BGP is one of the most important routing protocols on the Internet, used to implement routing exchange and path selection between different autonomous systems.

Its complexity and flexibility make it the backbone of the Internet, and it requires experienced network administrators to configure and maintain.

The stability and reliability of BGP are crucial to the normal operation of the Internet, so its security has also received much attention and improvement.

Conclusion

Kube-router is a high-performance, scalable Kubernetes networking plugin suitable for large-scale and security-sensitive production environments.

Although it may have some complexity to configure and deploy, it provides excellent performance and automation features that can greatly simplify network management of Kubernetes clusters.

When choosing a network plug-in, considering cluster size and performance requirements, Kube-router may be a very good choice.

--

--

Shingai Zivuku

Passionate about technology and driven by a love for learning and sharing knowledge