skip to Main Content

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


  1. With Nginx ingress, you will be able to inject the secret into the request if it’s coming outside and forward request to service

    nginx.ingress.kubernetes.io/configuration-snippet: |
      proxy_set_header My-Custom-Header $http_my_custom_header;
    

    since 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

    Login or Signup to reply.
  2. ingress-nginx supports configuration snippets as an annotation.

        nginx.ingress.kubernetes.io/configuration-snippet: |
          if ($http_version != "1.2.0") {
            return 418;
          }
    

    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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search