kubernetes内部使用Scala Akka的服务发现
我面临着使用Akka进行服务发现的问题。我最近将我的应用程序从Kubernetes版本1.18迁移到1.21。服务发现在较旧版本上工作正常,但似乎在1.21版上不起作用。以下是错误日志: -
play.api.UnexpectedException: Unexpected exception[IllegalStateException: Service ${serviceName} was not found by service locator]
at play.api.http.HttpErrorHandlerExceptions$.throwableToUsefulException(HttpErrorHandler.scala:358)
at play.api.http.DefaultHttpErrorHandler.onServerError(HttpErrorHandler.scala:264)
at play.core.server.AkkaHttpServer$$anonfun$2.applyOrElse(AkkaHttpServer.scala:430)
at play.core.server.AkkaHttpServer$$anonfun$2.applyOrElse(AkkaHttpServer.scala:422)
at scala.concurrent.impl.Promise$Transformation.run(Promise.scala:454)
at akka.dispatch.BatchingExecutor$AbstractBatch.processBatch(BatchingExecutor.scala:63)
at akka.dispatch.BatchingExecutor$BlockableBatch.$anonfun$run$1(BatchingExecutor.scala:100)
at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
at scala.concurrent.BlockContext$.withBlockContext(BlockContext.scala:94)
at akka.dispatch.BatchingExecutor$BlockableBatch.run(BatchingExecutor.scala:100)
配置文件看起来像: -
akka.management {
cluster.bootstrap {
contact-point-discovery {
discovery-method = kubernetes-api
service-name = ${serviceName}
required-contact-point-nr = ${REQUIRED_CONTACT_POINT_NR}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,确保您的如有记录。到目前为止,这是最常见的错误:不给予发现机制适当的权限。
其次,尝试手动指定
POD-LABEL-SELECTOR
而不是指定服务名称。这就是我最近所做的事情,也是文档中的默认值。因此,也许您处于无权查询无头服务的情况下,但是您可以直接通过POD-Label-Selector查询POD。从根本上说,它在做什么是微不足道的。它正在针对K8S API运行一个非常简单的查询(并且可以手动指定),并获得了POD IP的列表。 (然后,它进入了Akka群集机制,在其中它可以做更复杂的事情来建立和修改群集,但是此查询非常简单。)因此,从根本上讲,唯一可能是错误的事情是:
First, make sure that your Role and Rolebinding are correct, as documented. This is, by far, the most common mistake: not giving the discovery mechanism the proper permissions.
Secondly, try manually specifying the
pod-label-selector
rather than specifying a service-name. This is what I've done recently and what the defaults are in the docs. So maybe you are in a situation where you don't have permission to query the headless service, but you can query the pods directly via the pod-label-selector.Fundamentally what it's doing is trivial. It's running an extremely simple query (and that you can specify manually) against the K8S API and getting a list of Pod IPs back. (Which it then passes into the Akka Cluster mechanism where it does much more complex things to establish and modify the cluster, but this query is super simple.) So fundamentally, the only things that can be wrong are: