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

6/14/2018

I have my service (spring boot java application) running in a K8S cluster with 3 replicas(pods). 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. 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?

-- Kushal Kale
azure-kubernetes
kubernetes
service-discovery
spring-boot
spring-cloud

1 Answer

6/15/2018

In terms of Kubernetes, we have Deployments and Services.

Deployment is a description of state for ReplicaSet, which creates Pods. Pod consists of one or more containers.

Service is an abstraction which defines a logical set of Pods and a policy by which to access them.

In Eureka, you can set a configuration of Pods dynamically and reconfigure them on-fly, which does not match with Kubernetes design.

In Kubernetes, when you use 1 Deployment with 3 Replicas, all 3 Pods should be the same. 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.

Therefore, the better idea is to use 3 different Deployments with 1 Replica for each, all of them with the same configuration. Or use some Springboot’s features, like its service discovery if you want to reload application context on-fly.

-- Artem Golenyaev
Source: StackOverflow