當前位置:網站首頁>自建Kubernetes的LoadBalancer類型服務方案-MetalLB

自建Kubernetes的LoadBalancer類型服務方案-MetalLB

2022-01-27 20:58:11 ygqygq2

自建Kubernetes的LoadBalancer類型服務方案-MetalLB

1. 環境

kubernetes環境:

  • kubeadm v1.13.1,網絡使用flannel
  • helm v2.13.0

2. 安裝

helm fetch --untar stable/metallb
cd metallb
vim values.yaml  # 配置ip池
helm install --name metallb --namespce kube-system ./
configInline:
    # Example ARP Configuration
    address-pools:
    - name: default
      protocol: layer2
      addresses:
      - 192.168.105.170-192.168.105.175

3. 使用示例

示例:

nginx-metallb.yaml

apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: nginx-metallb
spec:
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
        ports:
        - name: http
          containerPort: 80

---
apiVersion: v1
kind: Service
metadata:
  name: nginx-metallb
spec:
  ports:
  - name: http
    port: 80
    protocol: TCP
    targetPort: 80
  selector:
    app: nginx
  type: LoadBalancer

正常結果是可以看到svc的EXTERNAL-IP列有分配IP池中的地址,kubernetes外部也可以訪問。

# 訪問測試
lb_ip=$(kubectl get svc nginx-metallb -ojsonpath={
     .status.loadBalancer.ingress[0].ip})
curl $lb_ip

參考鏈接:
[1] https://metallb.universe.tf/

版權聲明
本文為[ygqygq2]所創,轉載請帶上原文鏈接,感謝
https://cht.chowdera.com/2022/01/202201272058109350.html

隨機推薦