fix examples relevant readme docs (#3102)

fix examples relevant readme docs
pull/3104/head
panxiaojun233 2 years ago committed by GitHub
parent 2530f0400a
commit f233705dc3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -289,87 +289,6 @@ kubectl delete DestinationRule my-destination-rule
``` ```
删除规则后,可以看到路由的策略将不由请求头的携带与否来决定,而是完全遵从于负载均衡器的实现。 删除规则后,可以看到路由的策略将不由请求头的携带与否来决定,而是完全遵从于负载均衡器的实现。
## 集成OpenSergo
**注意 本章节只是为了便于您理解接入方式,本示例代码中已经完成接入工作,您无需再进行修改。**
1. 首先,修改`pom.xml` 文件,引入`spring-cloud-starter-alibaba-governance-routing`依赖。同时引入Spring Cloud Alibaba的`spring-cloud-starter-opensergo-adapter`模块
```XML
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-governance-routing</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-opensergo-adapter</artifactId>
</dependency>
```
2. 在`application.properties`配置文件中配置OpenSergo控制面的相关信息
```
# OpenSergo 控制面 endpoint
spring.cloud.opensergo.endpoint=127.0.0.1:10246
```
### 应用启动
启动三个模块的启动类分别为OpenSergoConsumerApplication两个ProviderApplication将其注入到Nacos注册中心中。
### 下发配置
[启动 OpenSergo 控制面](https://opensergo.io/zh-cn/docs/quick-start/opensergo-control-plane/) ,并通过 OpenSergo 控制面下发流量路由规则
```YAML
kubectl apply -f - << EOF
apiVersion: traffic.opensergo.io/v1alpha1
kind: TrafficRouter
metadata:
name: service-provider
namespace: default
labels:
app: service-provider
spec:
hosts:
- service-provider
http:
- match:
- headers:
tag:
exact: v2
route:
- destination:
host: service-provider
subset: v2
fallback:
host: service-provider
subset: v1
- route:
- destination:
host: service-provider
subset: v1
EOF
```
这条TrafficRouter指定了一条最简单的流量路由规则将请求头tag为v2的HTTP请求路由到v2版本其余的流量都路由到v1版本。
如果v2版本没有对应的节点则将流量fallback至v1版本。
### 效果演示
发送一条不带请求头的HTTP请求至IstioConsumerApplication:
```
curl --location --request GET '127.0.0.1:18083/router-test'
```
因为请求头不为gray所以请求将会被路由到v1版本返回如下:
```
Route in 30.221.132.228: 18081,version is v1.
```
之后发送一条请求头tag为gray的HTTP请求
```
curl --location --request GET '127.0.0.1:18083/router-test' --header 'tag: v2'
```
因为满足路由规则所以请求会被路由至v2版本:
```
Route in 30.221.132.228: 18082,version is v2.
```
最后删除这条标签路由规则:
```shell
kubectl delete VirtualService sca-virtual-service
kubectl delete DestinationRule my-destination-rule
```
删除规则后,可以看到路由的策略将不由请求头的携带与否来决定,而是完全遵从于负载均衡器的实现。
## 集成OpenSergo ## 集成OpenSergo
**注意 本章节只是为了便于您理解接入方式,本示例代码中已经完成接入工作,您无需再进行修改。** **注意 本章节只是为了便于您理解接入方式,本示例代码中已经完成接入工作,您无需再进行修改。**
1. 首先修改pom.xml 文件,引入`spring-cloud-starter-alibaba-governance-routing`依赖。同时引入Spring Cloud Alibaba的`spring-cloud-starter-opensergo-adapter`模块 1. 首先修改pom.xml 文件,引入`spring-cloud-starter-alibaba-governance-routing`依赖。同时引入Spring Cloud Alibaba的`spring-cloud-starter-opensergo-adapter`模块
@ -425,7 +344,7 @@ spec:
subset: v1 subset: v1
EOF EOF
``` ```
这条TrafficRouter指定了一条最简单的流量路由规则将请求头tag为v2的HTTP请求路由到v2版本其余的流量都路由到v1版本。 这条[TrafficRouter](https://github.com/opensergo/opensergo-specification/blob/main/specification/zh-Hans/traffic-routing.md) 指定了一条最简单的流量路由规则将请求头tag为v2的HTTP请求路由到v2版本其余的流量都路由到v1版本。
如果v2版本没有对应的节点则将流量fallback至v1版本。 如果v2版本没有对应的节点则将流量fallback至v1版本。
### 效果演示 ### 效果演示
发送一条不带请求头的HTTP请求至OpenSergoConsumerApplication 发送一条不带请求头的HTTP请求至OpenSergoConsumerApplication

@ -343,7 +343,7 @@ spec:
subset: v1 subset: v1
EOF EOF
``` ```
This TrafficRouter specifies the simplest label routing rule. HTTP requests with a gray header are routed to v2, and the rest of the traffic is routed to v1. This [TrafficRouter](https://github.com/opensergo/opensergo-specification/blob/main/specification/en/traffic-routing.md) specifies the simplest label routing rule. HTTP requests with a gray header are routed to v2, and the rest of the traffic is routed to v1.
If the version v2 does not have a corresponding instance, the HTTP request will fall back to the version v1. If the version v2 does not have a corresponding instance, the HTTP request will fall back to the version v1.
### Demonstrate effect ### Demonstrate effect
We send an HTTP request without a request header to OpenSergoConsumerApplication We send an HTTP request without a request header to OpenSergoConsumerApplication
@ -354,9 +354,9 @@ Since the request header is not gray, the request will be routed to version v1 w
``` ```
Route in 30.221.132.228: 18081,version is v1. Route in 30.221.132.228: 18081,version is v1.
``` ```
We then send an HTTP request with a gray tag in its header and the request path is `/istio-label-routing`: We then send an HTTP request with a gray tag in its header and the request path is `/router-test`:
``` ```
curl --location --request GET '127.0.0.1:18083/router-test' --header 'tag: gray' curl --location --request GET '127.0.0.1:18083/router-test' --header 'tag: v2'
``` ```
The request is routed to version v2 because the routing rule is matched by the request. The request is routed to version v2 because the routing rule is matched by the request.
``` ```

Loading…
Cancel
Save