Targets

Uses: Kong Gateway Admin API decK KIC Konnect API Terraform

What is a Target?

A Target identifies an instance of an upstream service using an IP address or hostname with a port. Each Upstream can have many Targets. Targets are used by Upstreams for load balancing. For example, if you have an example_upstream Upstream, you can point it to two different Targets: httpbin.konghq.com and httpbun.com. This is so that if one of the servers (like httpbin.konghq.com) is unavailable, it automatically detects the problem and routes all traffic to the working server (httpbun.com).

The following diagram illustrates how Targets are used by Upstreams for load balancing:

 
flowchart LR

  A("Request")
  B("`Route 
  (/mock)`")
  C("`Service
  (example_service)`")
  D("Target:
  httpbin.konghq.com")
  E("Target:
  httpbun.com")
  F(Upstream service:
  httpbin.konghq.com)
  G(Upstream service:
  httpbun.com)

  A --> B
  subgraph id1 ["`**KONG GATEWAY**`"]
    B --> C --> D & E
  subgraph id3 ["`**Upstream** (load balancer)`"]
  
    D & E
  end

  end

  subgraph id2 ["`**Target upstream services**`"]
    D --> F
    E --> G

  end

  style id2 stroke:none!important
  

Using hostnames

A Target can also have a hostname instead of an IP address. In that case, the name is resolved and all entries found are individually added to the load balancer.

For example, let’s say you add api.host.com:123 with weight=100:

  • If the hostname api.host.com resolves to an A record with 2 IP addresses, both IP addresses are added as a target, each with weight=100 and port 123.
  • If the hostname resolves to an SRV record, then the port and weight fields from the DNS record are used, and override the port and weight set in the Target.

The balancer honors the DNS record’s ttl setting. Upon expiry, it queries the nameserver and updates the balancer. When a DNS record has ttl=0, the hostname is added as a single target, with the specified weight. The nameserver is queried for every request, adding latency to the request.

Schema

Set up a Target

Something wrong?

Help us make these docs great!

Kong Developer docs are open source. If you find these useful and want to make them better, contribute today!