K8S LoadBalance 私有環境解決方案 == metallb 工具安裝和使用介紹

     接着上文,排除故障後,我從新配置了metallb組件到k8s環境。nginx

metallb爲k8s service 的loadbalance負載方式提供免費的解決方案。git

external-ip的收費方案,能夠選擇GRE或Azure,或其餘國內雲商LB方案。github

如下是詳細安裝和配置步驟:api

 

step 1:
root >> kubectl apply -f \
root >> kubectl get all -n metallb-system

 

step 2:
# 生成一個configmap,
# 注意:這裏的 IP 地址範圍須要跟集羣實際狀況相對應。
root >> kubectl apply -f - << EOF
apiVersion: v1
kind: ConfigMap
metadata:
  namespace: metallb-system
  name: config
data:
  config: |
    peers:
    # Cosmetic edit to make MetalLB notice that this is a new config.
    - my-asn: 64512
      peer-asn: 64512
      peer-address: 10.4.0.100
    - my-asn: 64512
      peer-asn: 64512
      peer-address: 10.4.0.101
    - my-asn: 64512
      peer-asn: 64512
      peer-address: 10.4.0.102
    address-pools:
    - name: my-ip-space
      protocol: bgp
      avoid-buggy-ips: true
      addresses:
      - 10.5.0.0/24

# 執行完畢以下圖app

# 而後,咱們在k8s物理機器的外網(好比我這裏一臺客戶機192.168.3.XX),訪問上面configmap的四個IP
<1> IP_1 = 10.4.0.100 / 10.4.0.101 / 10.4.0.101
<2> IP_2 = 10.5.0.0/24 ==> 10.5.0.1 (也能夠經過查詢k8s service獲得, kubectl get service --all-namespaces -o wide。)
root >> ping 10.4.0.100 -c 3
root >> ping 10.4.0.101 -c 3
root >> ping 10.4.0.102 -c 3
root >> ping 10.5.0.1 -c 3

 

step 3:
# 查看配置過程
# pod名稱,來自step 1查詢pod結果
root >> kubectl get all -n metallb-system
root >> kubectl logs -f controller-5f898b44f4-4pkk6 -n metallb-system
 
step 4:
# 建立一個私有loadbalance provider的nginx服務和部署,以下
root >> kubectl apply -f - << EOF
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: nginx-lb
  namespace: app
spec:
  selector:
    matchLabels:
      app: nginx-lb
  replicas: 1
  template:
    metadata:
      labels:
        app: nginx-lb
    spec:
      containers:
      - name: nginx-lb
        image: nginx:1.7.9
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-lb
  namespace: app
spec:
  type: LoadBalancer
  ports:
  - port: 8090
    targetPort: 80
  selector:
    app: nginx-lb

 

 
step 5
# 查看建立後的結果,以下圖
root >> kubectl get all -n app -o wide
# 測試一下nginx-lb的service,經過以下兩個地址
<1> cluster_ip : service_port
root >> curl http://10.3.2.28:8090 
<2> external_ip : service_port
root >> curl http://10.5.0.3:8090
相關文章
相關標籤/搜索