如何在k8和微服务之间相互访问 [英] How to access each other between k8s and microservices

查看:988
本文介绍了如何在k8和微服务之间相互访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用K8S部署,我们的项目基于springcloud.我想知道,在K8S中,因为多节点部署会通过注册表的默认主机名,所以网关部署在A中,配置部署在B中.它们以前无法通过eureka相互访问.我更改为eureka.instance.prefer-ip-address: true,但是我发现它们只能在同一主机上相互访问.他没有使用K8S的cluster-ip.我想知道如何在K8S的服务之间相互访问.

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.

推荐答案

在Activiti Cloud的7-201712-EA版本中,我们提供了一个使用在kubernetes中运行netflix库的服务的示例-稳定的使用k8s服务名称向eureka注册.

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.

为确保组件为eureka声明了正确的服务名称,我们或使用默认环境变量

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.

这篇关于如何在k8和微服务之间相互访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆