MetalLB Load Balancer
  rxEd1anVTirq 2023年12月23日 21 0

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

kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.13.12/config/manifests/metallb-native.yaml

or Helm

helm repo add metallb https://metallb.github.io/metallb
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. 

apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
  name: first-pool
  namespace: metallb-system
spec:
  addresses:
  - 192.168.9.10-192.168.9.20
---
apiVersion: metallb.io/v1beta1
kind: L2Advertisement
metadata:
  name: example
  namespace: metallb-system
spec:
  ipAddressPools:
  - first-pool

 Example

 
   
apiVersion: v1
kind: Pod
metadata:
  name: nginx
  labels:
    app: nginx
spec:
  containers:
    - name: nginx
      image: nginx:1.18.0
---
apiVersion: v1
kind: Service
metadata:
  name: nginx
spec:
  type: LoadBalancer
  ports:
    - port: 80
      targetPort: 80
  selector:
    app: nginx

Service '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

kubectl get service/nginx

MetalLB supports metallb.universe.tf/loadBalancerIPs annotation to set up service with a specific address.

apiVersion: v1
kind: Service
metadata:
  name: nginx
  annotations:
    metallb.universe.tf/loadBalancerIPs: 192.168.9.35
spec:
  type: LoadBalancer
  ports:
    - port: 80
      targetPort: 80
  selector:
    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.

apiVersion: v1
kind: Service
metadata:
  name: nginx
  annotations:
    metallb.universe.tf/address-pool: second-pool
spec:
  type: LoadBalancer
  ports:
    - port: 80
      targetPort: 80
  selector:
    app: nginx

 

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年12月23日 0

暂无评论

推荐阅读
  2xk0JyO908yA   2024年04月11日   45   0   0 Kubernetes
  az2L92p17wYQ   2024年04月29日   44   0   0 Kubernetes
  2xk0JyO908yA   2024年05月17日   41   0   0 Kubernetes
rxEd1anVTirq