2

Using K8S deployment, our project is based on springcloud. I want to know that in K8S, because the multi-node deployment passes the default host name of the registry, the gateway is deployed in A, and the config is deployed in B. They can't access each other through eureka before. I changed to eureka.instance.prefer-ip-address: true, but I found that they can only access each other on the same host. He is not using cluster-ip of K8S. I want to know how to access each other between services in K8S.

Calm
  • 119
  • 1
  • 10
  • Check what IPs are being advertised into Eureka? It would have to be the pod's public IP. That said, Eureka is not common in K8s since usually you use the Service system and cluster DNS for managing service discovery :) – coderanger Jan 03 '19 at 09:09
  • Thanks, I am trying to restrict the service registration to eureka's ip address so that other services in the cluster can access it. – Calm Jan 03 '19 at 09:25
  • You could use the service names to register with eureka instead of IPs. See https://stackoverflow.com/questions/52066141/zuul-unable-to-route-traffic-to-service-on-kubernetes There's an example of this in https://github.com/Activiti/activiti-cloud-examples/tree/7-201712-EA (though the latest version of that project no longer uses netflix) – Ryan Dawson Jan 03 '19 at 09:47
  • What you mean is that the name I registered in my eureka is the service name in the k8s of my service? – Calm Jan 03 '19 at 10:06
  • I has read another question,and I should set eureka.instance.hostname=k8s_servername:service_port? – Calm Jan 03 '19 at 10:17
  • Yes, I mean to register with the service name. We were using just service name when we were doing this on activiti - https://github.com/Activiti/example-runtime-bundle/blob/7-201712-EA/src/main/resources/application.properties#L35 used in https://github.com/Activiti/activiti-cloud-examples/blob/7-201712-EA/kubernetes/kubectl/application.yml#L158 – Ryan Dawson Jan 03 '19 at 10:50
  • @Calm I remembered why we didn't need to do anything special with the port - it's because we used the same port for java app and for service. Have put in an answer to make this clear. – Ryan Dawson Jan 05 '19 at 11:09
  • I have already seen it, thank you very much for your answer. – Calm Jan 06 '19 at 12:14

2 Answers2

3

In version 7-201712-EA of Activiti Cloud we provided an example using services running the netflix libraries in kubernetes - the stable github tags and docker images are available to refer to. We approached it by creating Kubernetes Services for each component and getting the component to register with eureka using the k8s service name.

To make sure the component declared the correct service name to eureka we set the eureka.instance.hostname in the component, which can be set in the Deployment yaml by specifying an environment variable or using the default environment variable EUREKA_INSTANCE_HOSTNAME. We also kept thing simple by using the same port for the java app in the Pod and for the Service. Again this can be set to match by setting the port in the Pod spec and passing the SERVER_PORT environment variable to the spring boot app.

Ryan Dawson
  • 11,832
  • 5
  • 38
  • 61
1

Check the spring-cloud-kubernetes project

salaboy
  • 4,123
  • 1
  • 14
  • 15