Higress替换Nginx-Ingress

Higress替换Nginx-Ingress

Deng YongJie's blog 20 2024-12-15

拉取helm包

#先添加远程仓库,拉取helm包,查看目录里面对于values.yaml的字段,自定义修改,因为下面的镜像参数,在官网是没有的。
helm repo add higress.io https://higress.io/helm-charts
helm pull higress.io/higress

#官方给出的部分参数
https://higress.cn/zh-cn/docs/user/configurations

#使用hostnetwork模式,然后使用内网nexus代理拉取镜像
helm install higress -n higress-system higress.io/higress --create-namespace --render-subchart-notes --set higress-console.o11y.enabled=true --set higress-console.pvc.rwxSupported=false \
--set higress-console.o11y.grafana.storage=10Gi --set higress-console.o11y.prometheus.storage=10Gi --set higress-console.o11y.prometheus.resources.limits.cpu=2000m \
--set higress-core.global.enableStatus=false --set higress-console.image.repository=nexus-gateway.xxx.xxx/higress/console \
--set higress-core.global.hub=nexus-gateway.xxx.xxx/higress --set higress-core.hub=nexus-gateway.xxx.xxx/higress \
--set higress-core.gateway.hub=nexus-gateway.xxx.xxx/higress --set higress-core.gateway.hostNetwork=true \
--set higress-core.controller.hub=nexus-gateway.xxx.xxx/higress --set higress-core.pilot.hub=nexus-gateway.xxx.xxx/higress 

注意:无法启动可能是资源限制limit太低,或者pv没有正常分配给pvc

然后创建nodeport临时访问console控制台

image-20240426175724867

在consolse创建域名、再创建路由配置才能被监听,否则telnet节点的端口是不通的

higress自身的命名空间不会监听,只监听其它命名空间的服务,自动发现service

image-1740473097687
image-20240426175937674
image-20240426175947790

创建完路由配置之后,会自动创建出对应的ingress,并存储到K8S集群的etcd里

image-1740473159395

如果是自建的ingress,需要配置ingressclass为higress才能被监听。或者在helm部署的时候,修改参数global.ingressClass=nginx,自动监听所有自建的ingress。但自建的ingress无法在console上面显示出来,所以务必要在console上面配置路由,统一规范化管理

官方helm不支持daemonset类型,尝试了克隆yaml之后,另外自建修改成daemonset类型都是无法启动。那问题来了:如果有节点没有分布到gateway,那么就无法监听80、443端口,节点负载不均衡,所以要另外手动做分布策略约束

#在higress-gateway的yaml文件添加配置
    spec:
      topologySpreadConstraints:
      - maxSkew: 1 # 最大偏斜度,确保Pod不会过度集中
        topologyKey: kubernetes.io/hostname # 依据节点名称分散Pod
        whenUnsatisfiable: DoNotSchedule # 当无法满足约束时不调度Pod


topologySpreadConstraints 通过以下几个关键参数来定义分布策略:
maxSkew: 定义了在给定的拓扑域(默认是节点kubernetes.io/hostname)内,Pod数量的最大不均衡程度。例如,如果maxSkew设置为1,意味着任何两个节点上该应用的Pod数量差不能超过1。
topologyKey: 指定了Pod分布所基于的拓扑键,如kubernetes.io/zone表示按照可用区分布,kubernetes.io/hostname表示按照节点分布。
whenUnsatisfiable: 指定了当约束条件无法满足时的行为。可选值为:
DoNotSchedule: 如果找不到合适的节点来满足约束条件,则不会调度新的Pod。
ScheduleAnyway: 即使不满足约束条件也会尝试调度Pod,但这可能导致分布不均。
labelSelector: 用于确定哪些Pod受此约束影响,通过标签选择器来匹配Pod。

然后测试分布式约束策略是否有效,添加多副本,超出节点数量的副本会长期处于pending状态,然后每个节点只会分布1个副本

image-20240426180907642