安装负载均衡器MetalLB和网关traefik

一、安装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对比

在这里插入图片描述

来源:https://ossinsight.io/analyze/kubernetes/ingress-nginx?vs=traefik%2Ftraefik#overview

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

杜莱恩特Durant

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值