Skip to content

Commit

Permalink
Merge pull request #2548 from spidernet-io/doc/route
Browse files Browse the repository at this point in the history
doc: update en route
  • Loading branch information
Icarus9913 authored Nov 7, 2023
2 parents 260a74c + ebc76a3 commit 6ff4554
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 162 deletions.
6 changes: 1 addition & 5 deletions docs/usage/route-zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Spiderpool 提供了为 Pod 配置路由信息的功能。

### 搭配网关配置默认路由

当我们为 SpiderIPPool 资源设置**网关地址**(`spec.gateway`)后,我们会根据该网关地址为 Pod 生成一条默认路由:
SpiderIPPool 资源设置**网关地址**(`spec.gateway`)后,我们会根据该网关地址为 Pod 生成一条默认路由:

```yaml
apiVersion: spiderpool.spidernet.io/v2beta1
Expand All @@ -26,8 +26,6 @@ spec:
我们也可为 SpiderIPPool 资源配置路由(`spec.routes`),创建 Pod 时会继承该路由:

> 注意:
>
> - 当 SpiderIPPool 资源配置了网关地址后,请勿为路由字段配置默认路由。
> - `dst` 和 `gw` 字段都为必填

Expand All @@ -50,8 +48,6 @@ spec:

我们也支持为应用配置自定义路由的功能,只需为 Pod 打上注解 `ipam.spidernet.io/routes`:

> 注意:
>
> - 当 SpiderIPPool 资源中配置了网关地址、或配置了默认路由后,请勿为 Pod 配置默认路由。
> - `dst` 和 `gw` 字段都为必填

Expand Down
182 changes: 25 additions & 157 deletions docs/usage/route.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,119 +2,32 @@

**English**[**简体中文**](./route-zh_CN.md)

## Description
## Introduction

Spiderpool supports the configuration of routing information.
Spiderpool supports the configuration of routing information for Pods.

## Get Started
### Configure Default Route with Gateway

### Set up Spiderpool

follow the guide [installation](./install/underlay/get-started-kind.md) to install Spiderpool.

### Create Subnet

Create a SpiderSubnet and set up a subnet routes, a Pod and get the IP address from the AutoIPPool of the subnet, then see the routes configured in the subnet that exist in the AutoIPPool and Pod.

```bash
kubectl apply -f https://raw.githubusercontent.com/spidernet-io/spiderpool/main/docs/example/route/subnet-route.yaml
```
When setting the **gateway address** (`spec.gateway`) for a SpiderIPPool resource, a default route will be generated for Pods based on that gateway address:

```yaml
apiVersion: spiderpool.spidernet.io/v2beta1
kind: SpiderSubnet
kind: SpiderIPPool
metadata:
name: ipv4-subnet-route
name: ipv4-ippool-route
spec:
subnet: 172.18.41.0/24
ips:
- 172.18.41.41-172.18.41.60
routes:
- dst: 172.18.42.0/24
gw: 172.18.41.1
```
### Create Deployment By SpiderSubnet
Create a Deployment whose Pods sets the Pod annotation `ipam.spidernet.io/subnet` to explicitly specify the subnet.

```bash
kubectl apply -f https://raw.githubusercontent.com/spidernet-io/spiderpool/main/docs/example/route/subnet-route-deploy.yaml
```

```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: subnet-test-app
spec:
replicas: 1
selector:
matchLabels:
app: subnet-test-app
template:
metadata:
annotations:
ipam.spidernet.io/subnet: |-
{
"ipv4": ["ipv4-subnet-route"]
}
labels:
app: subnet-test-app
spec:
containers:
- name: route-test
image: busybox
imagePullPolicy: IfNotPresent
command: ["/bin/sh", "-c", "trap : TERM INT; sleep infinity & wait"]
```

Spiderpool has created fixed IP pools for applications, ensuring that the applications' IPs are automatically fixed within the defined ranges.

```bash
~# kubectl get spiderpool
NAME VERSION SUBNET ALLOCATED-IP-COUNT TOTAL-IP-COUNT DEFAULT DISABLE
auto-subnet-test-app-v4-eth0-d69f2fb7bccf 4 172.18.41.0/24 1 1 false false
~# kubectl get spiderpool auto-subnet-test-app-v4-eth0-d69f2fb7bccf -oyaml
apiVersion: spiderpool.spidernet.io/v2beta1
kind: SpiderIPPool
...
ips:
- 172.18.41.41
podAffinity:
matchLabels:
app: subnet-test-app
routes:
- dst: 172.18.42.0/24
gw: 172.18.41.1
subnet: 172.18.41.0/24
...
```

The Pods are running.

```bash
~# kubectl get pod -l app=subnet-test-app -owide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
subnet-test-app-59df44fc57-clp8t 1/1 Running 0 3m48s 172.18.41.41 spider-worker <none> <none>
```

After the created Pod has obtained an IP from the automatic IPPool, the route set in the subnet, which is inherited by the automatic pool and takes effect in the Pod, you can view it via IP r as follows:

```bash
~# kubectl exec -it route-test-app-bdc84f8f5-2bxbr -- ip r
172.18.41.0/24 dev eth0 scope link src 172.18.41.41
172.18.42.0/24 via 172.18.41.1 dev eth0
- 172.18.41.51-172.18.41.60
gateway: 172.18.41.0
```
### Create IPPool
### Inherit IP Pool Routes
Create a SpiderIPPool and set up the routes for the IPPool, create the Pod and assign IP addresses from the IPPool, you can see the routing information in the ippool pool taking effect within the Pod.
SpiderIPPool resources also support configuring routes (`spec.routes`), which will be inherited by Pods during their creation process:

```bash
kubectl apply -f https://raw.githubusercontent.com/spidernet-io/spiderpool/main/docs/example/route/ippool-route.yaml
```
> - If a gateway address is configured for the SpiderIPPool resource, avoid setting default routes in the routes field.
> - Both `dst` and `gw` fields are required.

```yaml
apiVersion: spiderpool.spidernet.io/v2beta1
Expand All @@ -125,71 +38,26 @@ spec:
subnet: 172.18.41.0/24
ips:
- 172.18.41.51-172.18.41.60
gateway: 172.18.41.0
routes:
- dst: 172.18.42.0/24
gw: 172.18.41.1
```

### Create Deployment By IPPool
### Customize Routes

Create a Deployment whose Pods sets the Pod annotation `ipam.spidernet.io/ippool` to explicitly specify the IPPool.
You can customize routes for Pods by adding the annotation `ipam.spidernet.io/routes`:

```bash
kubectl apply -f https://raw.githubusercontent.com/spidernet-io/spiderpool/main/docs/example/route/ippool-route-deploy.yaml
```
> - When a gateway address or default route is configured in the SpiderIPPool resource, avoid configuring default routes for Pods.
> - Both `dst` and `gw` fields are required.

```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: ippool-test-app
spec:
replicas: 1
selector:
matchLabels:
app: ippool-test-app
template:
metadata:
annotations:
ipam.spidernet.io/ippool: |-
{
"ipv4": ["ipv4-ippool-route"]
}
labels:
app: ippool-test-app
spec:
containers:
- name: route-test
image: busybox
imagePullPolicy: IfNotPresent
command: ["/bin/sh", "-c", "trap : TERM INT; sleep infinity & wait"]
```

The Pods are running.

```bash
~# kubectl get pod -l app=ippool-test-app -owide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
ippool-test-app-66fd47d895-pthx5 1/1 Running 0 45s 172.18.41.53 spider-worker <none> <none>
```

After the created Pod has obtained an IP from IPPool, the route set in IPPool is already in effect in the Pod and you can view it via IP r as follows:

```bash
~# kubectl exec -it ippool-test-app-66fd47d895-pthx5 -- ip r
172.18.41.0/24 dev eth0 scope link src 172.18.41.53
172.18.42.0/24 via 172.18.41.1 dev eth0
```

### Clean up

Clean the relevant resources so that you can run this tutorial again

```bash
kubectl delete \
-f https://raw.githubusercontent.com/spidernet-io/spiderpool/main/docs/example/route/subnet-route.yaml \
-f https://raw.githubusercontent.com/spidernet-io/spiderpool/main/docs/example/route/subnet-route-deploy.yaml \
-f https://raw.githubusercontent.com/spidernet-io/spiderpool/main/docs/example/route/ippool-route.yaml \
-f https://raw.githubusercontent.com/spidernet-io/spiderpool/main/docs/example/route/ippool-route-deploy.yaml \
--ignore-not-found=true
ipam.spidernet.io/routes: |-
[{
"dst": "10.0.0.0/16",
"gw": "192.168.1.1"
},{
"dst": "172.10.40.0/24",
"gw": "172.18.40.1"
}]
```

0 comments on commit 6ff4554

Please sign in to comment.