自建Kubernetes的LoadBalancer类型服务方案-MetalLB
1. 环境
kubernetes环境:
- kubeadm v1.13.1,网络使用flannel
- helm v2.13.0
2. 安装
helm fetch --untar stable/metallb
cd metallb
vim values.yaml # 配置ip池
helm install --name metallb --namespce kube-system ./
configInline:
# Example ARP Configuration
address-pools:
- name: default
protocol: layer2
addresses:
- 192.168.105.170-192.168.105.175
3. 使用示例
示例:
nginx-metallb.yaml
apiVersion: apps/v1beta2
kind: Deployment
metadata:
name: nginx-metallb
spec:
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx
ports:
- name: http
containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: nginx-metallb
spec:
ports:
- name: http
port: 80
protocol: TCP
targetPort: 80
selector:
app: nginx
type: LoadBalancer
正常结果是可以看到svc的EXTERNAL-IP列有分配IP池中的地址,kubernetes外部也可以访问。
# 访问测试
lb_ip=$(kubectl get svc nginx-metallb -ojsonpath={.status.loadBalancer.ingress[0].ip})
curl $lb_ip
参考链接: [1] https://metallb.universe.tf/