Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to configure request routing in Istio in kubernetes

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly shows you "how to configure request routing in kubernetes". The content is simple and clear. I hope it can help you solve your doubts. Let me lead you to study and learn this article "how to configure request routing in Istio in kubernetes".

One: brief introduction

Since the Bookinfo sample deploys three versions of the reviews microservice, we need to set up a default route. Otherwise, if you visit the application multiple times, you will notice that sometimes the output contains a star score, and sometimes it does not. This is because when no default route is explicitly specified for the application, Istio randomly routes the request to all available versions of the service.

Second: routing configuration

Description: this task assumes that you have not set up any routes. If you have created conflicting routing rules for the sample application, you need to use replace instead of create in the following command

Set the default version of all microservices to v1

Istioctl create-f samples/bookinfo/networking/destination-rule-all.yaml

ApiVersion: networking.istio.io/v1alpha3kind: DestinationRulemetadata: name: productpagespec: host: productpage subsets:-name: v1 labels: version: v1---apiVersion: networking.istio.io/v1alpha3kind: DestinationRulemetadata: name: reviewsspec: host: reviews subsets:-name: V1 labels: version: V1-name: v2 labels: version: v2-name: v3 labels: version: v3---apiVersion: networking.istio.io/v1alpha3kind: DestinationRulemetadata: Name: ratingsspec: host: ratings subsets:-name: v1 labels: version: V1-name: v2 labels: version: v2-name: v2-mysql labels: version: v2MySQL-name: v2-mysql-vm labels: version: v2-mysql-vm---apiVersion: networking.istio.io/v1alpha3kind: DestinationRulemetadata: name: detailsspec: host: details subsets:-name: v1 labels: version: V1 -name: v2 labels: version: v2Murray-

Istioctl create-f samples/bookinfo/networking/virtual-service-all-v1.yaml

ApiVersion: networking.istio.io/v1alpha3kind: VirtualServicemetadata: name: productpagespec: hosts:-productpage http:-route:-destination: host: productpage subset: v1---apiVersion: networking.istio.io/v1alpha3kind: VirtualServicemetadata: name: reviewsspec: hosts:-reviews http:-route:-destination: host: reviews subset: v1---apiVersion: networking.istio.io/v1alpha3kind: VirtualServicemetadata: name: ratingsspec: hosts: -ratings http:-route:-destination: host: ratings subset: v1---apiVersion: networking.istio.io/v1alpha3kind: VirtualServicemetadata: name: detailsspec: hosts:-details http:-route:-destination: host: details subset: v1Murray-

3. Use istioctl get destinationrules-o yaml to display the subset definition for routing rules

ApiVersion: networking.istio.io/v1alpha3kind: DestinationRulemetadata: creationTimestamp: null name: details namespace: default resourceVersion: "14675502" spec: host: details subsets:-labels: version: v1 name: v1-labels: version: v2 name: v2---apiVersion: networking.istio.io/v1alpha3kind: DestinationRulemetadata: creationTimestamp: productpage namespace: default resourceVersion: "14675499" spec: host: productpage subsets:-labels: version: v1 name: V1mura- ApiVersion: networking.istio.io/v1alpha3kind: DestinationRulemetadata: creationTimestamp: null name: ratings namespace: default resourceVersion: "14675501" spec: host: ratings subsets:-labels: version: v1 name: V1-labels: version: v2 name: v2-labels: version: v2-mysql name: v2MyMythql-labels: version: v2-mysql-vm name: v2-mysql-vm---apiVersion: networking.istio.io/v1alpha3kind: DestinationRulemetadata: CreationTimestamp: null name: reviews namespace: default resourceVersion: "14675500" spec: host: reviews subsets:-labels: version: V1 name: V1-labels: version: v2 name: v2-labels: version: V3 name: V3 Murray-

4. Enable the ratings service for the test user "jason" by routing traffic from productpage to the reviews:v2 instance.

Istioctl replace-f samples/bookinfo/networking/virtual-service-reviews-test-v2.yaml

ApiVersion: networking.istio.io/v1alpha3kind: VirtualServicemetadata: name: reviewsspec: hosts:-reviews http:-match:-headers: end-user: exact: jason route:-destination: host: reviews subset: v2-route:-destination: host: reviews subset: v1

Log in as the user "jason" on the productpage page. You should now see the score (1-5 stars) next to each comment. Note that if you log in as any other user, you will continue to see the reviews:v1 version of the service, a page that does not contain star ratings.

Three: principle

First, 100% of the request traffic is routed to the v1 version of the Bookinfo service using Istio. A routing rule is then set up that adds a request-based "end-user" custom header to the productpage service to selectively route specific traffic to the v2 version of the reviews service.

In order to take advantage of Istio's L7 routing capabilities, services in Kubernetes, such as the Bookinfo service used in this task, must comply with certain restrictions.

1. The port needs to be named correctly: the service port must be named. Port names are only allowed in [- -] mode, and some of the options include http, http2, grpc, mongo, and redis,Istio to provide routing capabilities through support for these protocols. For example, name: http2-foo and name: http are valid port names, but name: http2foo is invalid. If the port is not named or the specified prefix is not used, traffic on that port is treated as normal TCP traffic (unless the port is explicitly declared to be a UDP port with Protocol: UDP).

two。 Associated services: Pod must be associated with Kubernetes services. If a Pod belongs to multiple services, these services cannot use different protocols on the same port, such as HTTP and TCP.

3.Deployment should be tagged with app and version: when using Kubernetes Deployment for Pod deployment, it is recommended to explicitly tag Deployment with app and version. Each Deployment should have a meaningful app tag and a version tag that identifies the Deployment version. App tags are used to add context information during distributed tracing. Istio also uses app and version tags to add context information to telemetry metric data.

Four: clear the route

Istioctl delete-f samples/bookinfo/networking/virtual-service-all-v1.yaml

These are all the contents of the article "how to configure request routing in kubernetes". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report