Setting Up Linkerd for HTTP Request Routing

Linkerd can be utilized as a router to direct HTTP requests to services that may be running on the same or different IP addresses but on different ports. Below is a configuration example that illustrates how to achieve this.

Configuration Example

In this example, we will configure Linkerd to listen on port 4142 and route requests to a service that is listening on port 4041.

routers:
  - protocol: http
    label: http-router
    dtab: |
      /svc => /$/inet/127.0.0.1/4041;
    servers:
      - port: 4142
        ip: 0.0.0.0
        maxConcurrentRequests: 250
    identifier:
      kind: io.l5d.header
      header: google

Explanation of the Configuration

  • routers: This section defines the routing rules for Linkerd.
  • protocol: Specifies the protocol being used, in this case, HTTP.
  • label: A unique identifier for the router, which can be helpful for monitoring and debugging.
  • dtab: This is the routing table that defines how requests are mapped. Here, requests to /svc are directed to the service at 127.0.0.1 on port 4041.
  • servers: This section specifies the server configuration where Linkerd will listen for incoming requests. The server is set to listen on port 4142 and accepts requests from any IP address (0.0.0.0).
  • maxConcurrentRequests: Limits the number of concurrent requests that can be processed, helping to manage load.
  • identifier: This section specifies how to identify requests, using a header named google in this case.

Common Issues

If you encounter an error such as Unable to route request!, it may indicate that the dtab is not correctly configured. Ensure that the dtab is properly defined with the correct IP and port. For static addresses, you should use the inet namer as shown in the example above.

By following this configuration, you should be able to successfully route HTTP requests through Linkerd to your desired service.