一、安装MetalLB
MetalLB是一种用于Kubernetes集群的负载平衡器实现,使用标准路由协议。
1.前置条件
https://metallb.io/installation/#preparation
如果您在IPVS模式下使用kube-proxy,则由于Kubernetes v1.14.2,您必须启用严格的ARP模式。
请注意,如果您使用kube-Router作为服务代理,则不需要此,因为它默认启用严格的ARP。
您可以通过在当前集群中编辑kube-proxy配置来实现这一点:
kubectl edit configmap -n kube-system kube-proxy
apiVersion: kubeproxy.config.k8s.io/v1alpha1
kind: KubeProxyConfiguration
mode: "ipvs"
ipvs:
strictARP: true
2.使用Helm安装
https://metallb.io/installation/#installation-with-helm
# values.yaml
speaker:
# ignore the exclude-from-external-loadbalancer label
ignoreExcludeLB: true
# 添加repo
helm repo add metallb https://metallb.github.io/metallb
# 更新repo仓库资源
helm repo update
helm upgrade --install -n metallb --create-namespace metallb metallb/metallb -f values.yaml
3.配置
https://metallb.io/configuration/_advanced_ipaddresspool_configuration/
apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
name: ip-pool
namespace: metallb
spec:
addresses:
- 192.168.170.1-192.168.170.255
---
apiVersion: metallb.io/v1beta1
kind: L2Advertisement
metadata:
name: l2adver
namespace: metallb
4.注意事项
4.1 ping不能作为验证,会报Destination Port Unreachable
https://metallb.io/troubleshooting/#general-concepts
MetalLB’s purpose is to attract traffic directed to the LoadBalancer IP to the cluster nodes. Once the traffic lands on a node, MetalLB’s responsibility is finished and the rest should be handled by the cluster’s CNI.
Because of that, being able to reach the LoadBalancerIP from one of the nodes doesn’t prove that MetalLB is working (or that it is working partially). It actually proves that the CNI is working.
Also, please be aware that pinging the service IP won’t work. You must access the service to ensure that it works. As much as this may sound obvious, check also if your application is behaving correctly.
4.2 MetalLB在控制面板节点和单节点集群不会生效,需要–ignore-exclude-lb标识
https://metallb.io/troubleshooting/#metallb-is-not-advertising-my-service-from-my-control-plane-nodes-or-from-my-single-node-cluster
MetalLB is not advertising my service from my control-plane nodes or from my single node cluster
Make sure your nodes are not labeled with the node.kubernetes.io/exclude-from-external-load-balancers label. MetalLB honors that label and won’t announce any service from such nodes. One way to circumvent the issue is to provide the speakers with the --ignore-exclude-lb flag (either from Helm or via Kustomize).
二、安装traefik
1.选型
1.1 问大模型的提示词
使用 Shields.io 帮助我创建一个展示以下 GitHub
仓库信息的表格,其中包括repo、releases、stars、forks、languages。
涉及的repo有:ingress-nginx、traefik。要求如下: 每个信息都需要有相关的超链接
releases没有的话可以用tags替换
1.2 ossinsight对比
2.安装
# 添加repo
helm repo add traefik https://helm.traefik.io/traefik
# 更新repo仓库资源
helm repo update
helm upgrade --install -n traefik --create-namespace traefik traefik/traefik
3.查看
# 查看helm列表
helm list -n traefik
# 查看pod资源信息
kubectl get pod -n traefik
# 查看service资源信息
kubectl get svc -n traefik
4.删除
helm uninstall traefik -n traefik
5.IngressRoute查看和删除
kubectl get ingressroute.traefik.io --all-namespaces
kubectl delete ingressroute.traefik.io --all --all-namespaces
6.配置示例
需要域名服务器(下一节讲PowerDNS吧),为了简单起见,可以添加到hosts里面
192.168.141.254 grafana.k8s.home.love
192.168.141.254 juicefs.k8s.home.love
192.168.141.254 traefik.k8s.home.love
6.1 IngressRoute: kubesphere-monitoring-system
http://grafana.k8s.home.love/
http://prometheus.k8s.home.love/
# https://doc.traefik.io/traefik/reference/routing-configuration/kubernetes/crd/http/ingressroute/
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
name: traefik-host
namespace: kubesphere-monitoring-system
spec:
entryPoints:
- web
routes:
- match: "Host(`grafana.k8s.home.love`)"
kind: Rule
services:
- name: grafana
port: 80
- match: "Host(`prometheus.k8s.home.love`)"
kind: Rule
services:
- name: prometheus-k8s
port: 9090
6.2 IngressRoute: kube-system
http://juicefs.k8s.home.love/pods
# https://doc.traefik.io/traefik/reference/routing-configuration/kubernetes/crd/http/ingressroute/
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
name: traefik-host
namespace: kube-system
spec:
entryPoints:
- web
routes:
- match: Host(`juicefs.k8s.home.love`)
kind: Rule
services:
- name: juicefs-csi-dashboard
namespace: kube-system
port: 8088
三、附OpenELB(不推荐)
OpenELB没有给svc自动分配vip地址呢,MetalLB都是可以自动分配的哦。
需要下面几个 annotations 注解:
lb.kubesphere.io/v1alpha1 : openelb 用来指定该 Service 使用 OpenELB
protocol.openelb.kubesphere.io/v1alpha1 : layer2 表示指定 OpenELB 用于 Layer2 模式
eip.openelb.kubesphere.io/v1alpha2 : eip-pool 用来指定了 OpenELB 使用的 Eip 对象,如果未配置此注解,OpenELB 会自动使用与协议匹配的第一个可用 Eip 对象。
原文链接:https://blog.csdn.net/weixin_39246554/article/details/129386533