简体   繁体   English

有没有一种方法可以在K8S服务发现中注册服务的自定义元数据?

[英]Is there a way to register custom metadata for a service in K8S Service Discovery?

I have my service (spring boot java application) running in a K8S cluster with 3 replicas(pods). 我的服务(春季启动Java应用程序)在具有3个副本(pod)的K8S集群中运行。 My use-case requires me to deploy application contexts dynamically. 我的用例要求我动态地部署应用程序上下文。 And i need to know which context is deployed on which of the 3 Pods through service discovery. 我需要通过服务发现来了解在3个Pod中的哪个部署了哪个上下文。 Is there a way to register custom metadata for a service in K8S Service Discovery, like we do in Eureka using eureka.instance.metadata-map? 有没有办法像在Eureka中那样使用eureka.instance.metadata-map在K8S Service Discovery中注册服务的自定义元数据?

In terms of Kubernetes, we have Deployments and Services. 就Kubernetes而言,我们有Deployments和Services。

Deployment is a description of state for ReplicaSet, which creates Pods. 部署是对ReplicaSet(创建Pods)的状态的描述。 Pod consists of one or more containers. Pod由一个或多个容器组成。

Service is an abstraction which defines a logical set of Pods and a policy by which to access them. 服务是一种抽象,定义了Pod的逻辑集和访问Pod的策略。

In Eureka, you can set a configuration of Pods dynamically and reconfigure them on-fly, which does not match with Kubernetes design. 在Eureka中,您可以动态设置Pod的配置并即时对其进行重新配置,这与Kubernetes设计不匹配。

In Kubernetes, when you use 1 Deployment with 3 Replicas, all 3 Pods should be the same. 在Kubernetes中,当您将1个Deployment与3个副本一起使用时,所有3个Pod应该都相同。 It has no options or features to export any metadata for separate Pods under the Services into different groups because ReplicaSet, which contain Pods with same labels, is a group itself. 它没有选项或功能可将服务下单独的Pod的任何元数据导出到不同的组中,因为包含具有相同标签的Pod的ReplicaSet本身就是一个组。

Therefore, the better idea is to use 3 different Deployments with 1 Replica for each, all of them with the same configuration. 因此,更好的主意是使用3个不同的部署,每个部署1个副本,所有部署都具有相同的配置。 Or use some Springboot's features, like its service discovery if you want to reload application context on-fly. 或者,如果您想即时重新加载应用程序上下文,请使用一些Springboot的功能,例如其服务发现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法通过 k8s 服务卷曲 http rest api - Not able to curl an http rest api through a k8s service K8s 中 statefulSet 的 Mongo 连接 URI,每个副本(pod)还是(无头)服务? - Mongo connection URI for statefulSet in K8s, each replica (pod) or the (headless) service? Istio 服务发现 - Istio Service discovery 服务发现中的 eureka unknownHostException - eureka unknownHostException in service discovery Spring服务发现限制 - Spring Service Discovery Restriction Kubernetes 中的服务发现 - Service Discovery within Kubernetes 有没有一种方法可以在localhost和Kubernetes上工作而无需更改代码行? - Is there a way of Service Discovery that works on localhost and Kubernetes without changing a line of code? Kubernetes 集群 - 无法从 spring 启动服务访问在一个 pod 中运行的 Kafka 代理,该服务在多 VM k8s 集群中的另一个 pod 中运行 - Kubernetes cluster - Cannot access Kafka broker running in a pod from spring boot service running in another pod in multi VM k8s cluster Spring Boot Zuul:如何在没有应用前缀的情况下在发现服务中注册多个 MS - Spring Boot Zuul: How to register multiple MS in discovery service without app prefix 使用 spring webflux WebClient 发现服务 - Service discovery with spring webflux WebClient
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM