I have a kubernetes cluster and i have more than 15 microservices running in it, Each REST API send me a custom header lets say "version":"1.2.0", i need to check this version from each REST api and throw a custom error if it doesn’t match with the value i have.
Suppose i have a mobile app and i have released a new version of the app and redeployed the microservices to match the new app, i want to throw a custom error to users using the old application to download the new app to continue using the application.
Is there a way to achieve this using ingress-nginx or in the kubernetes level instead of repeating logic in each microservice.
2
Answers
With
Nginx ingress
, you will be able to inject the secret into the request if it’s coming outside and forward request to servicesince as your all microservices talking internally and routing based on custom header you can use the service mesh
istio
for example : https://istio.io/latest/docs/tasks/traffic-management/request-routing/#route-based-on-user-identity
https://dwdraju.medium.com/simplified-header-based-routing-with-istio-for-http-grpc-traffic-ff9be55f83ca
ingress-nginx supports configuration snippets as an annotation.
You can configure the ingress to capture certain error codes so the default backend app receives these requests and can build a custom error response. Be aware that this captures all listed error codes. So don’t use a status code that the rest of your application might or you might hide a real error response.