一、如果使用metallb的layer2模式,需要如kube-proxy进行配置、让metallb接管主机上的arp管理。

  • 1、POD部暑kube-proxy
kubectl edit configmap -n kube-system kube-proxy
configmap/kube-proxy edited

apiVersion: kubeproxy.config.k8s.io/v1alpha1
kind: KubeProxyConfiguration
mode: "ipvs"
ipvs:
  strictARP: true

2、 二进制部暑kube-proxy

  --proxy-mode=ipvs
  --ipvs-strict-arp    

二、helm部暑

#添加仓库
helm repo add metallb https://metallb.github.io/metallb
# 更新下仓库
helm repo update 

#
mkdir -p /data/metallb
cd /data/metallb

#下载traefik2
helm pull metallb/metallb --version 0.12.1

#提取values.yaml文件
tar zxvf metallb-0.12.1.tgz --strip-components 1 metallb/values.yaml 

cat > /data/metallb/start.sh << 'EOF'
helm upgrade --install --create-namespace --wait metallb metallb-0.12.1.tgz -f values.yaml -n metallb-system
EOF

bash /data/metallb/start.sh

三、配置values.yaml

existingConfigMap: "config"
#configInline: 
#    address-pools:
#    - name: default
#      protocol: layer2
#      addresses:
#      - 192.168.11.90-192.168.11.100  

三、配置layer2-pool

cat > /data/metallb/layer2-pool.yaml < 'EOF'
apiVersion: v1
kind: ConfigMap
metadata:
  namespace: metallb-system
  name: config
data:
  config: |
    address-pools:
    - name: default
      protocol: layer2
      addresses:
      - 192.168.11.90-192.168.11.100
EOF

kubectl apply -f  /data/metallb/layer2-pool.yaml

四、验证

cat > /data/metallb/nginx-metallb.yaml << 'EOF'
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-test
spec:
  selector:
    matchLabels:
      app: nginx-test
  template:
    metadata:
      labels:
        app: nginx-test
    spec:
      containers:
      - name: nginx-test
        image: nginx
        ports:
        - name: http
          containerPort: 80

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

EOF

kubectl apply -f /data/metallb/nginx-metallb.yaml 

kubectl get svc 

在这里插入图片描述
在这里插入图片描述

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐