Envoy Gateway 网关
Envoy Gateway 是基于 Envoy Proxy 的 Gateway API 实现,提供 HTTP/TLS/TCP/UDP 路由、流量切分、重写、限流和可观测性。它把 Gateway API 资源翻译成 Envoy 配置,适合替代传统 Ingress Controller。
核心资源:GatewayClass、Gateway、HTTPRoute、GRPCRoute、TLSRoute、BackendTrafficPolicy 和 ClientTrafficPolicy。
安装 Gateway API CRD 和 Envoy Gateway:
kubectl apply -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v1.2.0/standard-install.yaml
helm install eg oci://docker.io/envoyproxy/gateway-helm \
--version v1.2.0 \
--namespace envoy-gateway-system --create-namespace
创建 GatewayClass 和 Gateway:
kubectl apply -f - <<'EOF'
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: public
namespace: demo
spec:
gatewayClassName: eg
listeners:
- name: http
protocol: HTTP
port: 80
- name: https
protocol: HTTPS
port: 443
tls:
mode: Terminate
certificateRefs:
- name: demo-tls
EOF
创建 HTTPRoute:
kubectl apply -f - <<'EOF'
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: demo
namespace: demo
spec:
parentRefs:
- name: public
hostnames:
- demo.example.com
rules:
- matches:
- path: {type: PathPrefix, value: /api}
backendRefs:
- name: api
port: 8080
- matches:
- path: {type: PathPrefix, value: /}
backendRefs:
- name: web
port: 80
EOF
流量切分:
kubectl apply -f - <<'EOF'
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: canary
namespace: demo
spec:
parentRefs:
- name: public
rules:
- backendRefs:
- name: app-v1
port: 80
weight: 90
- name: app-v2
port: 80
weight: 10
EOF
查看状态:
kubectl get gatewayclass
kubectl get gateway -n demo
kubectl get httproute -n demo
kubectl -n envoy-gateway-system logs deploy/envoy-gateway -f
gatewayClassName 与安装的 GatewayClass 不一致,Gateway 一直 Pending。parentRefs 指向错误命名空间,路由不生效。kubectl get gateway,httproute -A — 查看网关和路由kubectl describe gateway — 查看监听器和地址kubectl describe httproute — 查看路由状态kubectl logs -n envoy-gateway-system deploy/envoy-gateway — 控制面日志curl --resolve — 按 host 验证路由