spring zuul gateway in kubernetes - spring

I am introducing in microservices with spring and kubernetes.
I have gateway services made with spring-cloud-starter-netflix-zuul that works like an apigateway
I define Zull gateway like this:
server:
port: 8080
use-forward-headers: true
security:
basic:
enabled: false
oauth2:
resource:
jwk.key-set-uri: ${OAUTH_KEYSETURI}
spring:
config:
name: proxy-service
application:
name: proxy-service
zuul:
routes:
service-one:
path: /service-one/**
url: http://service-one:8080
serviceId: service-one
service-two:
path: /service-two/**
url: http://service-two:8080
serviceId: service-two
ribbon:
eureka:
enabled: false
eureka:
client:
enabled: false
error:
whitelabel:
enabled: false
But I found some problems, for example, that the requests have a limit per service, so I added the following lines:
zuul:
host:
max-per-route-connections: 100000
max-total-connections: 100000
I want to know. What is the most performant way to integrate spring-zuul with Kubernetes? I have read that it can also be integrated with spring-kubernetes-config, ribbon, and eureka. But doing it is more performant?
Recently I also read about spring-cloud-gateway. What is the difference with this project? Why spring has two gateway projects very similar? Are there differences in performance? Will both be supported in the future? What do you recommend to use?

Related

Deployment issue on Heroku : zuul + eureka + microservices

Thanks for taking the time to read my post.
My issue is as such. I have 2 microservices (auth-service and image-service) deployed on Heroku, as well as a server Eureka and a gateway Zuul.
In local, all of this works.
However, when deployed, the same calls give me 404 errors : for example :
zuul is deployed on port 8762 in local,
so http://localhost:8762/images/user/create works, it points to http://localhost:8200/user/create of the image-service.
Deployed, https://croquis-time-image.herokuapp.com/user/create works, but https://croquis-time-zuul.herokuapp.com/images/user/create throws a 404 error.
On eureka however, all my services are registered, so the trouble doesn't come from there. I thought perhaps zuul didn't manage to get all the services from Eureka, but I'm not sure how to check.
More information :
application.yml of zuul deployed :
server:
port: 8762
eureka:
client:
serviceUrl:
defaultZone: https://croquis-time-eureka.herokuapp.com/eureka/
instance:
hostName: croquis-time-eureka.herokuapp.com
zuul:
#Service will be mapped under the /api URI
prefix: /api
# Uncomment to disable auto-registering all services read from Eureka
# ignoredServices: '*'
routes:
image-service:
path: /images/**
serviceId: image-service
auth-service:
path: /auth/**
serviceId: auth-service
stripPrefix: false
sensitiveHeaders: Cookie,Set-Cookie
spring:
application:
name: zuul-server
security:
jwt:
uri: /auth/**
prefix: Bearer
expiration: 86400
header: Authorization
secret: *****************
The application.yml of eureka deployed
server:
port: 8761
eureka:
instance:
hostname: croquis-time-eureka.herokuapp.com
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: https://croquis-time-eureka.herokuapp.com/eureka/
spring:
application:
name: eureka-server
The image service I'm trying to call :
server:
port: 8200
eureka:
client:
serviceUrl:
defaultZone: https://croquis-time-eureka.herokuapp.com/eureka/
instance:
hostName: croquis-time-eureka.herokuapp.com
spring:
application:
name: image-service
jpa:
showSql: true
hibernate:
ddlAuto: update
datasource:
url: jdbc:mysql://***********:3306/croquis-time
username: ******************
password: ****************
I have tried removing and adding the "ignored-services" from zuul to see if that was the problem, but it didn't change anything.
I'm very willing to edit my question with more information if you require more, I'm not sure where is the origin of the problem, so I'm a bit at a loss as to what to add.
Thanks !
you have an issue with the configuration of .yml in zuul server
Your .yml of zuul server must be:
instance:
hostName: croquis-time-zuul.herokuapp.com
And your .yml of image must be:
instance:
hostName: croquis-time-image.herokuapp.com
because instance.hostname is the host of your application acting as the eureka client. if you need more information please visit: https://blog.heroku.com/managing_your_microservices_on_heroku_with_netflix_s_eureka

Multiple Configuration for Spring Cloud Load Balancer

Similar question asked in Spring Cloud Load Balancer multiple configurations.
I want to use health-check and same-instance-preference configurations for spring cloud load balancer at the same time. Unable to give mutiple configurations.
I am using SimpleDiscoveryClient for listing out the instances. Additionally, if both these configurations are clubbed, can it be a replacement for sticky session loadbalancer rule?
Posting my yml here:
spring:
application:
name: sample
cloud:
discovery:
client:
health-indicator:
enabled: false
simple:
instances:
test-service:
- uri: http://localhost:8082
- uri: http://localhost:8081
loadbalancer:
# configurations: health-check
configurations: same-instance-preference
sticky-session:
add-service-instance-cookie: true
cache:
enabled: false
health-check:
path:
default: /actuator/health
interval: 10000
gateway:
routes:
- id: test_routing
path: /user/*
uri: lb://test-service
predicates:
- Method=GET,POST
- Path=/user/**
server:
port: 45000

Error "Load balancer does not have available server for client" when using zuul and eureka

I have a couple of microservices on Heroku - eureka-server, Zuul server and some app services.
While I am trying to reach any of my services, for example, "service1" via Zuul gateway, Zuul is unable to forward the request to the respective service (when I'm trying to run them locally everything works fine).
I've found the following errors in Zuul logs:
com.netflix.zuul.exception.ZuulException: Forwarding error
Caused by: com.netflix.client.ClientException: Load balancer does not have the available server for the client: service1
Below are configurations of my services:
1) "zuul server" application.yml
server:
port: ${PORT:8000}
zuul:
prefix: /api
ignoredServices: '*'
routes:
service1:
path: /path_for_service1/**
serviceId: service1
strip-prefix: false
...
management:
endpoints:
web:
exposure:
include: "*"
eureka:
client:
serviceUrl:
defaultZone: ${EUREKA_URL:http://localhost:5000}/eureka/
2) "eureka server" application.yml
server:
port: ${PORT:5000}
eureka:
instance:
hostname: localhost
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
3.1) "service1" application.yml
server.port=${PORT:8081}
eureka.client.service-url.defaultZone=${EUREKA_URL:http://localhost:5000}/eureka/
3.2) "service1" bootstrap.yml
spring:
application:
name: service1
All microservices are visible in eureka dashboard.
If I change zuul routes to hard-coded url it works well but it is not what I'm looking for.
zuul:
prefix: /api
ignoredServices: '*'
routes:
service1:
path: /path_for_service1/**
url: http://url_of_service_1
strip-prefix: false
Could you please help me with this issue?
Finally, I've found root cause :)
All services are registered in eureka using heroku hostname by default (like "085930c7-b893-4b34-88a7-6e37fbe7fa0f") which is not accessible outside.
But services are accessible by domain names.
So I just added domain name settings to application.properties of each service (https://blog.heroku.com/managing_your_microservices_on_heroku_with_netflix_s_eureka)
eureka:
instance:
non-secure-port: 80
hostname: ${DOMAIN_NAME}
and now it works.

Spring Discovery First Bootstrap doesn't find ConfigServer

Currently I am running Spring Boot Services with Discovery First.
Starting the services one after another works just fine, but I am having issues starting the services all at once via docker-compose.
The discovery first bootstrap seems to not work as I expected. I would assume that the service would halt / retry till he receives the configuration from the configuration service, which has been discovered via eureka. But currently it will try to resolve the configuration once and then the service will start immediately after - no matter if a configuration has been brought or not.
The service bootstrap looks as following:
spring:
application:
name: my-service
cloud:
config:
fail-fast: false
discovery:
enabled: true
service-id: configserver
retry:
initialInterval: 2000
multiplier: 1.5
maxInterval: 60000
maxAttempts: 10
server:
port: ${APPLICATION_PORT:16000}
eureka:
client:
serviceUrl:
defaultZone: http://${EUREKA_HOSTNAME:localhost}:15000/eureka/
The eureka config looks as following:
spring:
application:
name: manager
server:
port: 15000
eureka:
client:
registerWithEureka: true
fetchRegistry: false
serviceUrl:
defaultZone: http://${EUREKA_HOSTNAME:localhost}:15000/eureka/
Last but not least - the configserver config looks as following:
spring:
application:
name: configserver
cloud:
config:
fail-fast: true
server:
port: 15001
eureka:
client:
serviceUrl:
defaultZone: http://${EUREKA_HOSTNAME:localhost}:15000/eureka/
Anyone able to give any advice here?
I found the issue:
Actually I found two issues on our side. The first one is not having a suitable lease renewal interval. The client just retried receiving the configuration with the cached services.
Since the cached services did not contain a configuration service, he wasn't able to receive a proper configuration.
The second problem was to not wait for enough time. This has been fixed in raising the maxAttempts higher. So the config and discovery services do have enough time to come up.
The client Configuration looks like the following now:
spring:
application:
name: service
cloud:
config:
fail-fast: true
discovery:
enabled: true
service-id: CONFIGSERVER
retry:
initialInterval: 2000
multiplier: 1.5
maxInterval: 60000
maxAttempts: 100
server:
port: ${APPLICATION_PORT:16000}
eureka:
instance:
lease-renewal-interval-in-seconds: 10
client:
fetch-registry: true
serviceUrl:
defaultZone: http://${EUREKA_HOSTNAME:localhost}:15000/eureka/

How to Configure Zuul Multiple instances of one microservice

i'm working in a spring cloud project and i have an eruka service, zull proxy and a microservice with the name defects-service (zull proxy and my defects-service are clients for eurka) and all works fine.
in my zull proxy i have the following configuration :
eureka:
client:
register-with-eureka: true
fetch-registry: true
serviceUrl:
defaultZone: http://localhost:8370/eureka/
instance:
hostname: localhost
zuul:
prefix: /api
routes:
defects-service:
path: /defects-service/**
url: http://localhost:8300
my issue is now i start two instances of my defects-service on diferents ports 8301 and 8302 (registred successfully in eruka service ) but i don't know how to configure my zull proxy to do a load balancing and start redirect requests to my three instances on ports (8300,8301,8302).
note , zull knows only the instance on http://localhost:8300
can anyone please helpe me to resolve this isuue .
Best regards .
Zuul support load balancing out of the box, instead of giving url in your configuration, use serviceId:
zuul:
prefix: /api
routes:
defects-service:
path: /defects-service/**
serviceId: defects-service
the solution of this problem is by using the following config :
zuul:
prefix: /api
routes:
defects-service:
path: /defects-service/**
serviceId: defects-service
after that if you got any error like Hystrix Readed time out.. just add the following config :
hystrix:
command:
default:
execution:
isolation:
thread:
timeoutInMilliseconds: 11000
ribbon:
ConnectTimeout: 10000
ReadTimeout: 10000

Resources