kubernetes内部使用Scala Akka的服务发现

发布于 2025-02-11 19:55:47 字数 2193 浏览 0 评论 0 原文

我面临着使用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}
    }
  }

I am facing issues with working with service discovery using akka. I recently migrated my application from Kubernetes version 1.18 to 1.21 . Service discovery is working fine on the older version but it doesn't seem to work on version 1.21. Below are the error log:-

 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)              

Config file looks like:-

akka.management {
  cluster.bootstrap {
    contact-point-discovery {
      discovery-method = kubernetes-api
      service-name = ${serviceName}
      required-contact-point-nr = ${REQUIRED_CONTACT_POINT_NR}
    }
  }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怪我鬧 2025-02-18 19:55:47

首先,确保您的如有记录。到目前为止,这是最常见的错误:不给予发现机制适当的权限。

其次,尝试手动指定 POD-LABEL-SELECTOR 而不是指定服务名称。这就是我最近所做的事情,也是文档中的默认值。因此,也许您处于无权查询无头服务的情况下,但是您可以直接通过POD-Label-Selector查询POD。

从根本上说,它在做什么是微不足道的。它正在针对K8S API运行一个非常简单的查询(并且可以手动指定),并获得了POD IP的列表。 (然后,它进入了Akka群集机制,在其中它可以做更复杂的事情来建立和修改群集,但是此查询非常简单。)因此,从根本上讲,唯一可能是错误的事情是:

  • 查询是错误的。 (要么您的查询不存在,要么查询中有错字或暗示查询。)
  • 查询的权限是错误的,因此您的ServiceAccount可以执行查询。

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:

  • The query is wrong. (Either the thing your querying doesn't exist or there is a typo in your query or implied query.)
  • The permissions on your query are wrong such that your serviceaccount can execute the query.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文