OpenELB:让k8s私有环境对外暴露端口

OpenELB:云原生负载均衡器插件

OpenELB 是一个开源的云原生负载均衡器实现,可以在基于裸金属服务器、边缘以及虚拟化的 Kubernetes 环境中使用 LoadBalancer 类型的 Service 对外暴露服务。

在 Kubernetes 中安装 OpenELB

1kubectl apply -f https://raw.githubusercontent.com/openelb/openelb/master/deploy/openelb.yaml
  • 查看状态
1kubectl get po -n openelb-system

使用 kubectl 删除 OpenELB

1kubectl delete -f https://raw.githubusercontent.com/openelb/openelb/master/deploy/openelb.yaml
1kubectl get ns

配置 OpenELB

1kubectl edit configmap kube-proxy -n kube-system
2
3# 修改 网卡
4ipvs:
5  strictARP: true

重启组件

1kubectl rollout restart daemonset kube-proxy -n kube-system

为 master1 节点添加一个 annotation 来指定网卡:

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

创建地址池 layer2-eip.yaml

1apiVersion: network.kubesphere.io/v1alpha2
2kind: Eip
3metadata:
4  name: layer2-eip
5spec:
6  address: 192.168.0.91-192.168.0.100
7  interface: eth0
8  protocol: layer2

创建部署 jobcher-service.yaml

 1#暴露端口
 2apiVersion: v1
 3kind: Service
 4metadata:
 5  name: jobcher-service
 6  annotations:
 7    lb.kubesphere.io/v1alpha1: openelb
 8    protocol.openelb.kubesphere.io/v1alpha1: layer2
 9    eip.openelb.kubesphere.io/v1alpha2: layer2-eip
10  labels:
11    app: jobcher-blog
12spec:
13  selector:
14    app: jobcher-blog
15  ports:
16    - name: jobcher-port
17      protocol: TCP
18      port: 80
19      targetPort: 80
20  type: LoadBalancer