EventMesh 与 K8S 集成

1. 依赖

  1. docker
  2. golang (version 1.19)
  3. kubernetes (kubectl)
  4. kubernetes docker 之间有一定的兼容性,请检查它们之间的版本兼容性,并下载相应的版本,以确保它们能一起正常工作。

2. 启动

进入 eventmesh-operator 目录。

  1. cd eventmesh-operator

将 CRD 安装到 k8s 集群。

  1. make install
  2. # Uninstall CRDs from the K8s cluster
  3. make uninstall

如果出现错误eventmesh-operator/bin/controller-gen: No such file or directory,运行以下命令:

  1. # 如有必要,在本地下载 controller-gen.
  2. make controller-gen
  3. # 如有必要,在本地下载 kustomize.
  4. make kustomize

查看 crds 信息:

  1. # 运行以下命令查看 crds 信息:
  2. kubectl get crds
  3. NAME CREATED AT
  4. connectors.eventmesh-operator.eventmesh 2023-11-28T01:35:21Z
  5. runtimes.eventmesh-operator.eventmesh 2023-11-28T01:35:21Z

创建和删除 CRs:

自定义资源对象位于:/config/samples

删除 CR,只需将create替换为delete即可。

  1. # 为 eventmesh-runtime、eventmesh-connector-rocketmq 创建 CR, 创建 clusterIP 可让 eventmesh-runtime 与其他组件通信。
  2. make create
  3. #success:
  4. configmap/runtime-config created
  5. runtime.eventmesh-operator.eventmesh/eventmesh-runtime created
  6. service/runtime-cluster-service created
  7. configmap/connector-rocketmq-config created
  8. connectors.eventmesh-operator.eventmesh/connector-rocketmq created
  9. # 查看创建的 service.
  10. kubectl get service
  11. NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
  12. runtime-cluster-service ClusterIP 10.109.209.72 <none> 10000/TCP 17s
  13. # Delete CR
  14. make delete

运行 eventmesh-operator 创建 pods。

  1. # run controller
  2. make run
  3. # log
  4. go fmt ./...
  5. go vet ./...
  6. go run ./main.go
  7. INFO controller-runtime.metrics Metrics server is starting to listen {"addr": ":9020"}
  8. INFO setup starting manager
  9. INFO Starting server {"kind": "health probe", "addr": "[::]:8081"}
  10. INFO Starting server {"path": "/metrics", "kind": "metrics", "addr": "[::]:9020"}
  11. INFO runtime Creating a new eventMeshRuntime StatefulSet. {"StatefulSet.Namespace": "default", "StatefulSet.Name": "eventmesh-runtime-0-a"}
  12. INFO connector Creating a new Connector StatefulSet. {"StatefulSet.Namespace": "default", "StatefulSet.Name": "connector-rocketmq"}
  13. INFO runtime Successful reconciliation!
  14. INFO connector Successful reconciliation!
  15. # 成功启动 pod 后,运行以下命令查看 pod。
  16. kubectl get pods
  17. NAME READY STATUS RESTARTS AGE
  18. connector-rocketmq-0 1/1 Running 0 12m
  19. eventmesh-runtime-0-a-0 1/1 Running 0 12m