Updating HTTP router settings
To update HTTP router settings:
- In the management console
, select the folder with your HTTP router. - Select Application Load Balancer.
- In the left-hand panel, select
HTTP routers. - Click your router name.
- Click Edit.
- Edit your router (virtual host, route) settings.
- Click Save at the bottom of the page.
If you do not have the Yandex Cloud CLI 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
settings.
-
See the description of the CLI command for updating an HTTP router:
yc alb http-router update --help
-
Run this command with new router settings specified:
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 do not have Terraform yet, install it and configure its Yandex Cloud provider.
-
Open the Terraform configuration file and edit the fragment describing your HTTP router.
... resource "yandex_alb_http_router" "tf-router" { name = "my-http-router" labels = { tf-label = "tf-label-value" empty-label = "" } } ...
For more information about
yandex_alb_http_router
properties, see this Terraform article . -
To add, update, or delete HTTP router virtual hosts, use the
yandex_alb_virtual_host
resource with your router ID specified in itshttp_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
yandex_alb_virtual_host
properties, see this Terraform article . -
Check the configuration using this command:
terraform validate
If your configuration is correct, you will get this message:
Success! The configuration is valid.
-
Run this command:
terraform plan
You will see a detailed list of resources. No changes will be made at this step. If your configuration contains errors, Terraform will show them.
-
Apply the changes:
terraform apply
-
Type
yes
and press Enter to confirm changes.You can check your HTTP router updates in the management console
or using this CLI 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 your HTTP router's virtual host:
- In the management console
, select the folder with your HTTP router. - Select Application Load Balancer.
- In the left-hand panel, select
HTTP routers. - Click your router name.
- Click Edit.
- Click Add route.
- Specify your route settings and click Save.
If you do not have the Yandex Cloud CLI 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
settings.
See the description of the CLI command for managing virtual hosts:
yc alb virtual-host --help
-
HTTP
You can add a new route at the beginning, end, or any position within the route list.
Add a route at the end of the list
-
See the description of the CLI command for adding a route at the end of the 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 \ --rate-limit rps=<request_limit>,requests-per-ip
For more information about
yc alb virtual-host append-http-route
options, see this 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 at the beginning of the list
-
See the description of the CLI command for adding a route at the beginning of the 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 \ --rate-limit rps=<request_limit>,requests-per-ip
For more information about
yc alb virtual-host prepend-http-route
options, 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 another route
-
See the description of the CLI command for adding a route before another 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 \ --rate-limit rps=<request_limit>,requests-per-ip
For more information about
yc alb virtual-host insert-http-route
options, see this 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 another route
-
See the description of the CLI command for adding a new route after another 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 \ --rate-limit rps=<request_limit>,requests-per-ip
For more information about
yc alb virtual-host insert-http-route
options, see this 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 at the beginning, end, or any position within the route list.
Add a route at the end of the list
-
See the description of the CLI command for adding a route at the end of the 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 \ --rate-limit rps=<request_limit>,requests-per-ip
For more information about
yc alb virtual-host append-grpc-route
options, see this 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 at the beginning of the list
-
See the description of the CLI command for adding a route at the beginning of the 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 \ --rate-limit rps=<request_limit>,requests-per-ip
For more information about
yc alb virtual-host prepend-grpc-route
options, see this 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 another route
-
See the description of the CLI command for adding a route before another 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 \ --rate-limit rps=<request_limit>,requests-per-ip
Where:
--virtual-host-name
: Name of the virtual host where you want to add a route.--before
: Route name following your new route.--http-router-name
: HTTP router name.--prefix-fqmn-match
: Service name first word.--backend-group-name
: Backend group name.--request-max-timeout
: Timeout in seconds.
For more information about
yc alb virtual-host insert-grpc-route
options, see this 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 another route
-
See the description of the CLI command for adding a new route after another 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 \ --rate-limit rps=<request_limit>,requests-per-ip
Where:
--virtual-host-name
: Name of the virtual host where you want to add a route.--after
: Route name before your new route.--http-router-name
: HTTP router name.--prefix-fqmn-match
: Service name first word.--backend-group-name
: Backend group name.--request-max-timeout
: Timeout in seconds.
For more information about
yc alb virtual-host insert-grpc-route
options, see this 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 do not have Terraform yet, install it and configure its Yandex Cloud provider.
-
Open the Terraform configuration file and add the
route
section to your virtual host description: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
yandex_alb_virtual_host
properties, see this Terraform article .The order of routes in the list matters. For more information, see this article.
-
Check the configuration using this command:
terraform validate
If your configuration is correct, you will get this message:
Success! The configuration is valid.
-
Run this command:
terraform plan
You will see a detailed list of resources. No changes will be made at this step. If your configuration contains errors, Terraform will show them.
-
Apply the changes:
terraform apply
-
Type
yes
and press Enter to confirm changes.You can check virtual host updates in the management console
or using 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 your virtual host’s route order
To change route order in the HTTP router:
- In the management console
, select the folder with your HTTP router. - Select Application Load Balancer.
- In the left-hand panel, select
HTTP routers. - Click your router name.
- Click Edit.
- Click Sort.
- In the window that opens, drag your route to a new position in the list.
- Click Save.
- Once you finish edits, click Save.
-
HTTP
-
See the description of the CLI command for deleting a route:
yc application-load-balancer virtual-host remove-http-route --help
-
Delete a route:
yc alb virtual-host remove-http-route <route_name> \ --virtual-host-name <virtual_host_name> \ --http-router-name <router_name>
-
Add your route at a required position as described above.
-
-
gRPC
-
See the description of the CLI command for deleting a route:
yc application-load-balancer virtual-host remove-gRPC-route --help
-
Delete a route:
yc alb virtual-host remove-grpc-route <route_name> \ --virtual-host-name <virtual_host_name> \ --http-router-name <router_name>
-
Add your route at a required position as described above.
-
Use the update REST API method for the VirtualHost resource or the VirtualHostService/Update gRPC API call.