Skip to content

Commit

Permalink
make up readme info
Browse files Browse the repository at this point in the history
  • Loading branch information
whalecold committed Aug 26, 2024
1 parent 4edd50d commit 4f7656e
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 4 deletions.
37 changes: 36 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ To enable xDS mode in Kitex, we should invoke `xds.Init()` to initialize the xds
#### Bootstrap
The xdsClient is responsible for the interaction with the xDS Server (i.e. Istio). It needs some environment variables for initialization, which need to be set inside the `spec.containers.env` of the Kubernetes Manifest file in YAML format.

* `POD_NAMESPACE`: the namespace of the current service.
* `POD_NAMESPACE`: the namespace of the current service.
* `POD_NAME`: the name of this pod.
* `INSTANCE_IP`: the ip of this pod.
* `KITEX_XDS_METAS`: the metadata of this xDS node.

Add the following part to the definition of your container that uses xDS-enabled Kitex client.

Expand All @@ -50,6 +51,8 @@ valueFrom:
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: KITEX_XDS_METAS
value: '{"CLUSTER_ID":"Kubernetes","DNS_AUTO_ALLOCATE":"true","DNS_CAPTURE":"true","INSTANCE_IPS":"$(INSTANCE_IP)","NAMESPACE":"$(POD_NAMESPACE)"}'
```

### Client-side
Expand Down Expand Up @@ -231,6 +234,10 @@ spec:
failure_percentage_threshold: 10
# the failure percentage request volume
failure_percentage_request_volume: 101
workloadSelector:
labels:
# the label of the service pod.
app.kubernetes.io/name: kitex-client
```

#### RateLimit
Expand Down Expand Up @@ -267,7 +274,35 @@ spec:
```

#### Retry

```
apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
name: retry-policy
namespace: default
spec:
configPatches:
- applyTo: HTTP_ROUTE
match:
context: SIDECAR_OUTBOUND
patch:
operation: MERGE
value:
route:
retryPolicy:
numRetries: 5
perTryTimeout: 100ms
retryBackOff:
baseInterval: 100ms
maxInterval: 100ms
workloadSelector:
labels:
# the label of the service pod.
app.kubernetes.io/name: kitex-client
```

## Example
The usage is as follows:
Expand Down
34 changes: 33 additions & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ Kitex 通过外部扩展 [kitex-contrib/xds](https://github.com/kitex-contrib/xd
xdsClient 负责与控制面(例如 Istio)交互,以获得所需的 xDS 资源。在初始化时,需要读取环境变量用于构建 node 标识。所以,需要在K8S 的容器配置文件 `spec.containers.env` 部分加入以下几个环境变量。


* `POD_NAMESPACE`: 当前 pod 所在的 namespace。
* `POD_NAMESPACE`: 当前 pod 所在的 namespace。
* `POD_NAME`: pod 名。
* `INSTANCE_IP`: pod 的 ip。
* `KITEX_XDS_METAS`: 用于构建 node 标识的元信息,格式为 json 字符串。

在需要使用 xDS 功能的容器配置中加入以下定义即可:

Expand All @@ -51,6 +52,8 @@ valueFrom:
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: KITEX_XDS_METAS
value: '{"CLUSTER_ID":"Kubernetes","DNS_AUTO_ALLOCATE":"true","DNS_CAPTURE":"true","INSTANCE_IPS":"$(INSTANCE_IP)","NAMESPACE":"$(POD_NAMESPACE)"}'
```

### Kitex 客户端
Expand Down Expand Up @@ -255,6 +258,35 @@ spec:
# 服务实例 pod 的标签,根据实际情况填写
app.kubernetes.io/name: kitex-server
```
#### 重试配置

```
apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
name: retry-policy
namespace: default
spec:
configPatches:
- applyTo: HTTP_ROUTE
match:
context: SIDECAR_OUTBOUND
patch:
operation: MERGE
value:
route:
retryPolicy:
numRetries: 5
perTryTimeout: 100ms
retryBackOff:
baseInterval: 100ms
maxInterval: 100ms
workloadSelector:
labels:
# the label of the service pod.
app.kubernetes.io/name: kitex-client
```

## 示例
Expand Down
4 changes: 2 additions & 2 deletions xdssuite/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func updateRetryPolicy(rc *retrySuit, res map[string]xdsresource.Resource) {
retryPolicy.FailurePolicy.BackOffPolicy = bop
rc.Container.NotifyPolicyChange(cluster.Name, retryPolicy)
// FIXME: The logic of retry is before the router, the value of key RouterClusterKey
// can't be found, use wildcard temporary and set the global policy here. And it recommend
// can't be found, so use wildcard temporarily and set the global policy here. And it recommend
// using envoyfilter to config the retry policy.
wildcarRetryPolicy = retryPolicy.DeepCopy()
}
Expand Down Expand Up @@ -136,7 +136,7 @@ func genRetryServiceKey(ctx context.Context, ri rpcinfo.RPCInfo) string {
}
// the value of RouterClusterKey is stored in route process.
// FIXME: The logic of retry is before the router, the value of key RouterClusterKey
// can't be found, use wildcard temporary.
// can't be found, so use wildcard temporarily.
key, _ := ri.To().Tag(RouterClusterKey)
if key == "" {
return wildcardRetryKey
Expand Down

0 comments on commit 4f7656e

Please sign in to comment.