修改kube-proxy:

非二进制安装的集群:

kubectl edit configmap kube-proxy -n kube-system
......
ipvs:
  strictARP: true
......

二进制安装的集群:

vim /etc/kubernetes/kube-proxy.yaml 
...
ipvs:
  strictARP: true
...

部署:

kubectl apply -f https://raw.githubusercontent.com/openelb/openelb/master/deploy/openelb.yaml

单节点多网卡:需要再作为eip的网卡添加如下annotation:

kubectl annotate nodes master1 layer2.openelb.kubesphere.io/v1alpha1="192.168.0.200"

eip:

# eip.yaml
apiVersion: network.kubesphere.io/v1alpha2
kind: Eip
metadata:
  name: eip-pool
spec:
  address: 192.168.0.200-192.168.0.230 # 地址池
  protocol: layer2
  disable: false
  interface: ens18 # 网卡名称

测试:

# openelb-nginx.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
spec:
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
        - name: nginx
          image: nginx
          ports:
            - containerPort: 80

# openelb-nginx-svc.yaml
apiVersion: v1
kind: Service
metadata:
  name: nginx
  annotations:
    lb.kubesphere.io/v1alpha1: openelb
    protocol.openelb.kubesphere.io/v1alpha1: layer2
    eip.openelb.kubesphere.io/v1alpha2: eip-pool # 如果没有这行,则可以使用 spec:loadBalancerIP 方式
spec:
  selector:
    app: nginx
  type: LoadBalancer
  ports:
    - name: http
      port: 80
      targetPort: 80

部署后查看资源:可以看到 LoadBalancer 已经有 EXTERNAL-IP 了。

~# kubectl get svc
NAME         TYPE           CLUSTER-IP    EXTERNAL-IP     PORT(S)        AGE
kubernetes   ClusterIP      172.16.0.1    <none>          443/TCP        4d3h
nginx        LoadBalancer   172.16.75.2   192.168.0.200   80:30271/TCP   58m

参考:

qikqiak.com/post/openelb