Istio - Header Based Routing

As you all know whenever a request getting into the system it's going to have a set of headers and that's going to have what user and lot other information. Based on the value that we have within the header I can route the request to different subset available within a service.

I'm going to consider the same book info example where I'm going to consider the user name that is available as a part of the header and route the request to the reviews to different subset version.

Let's go ahead and do the demo. Within the cluster I'm going to create a virtual service something like this.

So the kind is VirtualService. Within the specification I am going to mention the host as reviews because the requests going to land up within the review.

As a part of the match condition, I will be having the route destination to subset version two when the header with end-user as the key that's matching with the value jason or otherwise I will be having the route destination to the host reviews and subset V1

Before Login

So all the requests having the header as jason will get routed to version 2 and other requests or the other users will get routed to version 1. Let me go ahead and create the virtual service.

$ kubectl apply -f samples/bookinfo/networking/virtual-service-reviews-test-v2.yaml
virtualservice.networking.istio.io/reviews created

Let me go ahead and access the web UI. Now Let me refresh the page.

No alt text provided for this image


So whatever the number of times I'm refreshing, It's going to land in version 1. So what's happening now? the end user header is not available. So directly it's getting into the destination version 1. That's the reason it doesn't have any stars.

After Login

And if I log in as the user jason, it should route me to version 2. Sign in, let me provide the user say sign in Now, I logged in as the user jason, no need to provide any password.

No alt text provided for this image


And it got the review from version 1 and I'm getting the stars in black color. That means landed in version 2. Here, let me go ahead and refresh the page. What ever the number of times I'm refreshing I'm going to get the same review page.

So we're able to route the request based on the header that we're setting within the application.

Summary

So in a quick summary we saw how to route the request based on the user header that we are setting within the application using the virtual service.

Reference

https://www.waytoeasylearn.com/learn/header-based-routing/

要查看或添加评论,请登录

Ashok Kumar的更多文章

  • Need and Purpose of Package Manager

    Need and Purpose of Package Manager

    Need of Package Manager In this tutorial, we are going to discuss about the purpose and need of a package manager…

  • Hibernate with Multiple Databases

    Hibernate with Multiple Databases

    In single hibernate application we are able to interact with more than one Database, but, we must use the following…

  • Generic Methods

    Generic Methods

    1. m1(ArrayList) It is applicable for ArrayList of only String type.

  • Java Generics

    Java Generics

    Array objects are by default type safe. i.

  • Java Annotations Types

    Java Annotations Types

    Annotations are declared by using following syntax @interface AnnotationName { members } Members syntax datatype…

  • PostgreSQL Multi master using Bucardo

    PostgreSQL Multi master using Bucardo

    Bucardo is an asynchronous PostgreSQL replication system, allowing for both multi-master and multi-slave operations…

社区洞察

其他会员也浏览了