LBCF说明

组件介绍 : Load Balancer Controlling Framework (LBCF)

LBCF是一款部署在Kubernetes内的通用负载均衡控制面框架,旨在降低容器对接负载均衡的实现难度,并提供强大的扩展能力以满足业务方在使用负载均衡时的个性化需求。

部署在集群内kubernetes对象

在集群内部署LBCF Add-on , 将在集群内部署以下kubernetes对象

kubernetes对象名称类型默认占用资源所属Namespaces
lbcf-controllerDeployment/kube-system
lbcf-controllerServiceAccount/kube-system
lbcf-controllerClusterRole//
lbcf-controllerClusterRoleBinding//
lbcf-controllerSecret/kube-system
lbcf-controllerService/kube-system
backendrecords.lbcf.tkestack.ioCustomResourceDefinition//
backendgroups.lbcf.tkestack.ioCustomResourceDefinition//
loadbalancers.lbcf.tkestack.ioCustomResourceDefinition//
loadbalancerdrivers.lbcf.tkestack.ioCustomResourceDefinition//
lbcf-mutateMutatingWebhookConfiguration//
lbcf-validateValidatingWebhookConfiguration//

LBCF使用场景

LBCF对K8S内部晦涩的运行机制进行了封装并以Webhook的形式对外暴露,在容器的全生命周期中提供了多达8种Webhook。通过实现这些Webhook,开发人员可以轻松实现下述功能:

  • 对接任意负载均衡/名字服务,并自定义对接过程
  • 实现自定义灰度升级策略
  • 容器环境与其他环境共享同一个负载均衡
  • 解耦负载均衡数据面与控制面

LBCF使用方法

  1. 通过扩展组件安装LBCF
  2. 开发或选择安装LBCF Webhook规范的要求实现Webhook服务器
  3. 以下按腾讯云CLB开发的webhook服务器为例

详细的使用方法和帮助文档,请参考lb-controlling-framework文档

使用示例

使用已有四层CLB

本例中使用了id为lb-7wf394rv的负载均衡实例,监听器为四层监听器,端口号为20000,协议类型TCP。

注: 程序会以端口号20000,协议类型TCP为条件查询监听器,若不存在,会自动创建新的

  1. apiVersion: lbcf.tkestack.io/v1beta1
  2. kind: LoadBalancer
  3. metadata:
  4. name: example-of-existing-lb
  5. namespace: kube-system
  6. spec:
  7. lbDriver: lbcf-clb-driver
  8. lbSpec:
  9. loadBalancerID: "lb-7wf394rv"
  10. listenerPort: "20000"
  11. listenerProtocol: "TCP"
  12. ensurePolicy:
  13. policy: Always

创建新的七层CLB

本例在vpc vpc-b5hcoxj4中创建了公网(OPEN)负载均衡实例,并为之创建了端口号为9999的HTTP监听器,最后会在监听器中创建mytest.com/index.html的转发规则

  1. apiVersion: lbcf.tkestack.io/v1beta1
  2. kind: LoadBalancer
  3. metadata:
  4. name: example-of-create-new-lb
  5. namespace: kube-system
  6. spec:
  7. lbDriver: lbcf-clb-driver
  8. lbSpec:
  9. vpcID: vpc-b5hcoxj4
  10. loadBalancerType: "OPEN"
  11. listenerPort: "9999"
  12. listenerProtocol: "HTTP"
  13. domain: "mytest.com"
  14. url: "/index.html"
  15. ensurePolicy:
  16. policy: Always

设定backend权重

本例展示了Service NodePort的绑定。被绑定Service的名称为svc-test,service port为80(TCP),绑定到CLB的每个Node:NodePort的权重都是66

  1. apiVersion: lbcf.tkestack.io/v1beta1
  2. kind: BackendGroup
  3. metadata:
  4. name: web-svc-backend-group
  5. namespace: kube-system
  6. spec:
  7. lbName: test-clb-load-balancer
  8. service:
  9. name: svc-test
  10. port:
  11. portNumber: 80
  12. parameters:
  13. weight: "66"

附录

腾讯云CLB LBCF driver

ConfigMap:

  1. apiVersion: v1
  2. kind: ConfigMap
  3. metadata:
  4. name: trusted-tencentcloudapi
  5. namespace: kube-system
  6. data:
  7. tencentcloudapi.pem: |
  8. -----BEGIN CERTIFICATE-----
  9. .............
  10. -----END CERTIFICATE-----

Deployment

  1. apiVersion: lbcf.tkestack.io/v1beta1
  2. kind: LoadBalancerDriver
  3. metadata:
  4. name: lbcf-clb-driver
  5. namespace: kube-system
  6. spec:
  7. driverType: Webhook
  8. url: "http://lbcf-clb-driver.kube-system.svc"
  9. ---
  10. apiVersion: apps/v1
  11. kind: Deployment
  12. metadata:
  13. name: lbcf-clb-driver
  14. namespace: kube-system
  15. spec:
  16. replicas: 1
  17. selector:
  18. matchLabels:
  19. lbcf.tkestack.io/component: lbcf-clb-driver
  20. template:
  21. metadata:
  22. labels:
  23. lbcf.tkestack.io/component: lbcf-clb-driver
  24. spec:
  25. priorityClassName: "system-node-critical"
  26. containers:
  27. - name: driver
  28. image: ${image-name}
  29. args:
  30. - "--region=${your-region}"
  31. - "--vpc-id=${your-vpc-id}"
  32. - "--secret-id=${your-account-secret-id}"
  33. - "--secret-key=${your-account-secret-key}"
  34. ports:
  35. - containerPort: 80
  36. name: insecure
  37. imagePullPolicy: Always
  38. volumeMounts:
  39. - name: trusted-ca
  40. mountPath: /etc/ssl/certs
  41. readOnly: true
  42. volumes:
  43. - name: trusted-ca
  44. configMap:
  45. name: trusted-tencentcloudapi

Service:

  1. apiVersion: v1
  2. kind: Service
  3. metadata:
  4. labels:
  5. name: lbcf-clb-driver
  6. namespace: kube-system
  7. spec:
  8. ports:
  9. - name: insecure
  10. port: 80
  11. targetPort: 80
  12. selector:
  13. lbcf.tkestack.io/component: lbcf-clb-driver
  14. sessionAffinity: None
  15. type: ClusterIP