Professional Documents
Culture Documents
k8s负载均衡 openelb
k8s负载均衡 openelb
Service,由于我这是本地私有环境,所以需要部署一个支持该服务类型的负载
所以将目光转向了最近国内青云开源的另外一个负载均衡器 OpenELB。
IP 地址池管理
使用 CRD 进行 BGP 配置
与 MetaLB 对比
云原生架构
灵活的地址管理
架构简单,资源占用少
安装
证高可用,可以将该控制器扩展为两个副本。第一次安装的时候还会为
openelb-admission 1 62m
openelb-admission 1 62m
bgpconfs.network.kubesphere.io 2022-04-10T08:01:18Z
bgppeers.network.kubesphere.io 2022-04-10T08:01:18Z
eips.network.kubesphere.io 2022-04-10T08:01:18Z
配置
......
ipvs:
strictARP: true
......
用的网卡,如果节点只有一个网卡,则可以跳过此步骤,假设安装了 OpenELB
apiVersion: network.kubesphere.io/v1alpha2
kind: Eip
metadata:
name: eip-pool
spec:
address: 192.168.0.100-192.168.0.108
protocol: layer2
disable: false
interface: ens33
这里我们通过 address 属性指定了 IP 地址池,可以填写一个或多个 IP 地址(要
IP 地址,例如 192.168.0.100
IP 地址/子网掩码,例如 192.168.0.0/24
eip-pool 192.168.0.100-192.168.0.108 0 9
apiVersion: network.kubesphere.io/v1alpha2
kind: Eip
metadata:
finalizers:
- finalizer.ipam.kubesphere.io/v1alpha1
name: eip-pool
spec:
address: 192.168.0.100-192.168.0.108
interface: ens33
protocol: layer2
status:
firstIP: 192.168.0.100
lastIP: 192.168.0.108
poolSize: 9
ready: true
v4: true
到这里 LB 的地址池就准备好了,接下来我们创建一个简单的服务,通过 LB 来
进行暴露,如下所示:
# 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:
selector:
app: nginx
type: LoadBalancer
ports:
- name: http
port: 80
targetPort: 80
同样直接创建上面的 Service:
service/nginx created
☸ ➜ curl 192.168.0.101
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed
and
<a href="http://nginx.com/">nginx.com</a>.</p>
</body>
</html>
参考文档
https://openelb.github.io/docs/
https://kubesphere.io/zh/blogs/openelb-joins-cncf-sandbox-project/
https://mp.weixin.qq.com/s/uFwYaPE7cVolLWxYHcgZdQ