【问题标题】:Ideas to configure the application.server param dynamically for Kafka Streams remote interactive queries on a spring boot app running on Kubernetes在 Kubernetes 上运行的 Spring Boot 应用程序上为 Kafka Streams 远程交互式查询动态配置 application.server 参数的想法
【发布时间】:2018-08-24 06:22:18
【问题描述】:

我正在 Kubernetes 上部署一个 Kafka Streams 应用程序,复制为多个 pod。这个 pod 被暴露为 Kubernetes 服务,所以我有一个公共入口点来负载平衡流量:myapp:8080

关键是我想运行一个可以远程的交互式查询,所以我根据documentation进行了设置

Web 层由运行在 8080 端口上的 Spring Boot 应用程序提供。

我的问题是如何动态配置 application.server 参数,每个 pod 都有一个唯一的端点。

更新:

我想我需要用分配给每个 pod 的 kubernetes 端点的值来配置 application.server

$>kubectl get ep
NAME                    ENDPOINTS                       AGE
myapp   10.8.2.85:8080,10.8.2.88:8080   10d
  • Pod1 -> application.server= 10.8.2.85:8080
  • Pod2 -> application.server= 10.8.2.88:8080

但是打印应用程序的System.getEnv()我只有kubernetes服务的ip和端口,没有分配的pod端点:

MYAPP_SERVICE_PORT=8080
MYAPP_SERVICE_HOST=10.11.248.5
...

那么如何获取 pod 的 kubernetes 端点呢?

【问题讨论】:

    标签: kubernetes apache-kafka apache-kafka-streams


    【解决方案1】:

    我已经能够通过以这种方式将其添加为环境变量来获取每个 pod 的端点 ip:

    kubernetes 部署:

    spec:
      ...
      template:
        spec:
          containers:
            - env:
              - name: POD_IP
                valueFrom:
                  fieldRef:
                    fieldPath: status.podIP
              ...
    

    现在我可以访问 pod ip/port 并将其分配给应用程序的每个实例中的 application.server 参数:

    private final Environment environment;
    
    @Autowired
    public SomeController(Environment environment) {
        this.environment = environment;
    }
    
    ...
    props.put(StreamsConfig.APPLICATION_SERVER_CONFIG, System.getEnv("POD_IP") + ":" + environment.getProperty("local.server.port"));
    

    【讨论】:

    • 嗨@codependent,当您在Kubernetes上部署其他Kafka Stream实例(2个应用程序实例)时,您是否有任何访问问题?使用 podIP + 端口我得到一个 404 未找到外部休息 api 的请求
    • 您的 pod 是否属于您在部署时指定 ReplicaSet=2 的同一个服务?端口与您在 kubectl get svc 中看到的 local.server.port 相同吗?
    猜你喜欢
    • 2020-12-02
    • 2019-08-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-31
    • 1970-01-01
    • 1970-01-01
    • 2021-01-24
    • 1970-01-01
    相关资源
    最近更新 更多