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 use Traefik to build active load balancing in Rancher

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

Share

Shulou(Shulou.com)06/01 Report--

How to use Traefik to build active load balancer in Rancher? in view of this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.

Metadata service

In Rancher, we have an excellent built-in service discovery system called Rancher metadata service. In Rancher's metadata services, we can get information from native services or from other stacks or services. Rancher's metadata contains the latest information about what services are running on the system and where they are located.

To generate dynamic configuration files for your service, you need to communicate with Rancher's metadata service. To do this, you can use confd with a specific template.

For more details, I suggest you read this article by Bill Maxwell: http://rancher.com/introducing-rancher-metadata-service-for-docker/.

Load balancing

Rancher provides a built-in load balancing service. It is a containerized HAProxy, and it is very useful for publishing your service port to the public.

This load balancer can work in two different modes. This means that it can work at two different OSI layers, especially layer 4 and layer 7. But what does that mean?

The fourth floor

-

You can publish and provide access to TCP ports. You use this somewhat primitive mode to send packets to the back end of your service, but you cannot modify the port. In this mode, you cannot share ports. This means that you need to publish a different port for each service.

The seventh floor

-

At this level, you are working at the application level and can only publish HTTP (S) ports. In this mode, the load balancer can view and modify HTTP packets. You can check, add or modify HTTP header files. In this mode, you can share the same release port for different services. Obviously, the load balancer must know how to distinguish between incoming packets in order to forward them to the correct service. To do this, you need to define a HTTP header file filter that checks for incoming HTTP packets. Once the match is successful, the request will be sent to the correct service.

In both modes, load balancing works in "passive mode". This means that once you deploy a new service, you must modify the load balancing configuration and re-add the service. Obviously, if you delete a service from the load balancer, its configuration will also be deleted in the load balancer configuration.

Active load balancing

To provide users with a better choice, we have created an "active mode" load balancing based on Docker tags and Rancher metadata services. Cloud load balancer scans Rancher metadata and can configure it on its own, and provides access to services with specific tags.

To get this functionality, we use Traefik. Traefik is a programmable open source load balancer written in golang. It can be integrated with different service discovery systems such as Zookeeper,etcd,Consul. We did a preliminary integration with Rancher metadata. Traefik has a real zero downtime overload and implements the possibility of defining circuit breaker rules. For more information, visit https://traefik.io/.

To use Traefik, select it from the community Catalog and start it. Using the default parameters, Traefik will run on all hosts labeled traefik_lb=true. Expose host port 8080 for HTTP services and port 8000 managed as Traefik. It refreshes the configuration every 60 seconds. Makes it possible to override all parameters when you deploy the service.

Once the service is deployed, you can access the administrative interface http://host-address:9000

You need to define the following tags on the server side to automatically expose your services to Traefik:

Traefik.enable=

Traefik.domain=

Traefik.port=

Defining a health check in your service is mandatory because only healthy backends can be added to Traefik. If you define the traefik.enable=true tag in your service, but the service does not have a health check, the front end can be added to the Traefik, but the back end will only have an empty list.

test

We have written a basic Web testing service that enables it to check the Traefik service and test it in a quick way. This service exposes Web services on port 8080.

You can import the following docker-compose.yml and rancher-compose.yml to create a new Stack.

Docker-compose.yml

Web-test:

Log_driver:''

Labels:

Traefik.domain:local

Traefik.port:'8080'

Traefik.enable:'true'

Io.rancher.container.hostname_override:container_name

Tty:true

Log_opt: {}

Image:rawmind/web-test

Rancher-compose.yml

Web-test:

Scale:3

Health_check:

Port:8080

Interval:2000

Initializing_timeout:60000

Unhealthy_threshold:3

Strategy:recreate

Response_timeout:2000

Request_line:GET "/"HTTP/1.0"

Healthy_threshold:2

This is the answer to the question on how to use Traefik to build active load balancer in Rancher. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.

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