Skip to content

Commit

Permalink
add gateway docs and fsm architecture diagram
Browse files Browse the repository at this point in the history
Signed-off-by: Addo.Zhang <[email protected]>
  • Loading branch information
addozhang committed Sep 23, 2023
1 parent d7f4da9 commit 5ac9ee6
Show file tree
Hide file tree
Showing 10 changed files with 182 additions and 148 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The FSM Gateway serves as an implementation of the [Kubernetes Gateway API](http

Upon activation of the FSM Gateway, the FSM controller, assuming the position of gateway overseer, diligently monitors both Kubernetes native resources and Gateway API assets. Subsequently, it dynamically furnishes the pertinent configurations to [Pipy](https://github.com/flomesh-io/pipy), functioning as a proxy.

!!!IMAGE HERE
![FSM Gateway Architecture](/images/fsm-gateway.png)

Should you have an interest in the FSM Gateway, the ensuing documentation might prove beneficial.

Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ weight: 1
draft: true
---

```yaml

```
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,15 @@ We will follow the sample in [HTTP Routing](/guides/traffic_management/ingress/f

In our backend server, there are two paths `/headers` and `/get`. The previous one responds all request headers as body, and the latter one responds more information of client than `/headers`.

To facilitate testing, it's better to add records to local hosts.

```bash
echo $GATEWAY_IP foo.example.com bar.example.com >> /etc/hosts
-bash: /etc/hosts: Permission denied
```

```bash
curl -H 'host:foo.example.com' http://$GATEWAY_IP:8000/headers
curl foo.example.com/headers
{
"headers": {
"Accept": "*/*",
Expand All @@ -32,22 +39,24 @@ curl -H 'host:foo.example.com' http://$GATEWAY_IP:8000/headers
"User-Agent": "curl/7.68.0"
}
}
curl -H 'host:foo.example.com' http://$GATEWAY_IP:8000/get
curl bar.example.com/get
{
"args": {},
"headers": {
"Accept": "*/*",
"Connection": "keep-alive",
"Host": "foo.example.com",
"Host": "bar.example.com",
"User-Agent": "curl/7.68.0"
},
"origin": "10.42.0.87",
"url": "http://foo.example.com/get"
"url": "http://bar.example.com/get"
}
```

### Host Name Redirect

The HTTP status code `3XX` are used to redirect client to another address. We can redirect all requests to `foo.example.com` to `bar.example.com` by responding `301` status and new hostname.

```bash
apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
Expand All @@ -73,4 +82,123 @@ spec:
backendRefs:
- name: httpbin
port: 8080
```

Now, it will return the `301` code and `bar.example.com:8000` when requesting `foo.example.com`.

```bash
curl -i http://foo.example.com:8000/get
HTTP/1.1 301 Moved Permanently
Location: http://bar.example.com:8000/get
content-length: 0
connection: keep-alive
```

By default, curl does not follow location redirecting unless enable it by assign opiton `-L`.

```bash
curl -L http://foo.example.com:8000/get
{
"args": {},
"headers": {
"Accept": "*/*",
"Connection": "keep-alive",
"Host": "bar.example.com:8000",
"User-Agent": "curl/7.68.0"
},
"origin": "10.42.0.161",
"url": "http://bar.example.com:8000/get"
}
```

### Prefix Path Redirect

With path redirection, we can implement what we did with [URL Rewriting](/guides/traffic_management/ingress/fsm_gateway/http_url_rewrite/#replace-url-prefix-path): redirect the request to `/status/{n}` to `/stream/{n}`.

```bash
apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
name: http-route-foo
spec:
parentRefs:
- name: simple-fsm-gateway
port: 8000
hostnames:
- foo.example.com
rules:
- matches:
- path:
type: PathPrefix
value: /status
filters:
- type: RequestRedirect
requestRedirect:
path:
type: ReplacePrefixMatch
replacePrefixMatch: /stream
statusCode: 301
backendRefs:
- name: httpbin
port: 8080
- matches:
backendRefs:
- name: httpbin
port: 8080
```

After update rull, we will get.

```shell
curl -i http://foo.example.com:8000/status/204
HTTP/1.1 301 Moved Permanently
Location: http://foo.example.com:8000/stream/204
content-length: 0
connection: keep-alive
```

### Full Path Redirect

We can also change full path during redirecting, such as redirect all `/status/xxx` to `/status/200`.

```bash
apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
name: http-route-foo
spec:
parentRefs:
- name: simple-fsm-gateway
port: 8000
hostnames:
- foo.example.com
rules:
- matches:
- path:
type: PathPrefix
value: /status
filters:
- type: RequestRedirect
requestRedirect:
path:
type: ReplaceFullPath
replaceFullPath: /status/200
statusCode: 301
backendRefs:
- name: httpbin
port: 8080
- matches:
backendRefs:
- name: httpbin
port: 8080
```

Now, the status of requests to `/status/xxx` will be redirected to `/status/200`.

```bash
curl -i http://foo.example.com:8000/status/204
HTTP/1.1 301 Moved Permanently
Location: http://foo.example.com:8000/status/200
content-length: 0
connection: keep-alive
```
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,18 @@ curl -H 'host:foo.example.com' http://$GATEWAY_IP:8000/get

### Replace URL Prefix Path

In backend server, there is another path `/status/{statusCode}` which will respond with specified status code.
In backend server, there is another two paths:
- `/status/{statusCode}` will respond with specified status code.
- `/stream/{n}` will respond the response of `/get` `n` times in stream.

```bash
curl -s -w "%{response_code}\n" -H 'host:foo.example.com' http://$GATEWAY_IP:8000/status/204
204
curl -s -w "%{response_code}\n" -H 'host:foo.example.com' http://$GATEWAY_IP:8000/status/20
0
200
curl -s -H 'host:foo.example.com' http://$GATEWAY_IP:8000/stream/1
{"url": "http://foo.example.com/stream/1", "args": {}, "headers": {"Host": "foo.example.com", "User-Agent": "curl/7.68.0", "Accept": "*/*", "Connection": "keep-alive"}, "origin": "10.42.0.161", "id": 0}
```

If we hope to change all `20x` codes to `200`, the rule is required to update again.
If we hope to change the behavior of `/status` to `/stream`, the rule is required to update again.

```bash
apiVersion: gateway.networking.k8s.io/v1beta1
Expand All @@ -117,13 +118,13 @@ spec:
- matches:
- path:
type: PathPrefix
value: /status/20
value: /status
filters:
- type: URLRewrite
urlRewrite:
path:
type: ReplacePrefixMatch
replacePrefixMatch: /status/20
replacePrefixMatch: /stream
backendRefs:
- name: httpbin
port: 8080
Expand All @@ -136,11 +137,12 @@ spec:
port: 8080
```

Update the rule again, we will get `200` response even we specify `204`.
If we trigger the request to `/status/204` path again, we will stream the request data `204` times.

```bash
curl -s -w "%{response_code}\n" -H 'host:foo.example.com' http://$GATEWAY_IP:8000/status/204
200
curl -s -H 'host:foo.example.com' http://$GATEWAY_IP:8000/status/204
{"url": "http://foo.example.com/stream/204", "args": {}, "headers": {"Host": "foo.example.com", "User-Agent": "curl/7.68.0", "Accept": "*/*", "Connection": "keep-alive"}, "origin": "10.42.0.161", "id": 99}
...
```

### Replace Host Name
Expand Down Expand Up @@ -192,5 +194,5 @@ curl -H 'host:foo.example.com' http://$GATEWAY_IP:8000/get
"User-Agent": "curl/7.68.0"
},
"origin": "10.42.0.87",
"url": "http://foo.example.com/get"
"url": "http://baz.example.com/get"
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
title: "Service Loadbalancer"
description: ""
type: docs
weight: 6
---

Binary file added content/en/images/fsm-architecture.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/en/images/fsm-gateway.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions content/en/overview/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@ The evolution of Kubernetes to the edge side solves the difficulties of edge com

## Architecture

![Architecture diagram](https://user-images.githubusercontent.com/2224492/176060685-8504c433-c91b-4f9e-9754-f9ccb6c28a87.png)
![Architecture diagram](/images/fsm-architecture.png)

To break the tight coupling on Pipy and open doors for 3rd parties to develop or make use of their data plane or sidecar proxies, we have refactored the `FSM v1.2.0` codebase to make it generic and provide extension points. We strongly believe in and support open source and our [proposal](https://github.com/flomesh-io/fsm/issues/4874) for this refactoring have been submitted to upstream for their review, discussion, and/or utilization.
To break the tight coupling on Pipy and open doors for 3rd parties to develop or make use of their data plane or sidecar proxies, we have refactored the `FSM v1.1.x` codebase to make it generic and provide extension points. We strongly believe in and support open source and our [proposal](https://github.com/flomesh-io/fsm/issues/4874) for this refactoring have been submitted to upstream for their review, discussion, and/or utilization.
Loading

0 comments on commit 5ac9ee6

Please sign in to comment.