如何将 Akka 示例集群 kubernetes 与 Scala 和 minikube 一起使用?

How to use the Akka sample cluster kubernetes with Scala and minikube?

我正在尝试 运行 akka-sample-cluster-kubernetes-scala,因为建议使用 akka-management-cluster-bootstrap 将 Akka 集群部署到 minikube。在 运行 README 文件中推荐的每个步骤之后,我可以在我的 kubectl 输出中看到 pods 运行ning:

$ kubectl get pods
NAME                    READY   STATUS    RESTARTS   AGE
appka-8b88f7bdd-485nx   1/1     Running   0          48m
appka-8b88f7bdd-4blrv   1/1     Running   0          48m
appka-8b88f7bdd-7qlc9   1/1     Running   0          48m

当我执行 ./scripts/test.sh 时,最后一步似乎失败了:

"No 3 MemberUp log events found"

而且我无法连接到 README 文件中所述的给定地址。 错误:

$ curl http://127.0.0.1:8558/cluster/members/
curl: (7) Failed to connect to 127.0.0.1 port 8558: Connection refused

从现在开始,我将描述我如何尝试找到无法使用示例 akka + kubernetes 项目的原因。我正在尝试找出上述错误的原因。我想我必须执行 sbt run,即使示例项目中没有提到它。他们在 application.conf:

处收到关于 ${REQUIRED_CONTACT_POINT_NR} 变量的以下错误

[error] Exception in thread "main" com.typesafe.config.ConfigException$UnresolvedSubstitution: application.conf @ jar:file:/home/felipe/workspace-idea/akka-sample-cluster-kubernetes-scala/target/bg-jobs/sbt_12a05599/job-1/target/d9ddd12d/64fe375d/akka-sample-cluster-kubernetes_2.13-0.0.0-70-49d6a855-20210104-1057.jar!/application.conf: 19: Could not resolve substitution to a value: ${REQUIRED_CONTACT_POINT_NR}

#management-config
akka.management {
  cluster.bootstrap {
    contact-point-discovery {
      # pick the discovery method you'd like to use:
      discovery-method = kubernetes-api

      required-contact-point-nr = ${REQUIRED_CONTACT_POINT_NR}
    }
  }
}
#management-config

所以,我想它没有从 kubernetes/akka-cluster.yml 文件中获取配置:name: REQUIRED_CONTACT_POINT_NR。将其更改为 required-contact-point-nr = 34 我收到错误:

[error] SLF4J: A number (4) of logging calls during the initialization phase have been intercepted and are
[error] SLF4J: now being replayed. These are subject to the filtering rules of the underlying logging system.
[error] SLF4J: See also http://www.slf4j.org/codes.html#replay
...
[info] [2021-01-04 11:00:57,373] [INFO] [akka.remote.RemoteActorRefProvider$RemotingTerminator] [] [appka-akka.actor.default-dispatcher-3] - Shutting down remote daemon. MDC: {akkaAddress=akka://appka@127.0.0.1:25520, sourceThread=appka-akka.remote.default-remote-dispatcher-9, akkaSource=akka://appka@127.0.0.1:25520/system/remoting-terminator, sourceActorSystem=appka, akkaTimestamp=10:00:57.373UTC}
[info] [2021-01-04 11:00:57,376] [INFO] [akka.remote.RemoteActorRefProvider$RemotingTerminator] [] [appka-akka.actor.default-dispatcher-3] - Remote daemon shut down; proceeding with flushing remote transports. MDC: {akkaAddress=akka://appka@127.0.0.1:25520, sourceThread=appka-akka.remote.default-remote-dispatcher-9, akkaSource=akka://appka@127.0.0.1:25520/system/remoting-terminator, sourceActorSystem=appka, akkaTimestamp=10:00:57.375UTC}
[info] [2021-01-04 11:00:57,414] [INFO] [akka.remote.RemoteActorRefProvider$RemotingTerminator] [] [appka-akka.actor.default-dispatcher-3] - Remoting shut down. MDC: {akkaAddress=akka://appka@127.0.0.1:25520, sourceThread=appka-akka.remote.default-remote-dispatcher-9, akkaSource=akka://appka@127.0.0.1:25520/system/remoting-terminator, sourceActorSystem=appka, akkaTimestamp=10:00:57.414UTC}
[error] Nonzero exit code returned from runner: 255
[error] (Compile / run) Nonzero exit code returned from runner: 255
[error] Total time: 6 s, completed Jan 4, 2021 11:00:57 AM

由于您正在尝试使用 sbt run,因此您收到联系点错误。 sbt run 将 运行 minikube 之外的单个实例,这不是您想要的。而且由于它 运行ning 在 Minikube 之外,因此它不会获取容器规范中设置的环境变量。脚本执行 build/deploy,您不需要手动 运行 sbt。

此外,主要错误不是与 8558 的连接,我不认为配置会在 minikube 之外公开该管理端口。

所有三个容器都报告状态 运行 的事实表明您实际上可能有一个 运行ning 集群,测试脚本可能只是缺少日志中的消息。正如其他人在评论中所说,来自其中一个容器的日志将有助于确定您是否有一个工作集群,并诊断集群形成中的任何问题。

我的问题的答案和评论是正确的。我不需要 运行 sbt run 来可视化网络浏览器的输出。我缺少的是 port-forward 集群节点的当前端口到输出端口。这在 akka-sample-cluster-kubernetes-scala 上没有指定,但我相信这是因为它们 运行 直接在 Google Kubernetes Engine 平台上,而不是首先在 minikube 内部。

$ kubectl get pods -A
NAMESPACE     NAME                                        READY   STATUS      RESTARTS   AGE
appka-1       appka-8b88f7bdd-97zfl                       1/1     Running     0          9m10s
appka-1       appka-8b88f7bdd-bhv44                       1/1     Running     0          9m10s
appka-1       appka-8b88f7bdd-ff76s                       1/1     Running     0          9m10s
$ #### THIS COMMAND IS NOT IN THE README FILE OF THE DEMO ####
$ kubectl port-forward appka-8b88f7bdd-ff76s 8080
Forwarding from 127.0.0.1:8080 -> 8080
Forwarding from [::1]:8080 -> 8080

现在我可以看到输出:

$ http GET http://127.0.0.1:8080/
HTTP/1.1 200 OK
Content-Length: 11
Content-Type: text/plain; charset=UTF-8
Date: Wed, 06 Jan 2021 10:59:40 GMT
Server: akka-http/10.2.1

Hello world