本文是从零学习envoy笔记第三章
  • 从零学习envoy笔记 - Gateway总览
  • 从零学习envoy笔记 - 学习EG API和Gateway API
  • 从零学习envoy笔记 - 快速部署实验环境
  • 从零学习envoy笔记 - 官方Task Backend Routing
  • 从零学习envoy笔记 - 官方Task Backend Utilization Load Balancing
  • 从零学习envoy笔记 - 官方Task Bandwidth Limit
  • 从零学习envoy笔记 - 官方Task Client Traffic Policy

本文通过 Kind 来完成快速部署 Envoy Gateway

  • kind
  • helm
  • Envoy Gateway 1.81

准备 kind 环境

这里使用 kind 创建一个本地 Kubernetes 集群。

示例中准备两个节点,1 个 control-plane;2 个 worker

kind 配置如下:

yaml
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
ind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4

nodes:
  - role: control-plane
    image: kindest/node:v1.34.3
    extraPortMappings:
      # Envoy Proxy 数据面 HTTP
      - containerPort: 30080
        hostPort: 38080
        protocol: TCP

      # Envoy Proxy 数据面 HTTPS
      - containerPort: 30443
        hostPort: 38443
        protocol: TCP

      # Envoy Gateway 控制面 grpc
      - containerPort: 31000
        hostPort: 18000
        protocol: TCP

      # Envoy Gateway 控制面 ratelimit
      - containerPort: 31001
        hostPort: 18001
        protocol: TCP

      # Envoy Gateway 控制面 wasm
      - containerPort: 31002
        hostPort: 18002
        protocol: TCP

      # Envoy Gateway 控制面 metrics
      - containerPort: 31003
        hostPort: 19001
        protocol: TCP
  - role: worker
    image: kindest/node:v1.34.3
  - role: worker
    image: kindest/node:v1.34.3

这里 extraPortMappings是指宿主机端口映射到对应 kind 节点的端口,例如:

text
1
2
宿主机 8080 -> kind control-plane 节点 80
宿主机 8443 -> kind control-plane 节点 443

创建 kind 集群

text
1
./kind.exe create cluster --config kind.yaml --name k8s-test

创建成功后,会看到类似输出:

text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
Creating cluster "k8s-test" ...
 ✓ Ensuring node image (kindest/node:v1.34.3)
 ✓ Preparing nodes
 ✓ Writing configuration
 ✓ Starting control-plane
 ✓ Installing CNI
 ✓ Installing StorageClass
 ✓ Joining worker nodes
Set kubectl context to "kind-k8s-test"
You can now use your cluster with:
kubectl cluster-info --context kind-k8s-test
Have a nice day!

部署 Envoy Gateway

Envoy Gateway 可以通过 Helm 安装。Helm 安装时会同时安装两个 CRD Gateway API CRDEnvoy Gateway CRD

The default Helm install applies both Gateway API CRDs and Envoy Gateway CRDs. [1]

如果只是想单独安装 CRD,可以用下面命令

text
1
2
3
4
5
6
helm template eg oci://docker.io/envoyproxy/gateway-crds-helm \
  --version v1.8.1 \
  --set crds.gatewayAPI.enabled=true \
  --set crds.gatewayAPI.channel=standard \
  --set crds.envoyGateway.enabled=true \
  | kubectl apply --server-side -f -

如果直接安装 Envoy Gateway 可以使用下面命令

text
1
2
3
4
5
helm install eg oci://docker.io/envoyproxy/gateway-helm \
  --version v1.8.1 \
  -n envoy-gateway-system \
  --create-namespace \
  --skip-crds

这里在安装时使用的命令,直接开启了 Backend 功能

text
1
2
3
4
5
helm upgrade eg oci://docker.io/envoyproxy/gateway-helm \
	--version v1.8.1 \
	-n envoy-gateway-system \
	--reuse-values \
	--set config.envoyGateway.extensionApis.enableBackend=true

安装成功后,这里只是 envoy-gateway 的控制平面

text
1
2
3
$ kp -n envoy-gateway-system
NAME                             READY   STATUS    RESTARTS   AGE
envoy-gateway-5d4b5c47d-54rh1    1/1     Running   0          100m

部署测试业务实例

bash
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
IMAGE="${IMAGE:-cylonchau/envoy-end:latest}"
APP_PORT="${APP_PORT:-90}"
cat <<YAML | k apply -n default -f -
apiVersion: apps/v1
kind: Deployment
metadata:
  name: envoy-end-gray
spec:
  replicas: 1
  selector:
    matchLabels:
      app: envoy-end
      color: gray
  template:
    metadata:
      labels:
        app: envoy-end
        color: gray
    spec:
      containers:
        - name: envoy-end
          image: ${IMAGE}
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: ${APP_PORT}
          env:
            - name: VERSION
              value: "v1"
            - name: COLORFUL
              value: "gray"
---
apiVersion: v1
kind: Service
metadata:
  name: envoy-end-gray
spec:
  selector:
    app: envoy-end
    color: gray
  ports:
    - name: http-90
      port: 90
      targetPort: ${APP_PORT}
    - name: http-80
      port: 80
      targetPort: ${APP_PORT}
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: envoy-end-red
spec:
  replicas: 1
  selector:
    matchLabels:
      app: envoy-end
      color: red
  template:
    metadata:
      labels:
        app: envoy-end
        color: red
    spec:
      containers:
        - name: envoy-end
          image: ${IMAGE}
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: ${APP_PORT}
          env:
            - name: VERSION
              value: "v2"
            - name: COLORFUL
              value: "red"
---
apiVersion: v1
kind: Service
metadata:
  name: envoy-end-red
spec:
  selector:
    app: envoy-end
    color: red
  ports:
    - name: http-90
      port: 90
      targetPort: ${APP_PORT}
    - name: http-80
      port: 80
      targetPort: ${APP_PORT}
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: envoy-end-blue
spec:
  replicas: 1
  selector:
    matchLabels:
      app: envoy-end
      color: blue
  template:
    metadata:
      labels:
        app: envoy-end
        color: blue
    spec:
      containers:
        - name: envoy-end
          image: ${IMAGE}
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: ${APP_PORT}
          env:
            - name: VERSION
              value: "v3"
            - name: COLORFUL
              value: "blue"
---
apiVersion: v1
kind: Service
metadata:
  name: envoy-end-blue
spec:
  selector:
    app: envoy-end
    color: blue
  ports:
    - name: http-90
      port: 90
      targetPort: ${APP_PORT}
    - name: http-80
      port: 80
      targetPort: ${APP_PORT}
YAML

使用方法

  • GET /ping
  • GET /hostname
  • GET / GET /502bad
  • GET /colorful
  • GET /ping/{ok|fail}

用于模拟一些 envoy 的代理特性

Reference

[1] install helm