一 环境介绍
k8s版本:
系统版本:
cat /etc/redhat-release 
Rocky Linux release 9.4 (Blue Onyx)
二 higress部署
https://higress.cn/docs/latest/overview/what-is-higress/?spm=36971b57.c984973.0.0.40d67a85L8AV8k 官网介绍 Higress 是一款云原生 API 网关,内核基于 Istio 和 Envoy,可以用 Go/Rust/JS 等编写 Wasm 插件,提供了数十个现成的通用插件,以及开箱即用的控制台
Higress 在阿里内部为解决 Tengine reload 对长连接业务有损,以及 gRPC/Dubbo 负载均衡能力不足而诞生。
阿里云基于 Higress 构建了云原生 API 网关产品,为大量企业客户提供 99.99% 的网关高可用保障服务能力。
2.0 安装helm
wget https://get.helm.sh/helm-v3.13.0-linux-amd64.tar.gz
tar -zxvf helm-v3.13.0-linux-amd64.tar.gz
sudo mv linux-amd64/helm /usr/local/bin/helm
#验证安装
helm version
2.1 安装ingress
Higress 网关由控制面组件 higress-controller 和数据面组件 higress-gateway 组成。higress-gateway负责承载数据流量,higress-controller 负责管理配置下发。console是web页面
helm repo add higress.io https://higress.io/helm-charts
###nodeport裂类型
helm install higress -n higress-system higress.io/higress --create-namespace --render-subchart-notes --set global.local=true --set global.o11y.enabled=false --set higress-console.service.type=NodePort
安装完成后,通过本地的 80 和 443 端口即可访问本地集群内的 Higress Gateway。
访问地址就是console的端口号    http://192.168.234.150:30481/route
2.2 参数介绍
https://higress.cn/docs/latest/ops/deploy-by-helm/?spm=36971b57.35684624.0.0.29cf7cdcYo1p92


2.3 查看ingress版本
helm list -n higress-system
NAME   	NAMESPACE     	REVISION	UPDATED                                	STATUS  	CHART        	APP VERSION
higress	higress-system	1       	2025-04-29 14:21:32.801759395 +0800 CST	deployed	higress-2.1.1	2.1.1  
三 功能测试
3.2 demo-v1版本
3.2.1 yaml配置文件
apiVersion: apps/v1
kind: Deployment
metadata:
  name: demo
  labels:
    app: demo
spec:
  replicas: 1
  selector:
    matchLabels:
      app: demo
  template:
    metadata:
      labels:
        app: demo
    spec:
      containers:
      - name: demo
        imagePullPolicy: Always
        image: registry.cn-shanghai.aliyuncs.com/kubesre01/demo:v1
        ports:
        - containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
  name: demo-svc
spec:
  type: ClusterIP
  selector:
    app: demo
  ports:
    - port: 8080
      targetPort: 8080
3.1.2 创建域名

3.1.3 配置路由

3.1.4 验证访问
先配置对应hosts,这个host的地址,就是pod所在的node节点ip
192.168.234.152 demo.kubesrv.com    

3.2 demo-v2版本
3.2.1 yaml文件
apiVersion: apps/v1
kind: Deployment
metadata:
  name: demo-new
  labels:
    app: demo-new
spec:
  replicas: 1
  selector:
    matchLabels:
      app: demo-new
  template:
    metadata:
      labels:
        app: demo-new
    spec:
      containers:
      - name: demo-new
        imagePullPolicy: Always
        image: registry.cn-shanghai.aliyuncs.com/kubesre01/demo:v2
        ports:
        - containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
  name: demo-new-svc
spec:
  type: ClusterIP
  selector:
    app: demo-new
  ports:
    - port: 8080
      targetPort: 8080
3.2.2 基于客户端请求头的流量切分
测试验证:
curl -H "user: kubesre" http://demo.kubesrv.com/info
curl http://demo.kubesrv.com/info

3.2.3 基于权重访问
3.2.3.1 首先配置ingress
kubectl edit ingress -n higress-system demo-new-canary-header 添加如下两行 higress.io/canary: "true" higress.io/canary-weight: "30"
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    higress.io/canary: "true"
    higress.io/canary-weight: "30"
    higress.io/destination: demo-new-svc.default.svc.cluster.local:8080
    higress.io/ignore-path-case: "false"
  creationTimestamp: "2025-04-30T00:45:11Z"
  generation: 1
  labels:
    higress.io/domain_demo.kubesrv.com: "true"
    higress.io/resource-definer: higress
  name: demo-new-canary-header
  namespace: higress-system
  resourceVersion: "131918"
  uid: 41236a14-6274-4bc5-9dd0-a3ba895eeb74
spec:
  ingressClassName: higress
  rules:
  - host: demo.kubesrv.com
    http:
      paths:
      - backend:
          resource:
            apiGroup: networking.higress.io
            kind: McpBridge
            name: default
        path: /info
        pathType: Exact
status:
  loadBalancer: {}
3.2.3.2 然后进行测试访问

for i in {1..20}; do curl http://demo.kubesrv.com/info && echo; done

3.2.3.3 web页面查看
在对应的web页面查看,刚才添加的两行,会在页面展示,其实也可以直接在web页面配置,同样可以

四 发布策略
4.1 金丝雀发布-新旧都有
金丝雀发布,又称灰度发布,是指通过让小部份用户流量引入的新版本进行测试,如果一切顺利,则可以增加(可能逐渐增加)百分比,逐步替换旧版本。如在过程中出现任何问题,则可以中止并快速回滚到旧版本。最简单的方式是随机选择百分比请求到金丝雀版本,但在更复杂的方案下,则可以基于请求的内容、特定范围的用户或其他属性等。
金丝雀发布,就是上面刚刚验证过的,基于权重的访问过程
4.2 蓝绿发布-非0即100
蓝绿发布,提供了一种零宕机的部署方式,是一种以可观测的方式发布应用的方式,目的减少发布过程中停止时间。在保留老版本的同时部署新版本,将两个版本同时在线,新版本和老版本相互热备,通过切换路由权重的方式(非0即100)实现应用的不同版本上线或者下线,如果有问题可以快速地回滚到老版本。这样做的好处是无需停机,并且风险较小。

用higress实现蓝绿发布,此处目标配置的是新的服务
验证访问,发现访问的全是新的服务
当把目标服务换成版本1的svc,再次进行访问,结果全是v1版本


五 higress监控功能
higress-console.o11y.enabled=true    #启用监控插件
helm install higress -n higress-system higress.io/higress --create-namespace --render-subchart-notes \
    --set global.local=true \
    --set higress-console.service.type=NodePort \
    --set higress-console.o11y.enabled=true \











