Zuul Deployment in Kubernetes
In kubernetes you already have "discovery" service which is kubernetes-service. It locates pods and serves as load balancer for them.
Lets say you have Zuul configuration like this:
zuul: routes: books-service: path: /books/** serviceId: books-service
which routes requests matching /books/**
to the service books-service
. Usually you have an Eureka which gives you real address of books-service
, but not now.
And this is where Ribbon can help you - it allows you to manually tune routing after Zuul has matched it's request. So you need to add this to configuration:
books-service.ribbon.listOfServers: "http://books:8080"
and after Zuul had found serviceId (books-service
) it will route the request to books:8080
And books:8080
is just a kubernetes-service:
kind: ServiceapiVersion: v1metadata: name: booksspec: selector: app: spring-books-service ports: - protocol: TCP port: 8080 targetPort: 9376
You can say its a load balancer that takes traffic from :8080 and redirects it to pods with label app: spring-books-service
.
All you have to do next is to assign labels to pods (via deployments for example)
Btw, you can configure Ribbon like this in any app and kubernetes will locate all your apps (pods) with its services so you dont need any discovery service at all! And since k8s-services are much more reliable than Eureka, you can simply remove it.