Updating HTTP router parameters
To update the HTTP router parameters:
- In the management console
, select the folder where the HTTP router was created. - Select Application Load Balancer.
- In the left-hand panel, select
HTTP routers. - Click the router name.
- Click Edit.
- Edit the router, virtual host, or route settings.
- At the bottom of the page, click Save.
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
-
View a description of the CLI command to update a load balancer:
yc alb http-router update --help
-
Run the command, indicating the new router parameters:
yc alb http-router update <HTTP_router_name> --new-name <new_name_for_HTTP_router>
Result:
id: a5dld80l32ed******** name: new-http-router folder_id: aoe197919j8e******** virtual_hosts: - name: test-virtual-host authority: - your-domain.foo.com routes: - name: test-route http: match: path: prefix_match: / route: backend_group_id: a5d4db973944******** timeout: 2s idle_timeout: 3s modify_request_headers: - name: Accept-Language append: ru-RU created_at: "2021-02-11T21:31:01.676592016Z"
If you don't have Terraform, install it and configure the Yandex Cloud provider.
-
Open the Terraform configuration file and edit the fragment with the HTTP router description.
... resource "yandex_alb_http_router" "tf-router" { name = "my-http-router" labels = { tf-label = "tf-label-value" empty-label = "" } } ...
For more information about the
yandex_alb_http_router
resource parameters in Terraform, see the provider documentation . -
To add, update, or delete HTTP router virtual hosts, use the
yandex_alb_virtual_host
resource indicating the router in thehttp_router_id
field:resource "yandex_alb_virtual_host" "my-virtual-host" { name = "my-virtual-host" http_router_id = "${yandex_alb_http_router.tf-router.id}" route { name = "my-route" http_route { http_route_action { backend_group_id = "${yandex_alb_backend_group.backend-group.id}" timeout = "3s" } } } }
For more information about the
yandex_alb_virtual_host
resource parameters in Terraform, see the provider documentation . -
Check the configuration using this command:
terraform validate
If the configuration is correct, you will get this message:
Success! The configuration is valid.
-
Run this command:
terraform plan
The terminal will display a list of resources with parameters. No changes will be made at this step. If the configuration contains any errors, Terraform will point them out.
-
Apply the configuration changes:
terraform apply
-
Confirm the changes: type
yes
into the terminal and press Enter.You can check the HTTP router update using the management console
or this CLI](../../cli/quickstart.md) command:yc alb http-router get <HTTP_router_ID>
Use the update REST API method for the HttpRouter resource or the HttpRouterService/Update gRPC API call.
Adding a route to a virtual host
To add a new route to an HTTP router's virtual host:
- In the management console
, select the folder where the HTTP router was created. - Select Application Load Balancer.
- In the left-hand panel, select
HTTP routers. - Click the router name.
- Click Edit.
- Click Add route.
- Set the route parameters and click Save.
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
See the description of the CLI command for managing virtual hosts:
yc alb virtual-host --help
-
HTTP
You can add a new route to the beginning, end, or specific position in the host's route list.
Add a route to the end of a host's route list
-
View a description of the CLI command for adding a route to the end of a host's route list:
yc alb virtual-host append-http-route --help
-
Run this command:
yc alb virtual-host append-http-route <route_name> \ --virtual-host-name <virtual_host_name> \ --http-router-name <HTTP_router_name> \ --match-http-method <HTTP_method> \ --exact-path-match / \ --backend-group-name <backend_group_name> \ --request-timeout <request_timeout>s \ --request-idle-timeout <request_idle_timeout>s
For more information about the
yc alb virtual-host append-http-route
command parameters, see the CLI reference.Result:
name: test-virtual-host authority: - your-domain.foo.com routes: - name: test-route ... - name: test-route-toend http: match: path: prefix_match: / route: backend_group_id: a5d3e9ko2qf0******** timeout: 2s idle_timeout: 3s
Add a route to the beginning of a host's route list
-
View a description of the CLI command for adding a route to the beginning of a host's route list:
yc alb virtual-host prepend-http-route --help
-
Run this command:
yc alb virtual-host prepend-http-route <route_name> \ --virtual-host-name <virtual_host_name> \ --http-router-name <HTTP_router_name> \ --match-http-method <HTTP_method> \ --exact-path-match / \ --backend-group-name <backend_group_name> \ --request-timeout <request_timeout>s \ --request-idle-timeout <request_idle_timeout>s
For more information about the
yc alb virtual-host prepend-http-route
command parameters, see the CLI reference.Result:
name: test-virtual-host authority: - your-domain.foo.com routes: - name: test-route-tostart http: match: http_method: - GET path: exact_match: / route: backend_group_id: a5d3e9ko2qf0******** timeout: 2s idle_timeout: 3s - name: test-route ...
Add a route before a specific route
-
View a description of the CLI command for adding a route before a specific route:
yc alb virtual-host insert-http-route --help
-
Run this command:
yc alb virtual-host insert-http-route <route_name> \ --virtual-host-name <virtual_host_name> \ --before <route_name_to_be_preceded_by_new_route> \ --http-router-name <HTTP_router_name> \ --match-http-method <HTTP_method> \ --exact-path-match / \ --backend-group-name <backend_group_name> \ --request-timeout <request_timeout>s \ --request-idle-timeout <request_idle_timeout>s
For more information about the
yc alb virtual-host insert-http-route
command parameters, see the CLI reference.Result:
done (2s) name: test-virtual-host authority: - your-domain.foo.com routes: ... - name: test-route-insbefore http: match: http_method: - GET path: exact_match: / route: backend_group_id: a5d3e9ko2qf0******** timeout: 2s idle_timeout: 3s - name: test-route ...
Add a route after a specific route
-
View a description of the CLI command for adding a new route after a specific route:
yc alb virtual-host insert-http-route --help
-
Run this command:
yc alb virtual-host insert-http-route <route_name> \ --virtual-host-name <virtual_host_name> \ --after <route_name_to_be_followed_by_new_route> \ --http-router-name <HTTP_router_name> \ --match-http-method <HTTP_method> \ --exact-path-match / \ --backend-group-name <backend_group_name> \ --request-timeout <request_timeout>s \ --request-idle-timeout <request_idle_timeout>s
For more information about the
yc alb virtual-host insert-http-route
command parameters, see the CLI reference.Result:
done (2s) name: test-virtual-host authority: - your-domain.foo.com routes: - name: test-route ... - name: test-route-insafter http: match: path: prefix_match: / route: backend_group_id: a5d3e9ko2qf0******** timeout: 2s idle_timeout: 3s ...
-
-
gRPC
You can add a new route to the beginning, end, or specific position in the host's route list.
Add a route to the end of a host's route list
-
View a description of the CLI command for adding a route to the end of a host's route list:
yc alb virtual-host append-grpc-route --help
-
Run this command:
yc alb virtual-host append-grpc-route <route_name> \ --virtual-host-name <virtual_host_name> \ --http-router-name <HTTP_router_name> \ --prefix-fqmn-match /<first_word_of_service_name> \ --backend-group-name <backend_group_name> \ --request-max-timeout <timeout>s
For more information about the
yc alb virtual-host append-grpc-route
command parameters, see the CLI reference.Result:
name: <virtual_host_name> authority: - * routes: - name: grpc-route ... - name: grpc-route-toend grpc: match: fqmn: prefix_match: /helloworld route: backend_group_id: ds7snban2dvn******** max_timeout: 60s auto_host_rewrite: false
Add a route to the beginning of a host's route list
-
View a description of the CLI command for adding a route to the beginning of a host's route list:
yc alb virtual-host prepend-grpc-route --help
-
Run this command:
yc alb virtual-host prepend-grpc-route <route_name> \ --virtual-host-name <virtual_host_name> \ --http-router-name <HTTP_router_name> \ --prefix-fqmn-match /<first_word_of_service_name> \ --backend-group-name <backend_group_name> \ --request-max-timeout <timeout>s
For more information about the
yc alb virtual-host prepend-grpc-route
command parameters, see the CLI reference.Result:
name: <virtual_host_name> authority: - * routes: - name: grpc-route-tostart grpc: match: fqmn: prefix_match: /helloworld route: backend_group_id: ds7snban2dvn******** max_timeout: 60s auto_host_rewrite: false - name: grpc-route ...
Add a route before a specific route
-
View a description of the CLI command for adding a route before a specific route:
yc alb virtual-host insert-grpc-route --help
-
Run this command:
yc alb virtual-host insert-grpc-route <route_name> \ --virtual-host-name <virtual_host_name> \ --before <route_name> \ --http-router-name <HTTP_router_name> \ --prefix-fqmn-match /<first_word> \ --backend-group-name <backend_group_name> \ --request-max-timeout <timeout>s
Where:
--virtual-host-name
: Name of the virtual host to add a route to.--before
: Route name to be preceded by the new route.--http-router-name
: HTTP router name.--prefix-fqmn-match
: First word in the service name.--backend-group-name
: Backend group name.--request-max-timeout
: Timeout in seconds.
For more information about the
yc alb virtual-host insert-grpc-route
command parameters, see the CLI reference.Result:
name: grpc-host authority: - * routes: ... - name: grpc-route-before grpc: match: fqmn: prefix_match: /helloworld route: backend_group_id: ds7snban2dvn******** max_timeout: 60s auto_host_rewrite: false - name: grpc-route ...
Add a route after a specific route
-
View a description of the CLI command for adding a new route after a specific route:
yc alb virtual-host insert-grpc-route --help
-
Run this command:
yc alb virtual-host insert-grpc-route <route_name> \ --virtual-host-name <virtual_host_name> \ --after <route_name> \ --http-router-name <HTTP_router_name> \ --prefix-fqmn-match /<first_word> \ --backend-group-name <backend_group_name> \ --request-max-timeout <timeout>s
Where:
--virtual-host-name
: Name of the virtual host to add a route to.--after
: Route name to be followed by the new route.--http-router-name
: HTTP router name.--prefix-fqmn-match
: First word in the service name.--backend-group-name
: Backend group name.--request-max-timeout
: Timeout in seconds.
For more information about the
yc alb virtual-host insert-grpc-route
command parameters, see the CLI reference.Result:
name: grpc-host authority: - * routes: ... - name: grpc-route ... - name: grpc-route-after grpc: match: fqmn: prefix_match: /helloworld route: backend_group_id: ds7snban2dvn******** max_timeout: 60s auto_host_rewrite: false ...
-
If you don't have Terraform, install it and configure the Yandex Cloud provider.
-
Open the Terraform configuration file and edit the virtual host description fragment by adding the
route
section:resource "yandex_alb_virtual_host" "my-virtual-host" { name = "my-virtual-host" http_router_id = "${yandex_alb_http_router.tf-router.id}" route { name = "my-route" http_route { http_route_action { backend_group_id = "${yandex_alb_backend_group.backend-group.id}" timeout = "3s" } } } }
For more information about the
yandex_alb_virtual_host
resource parameters in Terraform, see the provider documentation .The sequence of routes inside a virtual host description matters. For more information, see the concept.
-
Check the configuration using this command:
terraform validate
If the configuration is correct, you will get this message:
Success! The configuration is valid.
-
Run this command:
terraform plan
The terminal will display a list of resources with parameters. No changes will be made at this step. If the configuration contains any errors, Terraform will point them out.
-
Apply the configuration changes:
terraform apply
-
Confirm the changes: type
yes
into the terminal and press Enter.You can check the virtual host update using the management console
or this CLI command:yc alb virtual-host get <virtual_host_ID>
Use the update REST API method for the VirtualHost resource or the VirtualHostService/Update gRPC API call.
Change route order in the virtual host
To change the order of HTTP router routes:
- In the management console
, select the folder where the HTTP router was created. - Select Application Load Balancer.
- In the left-hand panel, select
HTTP routers. - Click the router name.
- Click Edit.
- Click Sort.
- In the window that opens, drag the route to a new position in the list.
- Click Save.
- Finish editing the router and click Save.
-
HTTP
-
View a description of the CLI route delete command:
yc application-load-balancer virtual-host remove-http-route --help
-
Delete the route:
yc alb virtual-host remove-http-route <route_name> \ --virtual-host-name <virtual_host_name> \ --http-router-name <router_name>
-
Add the route to a desired position using one of the ways described above.
-
-
gRPC
-
View a description of the CLI route delete command:
yc application-load-balancer virtual-host remove-gRPC-route --help
-
Delete the route:
yc alb virtual-host remove-grpc-route <route_name> \ --virtual-host-name <virtual_host_name> \ --http-router-name <router_name>
-
Add the route to a desired position using one of the ways described above.
-
Use the update REST API method for the VirtualHost resource or the VirtualHostService/Update gRPC API call.