Yandex Cloud
  • Services
  • Solutions
  • Why Yandex Cloud
  • Pricing
  • Documentation
  • Contact us
Get started
Language / Region
© 2022 Yandex.Cloud LLC
Yandex Application Load Balancer
  • Getting started
  • Step-by-step instructions
    • All instructions
    • Target groups
      • Create a target group
      • Edit a target group
      • Delete a target group
    • Backend groups
      • Create a backend group
      • Edit a backend group
      • Delete a backend group
    • HTTP routers
      • Create HTTP router
      • Edit an HTTP router
      • Delete an HTTP router
    • L7 load balancers
      • Create an L7 load balancer
      • Edit an L7 load balancer
      • View L7 load balancer statistics
      • View the L7 load balancer logs
      • Get the ID of the log group of the L7 load balancer
      • Stopping and restarting an L7 load balancer
      • Delete an L7 load balancer
    • Ingress Controller for Managed Service for Kubernetes
      • Install an Ingress controller
      • Create or update resources based on configuration
  • Practical guidelines
    • Setting up a virtual hosting
    • Creating a load balancer with DDoS protection
    • Integrating an L7 load balancer with the CDN and Object Storage
    • Blue-green and canary deployment of service versions
    • Terminating TLS connections
    • Writing load balancer logs to PostgreSQL
  • Concepts
    • Overview
    • Load balancers
    • HTTP routers
    • Backend groups
    • Target groups
    • Quotas and limits
  • Tools
    • Ingress Controller for Managed Service for Kubernetes
      • Overview
      • How it works
      • Security groups
      • Service accounts
  • Access management
  • Pricing policy
  • API reference
    • Authentication in the API
    • gRPC
      • Overview
      • BackendGroupService
      • HttpRouterService
      • LoadBalancerService
      • TargetGroupService
      • VirtualHostService
      • OperationService
    • REST
      • Overview
      • BackendGroup
        • Overview
        • addBackend
        • create
        • delete
        • get
        • list
        • listOperations
        • removeBackend
        • update
        • updateBackend
      • HttpRouter
        • Overview
        • create
        • delete
        • get
        • list
        • listOperations
        • update
      • LoadBalancer
        • Overview
        • addListener
        • addSniMatch
        • create
        • delete
        • get
        • getTargetStates
        • list
        • listOperations
        • removeListener
        • removeSniMatch
        • start
        • stop
        • update
        • updateListener
        • updateSniMatch
      • TargetGroup
        • Overview
        • addTargets
        • create
        • delete
        • get
        • list
        • listOperations
        • removeTargets
        • update
      • VirtualHost
        • Overview
        • create
        • delete
        • get
        • list
        • removeRoute
        • update
        • updateRoute
  • Ingress controller reference
    • Overview
    • Ingress
    • HttpBackendGroup
    • Service
  • Log reference
  1. Step-by-step instructions
  2. HTTP routers
  3. Edit an HTTP router

Change HTTP router parameters

Written by
Yandex Cloud
  • Adding a route to a virtual host

To change the HTTP router parameters:

Management console
CLI
Terraform
  1. In the management console, select the folder where the HTTP router was created.
  2. Select Application Load Balancer.
  3. On the left-hand panel, select HTTP routers.
  4. Click on the name of the router you need.
  5. Click Edit.
  6. Edit the router settings.
  7. At the bottom of the page, click Save.

If you don't 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.

  1. View a description of the CLI command to update a load balancer:

    yc alb http-router update --help
    
  2. Run the command, indicating the new router parameters:

    yc alb http-router update <HTTP router name> --new-name <new HTTP router name>
    

    Result:

    id: a5dld80l32edg407nsti
    name: new-http-router
    folder_id: aoe197919j8elpeg1lkp
    virtual_hosts:
    - name: test-virtual-host
      authority:
      - your-domain.foo.com
      routes:
      - name: test-route
        http:
          match:
            path:
              prefix_match: /
          route:
            backend_group_id: a5d4db973944t2fh8gor
            timeout: 2s
            idle_timeout: 3s
      modify_request_headers:
      - name: Accept-Language
        append: ru-RU
    created_at: "2021-02-11T21:31:01.676592016Z"
    

For more information about Terraform, see the documentation.

  1. 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 in Terraform, see the provider documentation.

  2. To add, update, or delete an HTTP router's virtual hosts, use the yandex_alb_virtual_host resource indicating the router in the http_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 in Terraform, see the provider documentation.

  3. Check the configuration using the command:

    terraform validate
    

    If the configuration is correct, the following message is returned:

    Success! The configuration is valid.
    
  4. Run the command:

    terraform plan
    

    The terminal will display a list of resources with parameters. No changes are made at this step. If there are errors in the configuration, Terraform points them out.

  5. Apply the configuration changes:

    terraform apply
    
  6. Confirm the changes: type yes into the terminal and press Enter.

    You can verify the change to the HTTP router using the management console or the following CLI command:

    yc alb http-router get <HTTP router ID>
    

Adding a route to a virtual host

To add a new route to an HTTP router's virtual host:

Management console
CLI
Terraform
  1. In the management console, select the folder where the HTTP router was created.
  2. Select Application Load Balancer.
  3. On the left-hand panel, select HTTP routers.
  4. Click on the name of the router you need.
  5. Click Edit.
  6. Click Add route.
  7. Set the route parameters and click Save.

If you don't 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

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

  1. 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
    
  2. Run the 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 GET \
      --exact-path-match / \
      --backend-group-name <backend group name> \
      --request-timeout <request timeout>s \
      --request-idle-timeout <request idle timeout>s
    

    Result:

    name: test-virtual-host
    authority:
    - your-domain.foo.com
    routes:
    - name: test-route
      http:
        match:
          path:
            prefix_match: /
        route:
          backend_group_id: a5d3e9ko2qf0tbk0s27b
          timeout: 2s
          idle_timeout: 3s
    - name: test-route-toend
    ...
    

Add a route to the beginning of a host's route list

  1. 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
    
  2. Run the 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 GET \
      --exact-path-match / \
      --backend-group-name <backend group name> \
      --request-timeout <request timeout>s \
      --request-idle-timeout <request idle timeout>s
    

    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: a5d3e9ko2qf0tbk0s27b
          timeout: 2s
          idle_timeout: 3s
    - name: test-route
    ...
    

Add a route before a specific route

  1. View a description of the CLI command for adding a route before a specific route:

    yc alb virtual-host insert-http-route --help
    
  2. Run the command:

    yc alb virtual-host insert-http-route <route name> \
      --virtual-host-name <virtual host name> \
      --before <name of the route to add a new route before> \
      --http-router-name <HTTP router name> \
      --match-http-method GET \
      --exact-path-match / \
      --backend-group-name <backend group name> \
      --request-timeout <request timeout>s \
      --request-idle-timeout <request idle timeout>s
    

    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: a5d3e9ko2qf0tbk0s27b
          timeout: 2s
          idle_timeout: 3s
    - name: test-route
    ...
    

Add a route after a specific route

  1. View a description of the CLI command for adding a new route after a specific route:

    yc alb virtual-host insert-http-route --help
    
  2. Run the command:

    yc alb virtual-host insert-http-route <route name> \
      --virtual-host-name <virtual host name> \
      --after <name of the route to add a new route after> \
      --http-router-name <HTTP router name> \
      --match-http-method GET \
      --exact-path-match / \
      --backend-group-name <backend group name> \
      --request-timeout <request timeout>s \
      --request-idle-timeout <request idle timeout>s
    

    Result:

    done (2s)
    name: test-virtual-host
    authority:
    - your-domain.foo.com
    routes:
    - name: test-route
      http:
        match:
          path:
            prefix_match: /
        route:
          backend_group_id: a5d3e9ko2qf0tbk0s27b
          timeout: 2s
          idle_timeout: 3s
    - name: test-route-insafter
    ...
    

For more information about Terraform, see the documentation.

  1. Open the Terraform configuration file and edit the fragment with the virtual host description 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 in Terraform, see the provider documentation.

    The sequence of routes inside a virtual host description matters. For more information, see the concept.

  2. Check the configuration using the command:

    terraform validate
    

    If the configuration is correct, the following message is returned:

    Success! The configuration is valid.
    
  3. Run the command:

    terraform plan
    

    The terminal will display a list of resources with parameters. No changes are made at this step. If there are errors in the configuration, Terraform points them out.

  4. Apply the configuration changes:

    terraform apply
    
  5. Confirm the changes: type yes into the terminal and press Enter.

    You can verify the change to the virtual host using the management console or the following CLI command:

    yc alb virtual-host get <virtual host ID>
    

Was the article helpful?

Language / Region
© 2022 Yandex.Cloud LLC