Customize VPC Internal Load Balancing¶
The Service provided by Kubernetes can be used for load balancing within the cluster. However, there are several issues with using Service as internal load balancing in customize VPC mode:
- The Service IP range is a cluster resource, shared by all customize VPCs, and cannot overlap.
- Users cannot set internal load balancing IP addresses according to their own preferences.
To address the above issues, Kube OVN introduced the SwitchLBRule CRD in 1.11, allowing users to set internal load balancing rules within customize VPCs.
SwitchLBRule support the following two ways to set internal load balancing rules within a customize VPC.
Automatically Generate Load Balancing Rules by Selector¶
Load balancing rules can be generated by selector automatic association with pod configuration through label.
example of SwitchLBRule is as follows:
apiVersion: kubeovn.io/v1
kind: SwitchLBRule
metadata:
name: cjh-slr-nginx
spec:
vip: 1.1.1.1
sessionAffinity: ClientIP
namespace: default
selector:
- app:nginx
ports:
- name: dns
port: 8888
targetPort: 80
protocol: TCP
-
usage of
selector,sessionAffinity, andportis the same as Kubernetes Service. -
vip:customize load balancing IP address. -
namespace:namespace of thepodselected byselector.Kube OVN will determine the VPC of the selected
podbased on theSwitchLBRuledefinition and set the corresponding L2 LB.
Manually Defined Load Balancing Rules by Endpoints¶
Load balancing rules can be customized configured by endpoints, to support scenarios where load balancing rules cannot be automatically generated through selector. For example, the load balancing backend is vm created by kubevirt.
example of SwitchLBRule is as follows:
apiVersion: kubeovn.io/v1
kind: SwitchLBRule
metadata:
name: cjh-slr-nginx
spec:
vip: 1.1.1.1
sessionAffinity: ClientIP
namespace: default
endpoints:
- 192.168.0.101
- 192.168.0.102
- 192.168.0.103
ports:
- name: dns
port: 8888
targetPort: 80
protocol: TCP
-
usage of
sessionAffinity, andportis the same as Kubernetes Service. -
vip:customize load balancing IP address. -
namespace:namespace of thepodselected byselector. -
endpoints:load balancing backend IP list.
attention:If both
selectorandendpointsare configured, theselectorconfiguration will be automatically ignored.