玩转 Router
Kubeedge - 5: 玩转 Router
什么是 Router
- router 是 KubeEdge 中的一种通过实现 CRDs 来实现与边缘端进行MQTT通信的模式
- 在 KubeEdge 中通过 Rule 和 RuleEndPoint 实现了几种通信模式
配置开启 router
云端(cloud)
- 开启router模式
# 如果你是通过pod安装的cloudcore 查看是否开启
#可以通过kubectl edit pod <cloudcore_name> -n kubeedge 修改
kubectl describe cm cloudcore -n kubeedge.......
router:
enable: true
.......
边缘端(edge)
- 开启
eventbus
和servicebus
vi /etc/kubeedge/config/edgecore.yaml
metaManager:
contextSendGroup: hub
contextSendModule: websocket
enable: true
metaServer:
enable: true
server: 127.0.0.1:10550
tlsCaFile: /etc/kubeedge/ca/rootCA.crt
tlsCertFile: /etc/kubeedge/certs/server.crt
tlsPrivateKeyFile: /etc/kubeedge/certs/server.key
remoteQueryTimeout: 60
serviceBus:
enable: true
port: 9060
server: 127.0.0.1
timeout: 60
什么是 EventBus 和 ServiceBus
EventBus-边缘消息
- 通过MQTT接收外部客户端到消息
- 通过MQTT发送消息
ServiceBus-边缘消息
- 云端通过 beehive 发送消息
- EdgeHub接收消息然后发送给ServiceBus
- ServiceBus 提供http调用然后返回消息
三大消息传递
云到边 - eventbus
- 用户创建源和目标的规则
- 云端APP调用api发送消息,消息到边缘端后通过eventbus 发布到 MQTT Broker
- 边缘端应用收到订阅的相关消息
云到边 - servicebus
- 用户创建源和目标的规则
- 云端 App 调用云端 api 发送消息,到达 servicebus
- servicebus 调用 边缘端 App 的 http API
边的 eventbus ->云
- 用户创建源和目标的规则
- 边缘应用发布消息到 MQTT Broker,eventbus 订阅消息并发布到云端
- 云端应用通过配置 router 中定义的规则得到上述消息
exmaple-rule and endpoint
cloud to edge : rest->eventbus
- cloud-endpoint
apiVersion: rules.kubeedge.io/v1
kind: RuleEndpoint
metadata:
name: my-rest
labels:
description: test
spec:
ruleEndpointType: "rest"
properties: {} - edge-endpoint
apiVersion: rules.kubeedge.io/v1
kind: RuleEndpoint
metadata:
name: my-eventbus
labels:
description: test
spec:
ruleEndpointType: "eventbus"
properties: {} - rule
apiVersion: rules.kubeedge.io/v1
kind: Rule
metadata:
name: my-rule
labels:
description: test
spec:
source: "my-rest"
sourceResource: {"path":"/a"}
target: "my-eventbus"
targetResource: {"topic":"test"}
edge to cloud: eventbus->rest
- cloud-endpoint
apiVersion: rules.kubeedge.io/v1
kind: RuleEndpoint
metadata:
name: my-rest
labels:
description: test
spec:
ruleEndpointType: "rest"
properties: {} - edge-endpoint
apiVersion: rules.kubeedge.io/v1
kind: RuleEndpoint
metadata:
name: my-eventbus
labels:
description: test
spec:
ruleEndpointType: "eventbus"
properties: {} - rule
apiVersion: rules.kubeedge.io/v1
kind: Rule
metadata:
name: my-rule-eventbus-rest
labels:
description: test
spec:
source: "my-eventbus"
sourceResource: {"topic": "test","node_name": "xxx"}
target: "my-rest"
targetResource: {"resource":"http://a.com"}
cloud to edge : rest->servicebus
- cloud-endpoint
apiVersion: rules.kubeedge.io/v1
kind: RuleEndpoint
metadata:
name: my-rest
labels:
description: test
spec:
ruleEndpointType: "rest"
properties: {} - edge-endpoint
apiVersion: rules.kubeedge.io/v1
kind: RuleEndpoint
metadata:
name: my-servicebus
labels:
description: test
spec:
ruleEndpointType: "servicebus"
properties: {"service_port":"6666"} - rule
apiVersion: rules.kubeedge.io/v1
kind: Rule
metadata:
name: my-rule-rest-servicebus
labels:
description: test
spec:
source: "my-rest"
sourceResource: {"path":"/a"}
target: "my-servicebus"
targetResource: {"path":"/b"}
MoreInfo
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 Joohwan!
评论