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 split Traffic in Linkerd2

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

How to split traffic in Linkerd2, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

The latest release of Linkerd 2.4adds support for traffic splitting.

After installing the latest version, you can see that the API resources used by this traffic splitting feature are not from Linkerd, but are part of the SMI specification.

$curl-sL https://run.linkerd.io/install | sh

...

$kubectl api-resources | grep-I split

Trafficsplits ts split.smi-spec.io true TrafficSplit

Unlike Istio's Service + Selector split, Linkerd actually has no special upstream definition, simply defining an independent Service. For example, if we want to offload flaskapp services to v1 and v2 versions, in Istio, we need to define a flaskapp service and then use tags to select two sets of Subset as destinations in the tag subset of Service. In Linkerd/SMI, you need to define three services, such as flaskapp, flaskapp-v1, and flaskapp-v2. Let's have a simple drill.

$wget https://raw.githubusercontent.com/fleeto/istio-for-beginner/master/code/flaskapp/flaskapp.istio.yaml

$linkerd inject flaskapp.istio.yaml | kubectl apply-f-

...

$wget https://raw.githubusercontent.com/fleeto/istio-for-beginner/master/code/sleep/sleep.yaml

$linkerd inject sleep.yaml | kubectl apply-f-

...

After installing two versions of flaskapp and one version of sleep service. Create two more flaskapp version services.

ApiVersion: v1

Kind: Service

Metadata:

Name: flaskapp-v1

Labels:

App: flaskapp

Spec:

Selector:

App: flaskapp

Version: v1

Ports:

-name: http

Port: 80

TargetPort: 80

-

ApiVersion: v1

Kind: Service

Metadata:

Name: flaskapp-v2

Labels:

App: flaskapp

Spec:

Selector:

App: flaskapp

Version: v2

Ports:

-name: http

Port: 80

TargetPort: 80

After creating two services, you can try to split it, which is also a YAML:

ApiVersion: split.smi-spec.io/v1alpha1

Kind: TrafficSplit

Metadata:

Name: flask-split

Spec:

Service: flaskapp

Backends:

-service: flaskapp-v1

Weight: 1

-service: flaskapp-v2

Weight: 500m

Note that the definition here is also slightly different from Istio, using weights rather than percentages for diversion.

You can test it in Sleep:

$for i in {1... 1000}; do curl-sSL http://flaskapp/env/version | grep v1; done | wc-l

six hundred and sixty

It can be seen that according to our weight distribution, the diversion has been carried out successfully. However, at present, there is no relevant content about conditional selection in SMI, so the current features may be relatively elementary. More complex functions can be achieved through the blessing of Flagger.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

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