Skip to content

Commit

Permalink
feat:create worker and env on k8s,according to the DB declaration.
Browse files Browse the repository at this point in the history
  • Loading branch information
2011shenlin committed Oct 27, 2024
1 parent 7bc9451 commit 53b4e1d
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.apache.rocketmq.eventbridge.adapter.runtime.manager.worker.WorkerService;
import org.apache.rocketmq.eventbridge.adapter.runtime.manager.worker.WorkerStatusEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
Expand All @@ -49,6 +50,10 @@ public class WatchWorker {
@Autowired
WorkerInstanceRepository workerInstanceRepository;


@Value("${rocketmq.namesrvAddr}")
private String rmqNamesrvAddr;

private final ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(
new ThreadFactoryImpl(WatchWorker.class.getSimpleName()));

Expand All @@ -71,6 +76,10 @@ public void run() {
put("name", "workerName");
put("value", worker.getName());
}});
env.add(new HashMap<String, String>(){{
put("name", "rocketmq.namesrvAddr");
put("value", rmqNamesrvAddr);
}});
environments.put("env", env);
log.info("applyWorkerInstance, workerName: {}, workerImageTag: {}, workerResource: {}, environments: {}", worker.getName(), worker.getImage(), worker.getResources(), new Gson().toJson(environments));
boolean isApplied = workerInstanceRepository.applyWorkerInstance(worker.getName(), worker.getImage(), new Gson().fromJson(worker.getResources(), WorkerResource.class), environments);
Expand Down
48 changes: 48 additions & 0 deletions docs/cn/RocketMQEventBridgeRunOnK8S.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
## Apache RocketMQ EventBridge Runtime 运行在 kubernetes

本文用来说明如何将EventBridge Runtime运行在kubernetes(以下简称K8S).


![image](https://github.com/apache/rocketmq-eventbridge/assets/8605835/f0763ce9-8193-44ab-a7e4-a8ef5f50e4e6)

前提准备:
* K8S环境
* K8S连接配置:kubeconfig
* Runtime 镜像

### 核心概念
#### Cluster

Cluster 是一个虚拟的概念,用来标注同一类Worker,这类Worker拥有相同的资源配置,镜像版本等。引入Cluster的目的主要包括:

- 资源隔离:不同的Cluster管理不同规模的Worker,同一个Target Runner只能分配到一个Cluster中的一个或多个Worker上;
- 方便Worker管理:Worker的生命周期管理,以Cluster为粒度,我们可以Cluster方便的升级该Cluster下所有的Worker;也可以通过Cluster来控制Worker的数量;

cluster定义在表 event_cluster:
![image](https://github.com/apache/rocketmq-eventbridge/assets/8605835/87008ec6-35db-4ea1-a6b3-593d22f8c14e)

#### Worker
Worker和Runtime的区别是:Runtime代表软件的运行时,而Worker是Runtime运行时的资源节点。Worker定义在表event_worker中:
![image](https://github.com/apache/rocketmq-eventbridge/assets/8605835/4de02958-2c53-4c98-9392-8a79f373089d)

### K8S集群信息
在application.properties中配置K8S集群信息:

```
kubernates.kube.config=xxxx/xxxx.config
```
### 初始化Cluster
在cluster中插入一条cluster的声明:
* name: 集群的名称
* resources: cpu核数为1,内存为1G;
* replica: 副本数
* image: 镜像地址
* md5: 用于标记当前集群的MD5值,判断集群配置是否有更新
![cluster-init-demo.png](images/cluster-init-demo.png)

系统会按照event_cluster表的声明,自动创建Worker资源。

### 检查Worker是否正常被创建
* 检查worker表元素是否被正常创建
![worker-init-demo.png](images/worker-init-demo.png)
* 检查K8S资源是否被正常创建
Binary file added docs/cn/images/cluster-init-demo.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 docs/cn/images/worker-init-demo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 53b4e1d

Please sign in to comment.