MetalLB Load Balancer

王海鱼  金牌会员 | 2024-3-2 19:45:54 | 来自手机 | 显示全部楼层 | 阅读模式
打印 上一主题 下一主题

主题 593|帖子 593|积分 1779

MetalLB hooks into your Kubernetes cluster, and provides a network load-balancer implementation. In short, it allows you to create Kubernetes services of type LoadBalancer in clusters that don’t run on a cloud provider, and thus cannot simply hook into paid products to provide load balancers.
Installation

There are multiple ways to install MetalLB, for example
Through manifest
  1. kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.13.12/config/manifests/metallb-native.yaml
复制代码
or Helm
  1. helm repo add metallb https://metallb.github.io/metallb
  2. helm install metallb metallb/metallb
复制代码
The related service, deployment, and pods are in the newly created namespace 'metallb-system'
 'IPAddressPool' defines the IP address range that will be allocated to 'LoadBalancer' type service. The pool of IPs must be dedicated to MetalLB's use. You can't reuse for example the Kubernetes node IPs or IPs controlled by other services.
MetalLB supports two types of traffic policies, Layer2 and BGP. In summary, Layer 2 focuses on local network communication, while BGP handles routing between different networks and plays a critical role in global Internet connectivity. 
  1. apiVersion: metallb.io/v1beta1
  2. kind: IPAddressPool
  3. metadata:
  4.   name: first-pool
  5.   namespace: metallb-system
  6. spec:
  7.   addresses:
  8.   - 192.168.9.10-192.168.9.20
  9. ---
  10. apiVersion: metallb.io/v1beta1
  11. kind: L2Advertisement
  12. metadata:
  13.   name: example
  14.   namespace: metallb-system
  15. spec:
  16.   ipAddressPools:
  17.   - first-pool
复制代码
 Example
  1. [/code]apiVersion: v1kind: Podmetadata:  name: nginx  labels:    app: nginxspec:  containers:    - name: nginx      image: nginx:1.18.0---apiVersion: v1kind: Servicemetadata:  name: nginxspec:  type: LoadBalancer  ports:    - port: 80      targetPort: 80  selector:    app: nginxService 'nginx' will be allocated with an external-ip in 192.168.9.10-192.168.9.20 defined in IPAddressPool first-pool above, check the assigned external-ip with the command below
  2. [code]kubectl get service/nginx
复制代码
MetalLB supports metallb.universe.tf/loadBalancerIPs annotation to set up service with a specific address.
  1. apiVersion: v1
  2. kind: Service
  3. metadata:
  4.   name: nginx
  5.   annotations:
  6.     metallb.universe.tf/loadBalancerIPs: 192.168.9.35
  7. spec:
  8.   type: LoadBalancer
  9.   ports:
  10.     - port: 80
  11.       targetPort: 80
  12.   selector:
  13.     app: nginx
复制代码
MetalLB also supports requesting a specific address pool, when you have multiple pools, for example, one for production public IPs, and one for development private IPs.
  1. apiVersion: v1
  2. kind: Service
  3. metadata:
  4.   name: nginx
  5.   annotations:
  6.     metallb.universe.tf/address-pool: second-pool
  7. spec:
  8.   type: LoadBalancer
  9.   ports:
  10.     - port: 80
  11.       targetPort: 80
  12.   selector:
  13.     app: nginx
复制代码
 

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

王海鱼

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表