本文介绍了尤里卡和Kubernetes的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在整理一个概念证明,以帮助一起使用Spring Boot/Netflix OSS和Kubernetes识别陷阱.这也是为了证明相关技术,例如Prometheus和Graphana.

我有一个Eureka服务设置,在我的Kubernetes集群中毫无问题的开始.使用

将其添加到K8时,它被称为发现,并被命名为"discovery-1551420162-iyz2c".

kubectl run discovery --image=xyz/discovery-microservice --replicas=1 --port=8761

对于我的配置服务器,我正在尝试基于逻辑URL使用Eureka,因此在我的bootstrap.yml中有

server:
  port: 8889

eureka:
  instance:
    hostname: configserver
  client:
    registerWithEureka: true
    fetchRegistry: true
    serviceUrl:
      defaultZone: http://discovery:8761/eureka/

spring:
  cloud:
    config:
      server:
        git:
          uri: https://github.com/xyz/microservice-config

我正在使用

kubectl run configserver --image=xyz/config-microservice --replicas=1 --port=8889

此服务最终运行名为configserver-3481062421-tmv4d.然后,我在配置服务器日志中看到异常,因为它试图找到eureka实例,但是找不到.

我使用带有链接的docker-compose在本地进行了相同的设置,并且启动了各种容器都没有问题.

discovery:
  image: xyz/discovery-microservice
  ports:
   - "8761:8761"
configserver:
  image: xyz/config-microservice
  ports:
   - "8888:8888"
  links:
   - discovery

我应该如何设置eureka.client.serviceUri之类的东西,以便我的微服务可以在不知道K8群集内固定IP地址的情况下找到其对等对象?

解决方案

您必须在eureka pods/deployments顶部有一个Kubernetes 服务然后,它将为您提供一个可参考的IP地址和端口号.然后使用该可引用地址查找Eureka服务,而不是"8761".

要进一步解决有关尤里卡(Eureka)HA配置的问题

每个k8s服务不应有一个以上的尤里卡吊舱/副本(请记住,吊舱是短暂的,尤里卡服务注册表需要一个可参考的IP地址/域名).为了实现高可用性(HA),请在每个中包含一个Pod的情况下启动更多k8s服务.

  • 尤里卡服务1->单个吊舱
  • Eureka服务2->另一个豆荚
  • ..
  • ..
  • Eureka服务n->另一个豆荚

因此,现在您对每个Eureka都有一个可参考的IP/域名(k8s服务的IP).现在它可以相互注册了.

觉得这是一个过大的杀伤力?如果您所有的服务都在同一个kubernetes命名空间中,则可以通过k8s服务+ KubeDNS附加组件来实现eureka提供的所有功能(嗯,几乎所有的功能,除了客户端负载平衡).阅读Christian Posta撰写的文章 >

编辑

您可以使用 StatefulSets 如 Stefan Ocke 所指出.

I am putting together a proof of concept to help identify gotchas using Spring Boot/Netflix OSS and Kubernetes together. This is also to proove out related technologies such as Prometheus and Graphana.

I have a Eureka service setup which is starting with no trouble within my Kubernetes clouster. This is named discovery and has been given the name "discovery-1551420162-iyz2c" when added to K8 using

kubectl run discovery --image=xyz/discovery-microservice --replicas=1 --port=8761

For my config server, I am trying to use Eureka based on a logical URL so in my bootstrap.yml I have

server:
  port: 8889

eureka:
  instance:
    hostname: configserver
  client:
    registerWithEureka: true
    fetchRegistry: true
    serviceUrl:
      defaultZone: http://discovery:8761/eureka/

spring:
  cloud:
    config:
      server:
        git:
          uri: https://github.com/xyz/microservice-config

and I am starting this using

kubectl run configserver --image=xyz/config-microservice --replicas=1 --port=8889

This service ends up running named as configserver-3481062421-tmv4d. I then see exceptions in the config server logs as it tries to locate the eureka instance and cannot.

I have the same setup for this using docker-compose locally with links and it starts the various containers with no trouble.

discovery:
  image: xyz/discovery-microservice
  ports:
   - "8761:8761"
configserver:
  image: xyz/config-microservice
  ports:
   - "8888:8888"
  links:
   - discovery

How can should I setup something like eureka.client.serviceUri so my microserices can locate their peers without knowing fixed IP addresses within the K8 cluster?

解决方案

You have to have a Kubernetes service on top of the eureka pods/deployments which then will provide you a referable IP address and port number. And then use that referable address to look up the Eureka service, instead of "8761".

To address further question about HA configuration of Eureka

You shouldn't have more than one pod/replica of Eureka per k8s service (remember, pods are ephemeral, you need a referable IP address/domain name for eureka service registry). To achieve high availability (HA), spin up more k8s services with one pod in each.

  • Eureka service 1 --> a single pod
  • Eureka Service 2 --> another single pod
  • ..
  • ..
  • Eureka Service n --> another single pod

So, now you have referable IP/Domain name (IP of the k8s service) for each of your Eureka.. now it can register each other.

Feeling like it's an overkill?If all your services are in same kubernetes namespace you can achieve everything (well, almost everything, except client side load balancing) that eureka offers though k8s service + KubeDNS add-On. Read this article by Christian Posta

Edit

Instead of Services with one pod each, you can make use of StatefulSets as Stefan Ocke pointed out.

这篇关于尤里卡和Kubernetes的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-26 11:52