Upstreams

Upsert a Upstream

Changed on

Create or Update Upstream using ID or name.

put/{workspace}/upstreams/{UpstreamIdOrName}

Request

  • Base URL
    http://localhost:8001
  • Auth
    API key in header Kong-Admin-Token

Path parameters

UpstreamIdOrName, string required

ID or name of the Upstream to lookup

workspace, string required
Example:team-payments

The name of the workspace

Request body

Upstream required

The upstream object represents a virtual hostname and can be used to loadbalance incoming requests over multiple services (targets). So for example an upstream named service.v1.xyz for a Service object whose host is service.v1.xyz. Requests for this Service would be proxied to the targets defined within the upstream. An upstream also includes a [health checker][healthchecks], which is able to enable and disable targets based on their ability or inability to serve requests. The configuration for the health checker is stored in the upstream object, and applies to all of its targets.

algorithm, 'consistent-hashing' | 'latency' | 'least-connections' | 'round-robin' | 'sticky-sessions' nullable

Which load balancing algorithm to use.

client_certificate, object nullable

If set, the certificate to be used as client certificate while TLS handshaking to the upstream server.

created_at, integer nullable

Unix epoch when the resource was created.

hash_fallback, 'consumer' | 'cookie' | 'header' | 'ip' | 'none' | 'path' | 'query_arg' | 'uri_capture' nullable

What to use as hashing input if the primary hash_on does not return a hash (eg. header is missing, or no Consumer identified). Not available if hash_on is set to cookie.

hash_fallback_header, string nullable

The header name to take the value from as hash input. Only required when hash_fallback is set to header.

hash_fallback_query_arg, string nullable

The name of the query string argument to take the value from as hash input. Only required when hash_fallback is set to query_arg.

hash_fallback_uri_capture, string nullable

The name of the route URI capture to take the value from as hash input. Only required when hash_fallback is set to uri_capture.

hash_on, 'consumer' | 'cookie' | 'header' | 'ip' | 'none' | 'path' | 'query_arg' | 'uri_capture' nullable

What to use as hashing input. Using none results in a weighted-round-robin scheme with no hashing.

hash_on_cookie, string nullable

The cookie name to take the value from as hash input. Only required when hash_on or hash_fallback is set to cookie. If the specified cookie is not in the request, Kong will generate a value and set the cookie in the response.

hash_on_cookie_path, string nullable

The cookie path to set in the response headers. Only required when hash_on or hash_fallback is set to cookie.

hash_on_header, string nullable

The header name to take the value from as hash input. Only required when hash_on is set to header.

hash_on_query_arg, string nullable

The name of the query string argument to take the value from as hash input. Only required when hash_on is set to query_arg.

hash_on_uri_capture, string nullable

The name of the route URI capture to take the value from as hash input. Only required when hash_on is set to uri_capture.

healthchecks, object nullable

The array of healthchecks.

host_header, string nullable

The hostname to be used as Host header when proxying requests through Kong.

id, string nullable

A string representing a UUID (universally unique identifier).

name, string required

This is a hostname, which must be equal to the host of a Service.

slots, integer nullable

The number of slots in the load balancer algorithm. If algorithm is set to round-robin, this setting determines the maximum number of slots. If algorithm is set to consistent-hashing, this setting determines the actual number of slots in the algorithm. Accepts an integer in the range 10-65536.

sticky_sessions_cookie, string nullable

The cookie name to keep sticky sessions.

sticky_sessions_cookie_path, string nullable

A string representing a URL path, such as /path/to/resource. Must start with a forward slash (/) and must not contain empty segments (i.e., two consecutive forward slashes).

tags, string[] nullable

An optional set of strings associated with the Upstream for grouping and filtering.

updated_at, integer nullable

Unix epoch when the resource was last updated.

use_srv_name, boolean nullable

If set, the balancer will use SRV hostname(if DNS Answer has SRV record) as the proxy upstream Host.

Example request

{
  "algorithm": "round-robin",
  "hash_fallback": "none",
  "hash_on": "none",
  "hash_on_cookie_path": "/",
  "healthchecks": {
    "active": {
      "concurrency": 10,
      "healthy": {
        "http_statuses": [
          200,
          302
        ],
        "interval": 0,
        "successes": 0
      },
      "http_path": "/",
      "https_verify_certificate": true,
      "timeout": 1,
      "type": "http",
      "unhealthy": {
        "http_failures": 0,
        "http_statuses": [
          429,
          404,
          500,
          501,
          502,
          503,
          504,
          505
        ],
        "interval": 0,
        "tcp_failures": 0,
        "timeouts": 0
      }
    },
    "passive": {
      "healthy": {
        "http_statuses": [
          200,
          201,
          202,
          203,
          204,
          205,
          206,
          207,
          208,
          226,
          300,
          301,
          302,
          303,
          304,
          305,
          306,
          307,
          308
        ],
        "successes": 0
      },
      "type": "http",
      "unhealthy": {
        "http_failures": 0,
        "http_statuses": [
          429,
          500,
          503
        ],
        "tcp_failures": 0,
        "timeouts": 0
      }
    },
    "threshold": 0
  },
  "id": "6eed5e9c-5398-4026-9a4c-d48f18a2431e",
  "name": "api.example.internal",
  "slots": 10000
}

Response

Successfully upserted Upstream

Upstream required

The upstream object represents a virtual hostname and can be used to loadbalance incoming requests over multiple services (targets). So for example an upstream named service.v1.xyz for a Service object whose host is service.v1.xyz. Requests for this Service would be proxied to the targets defined within the upstream. An upstream also includes a [health checker][healthchecks], which is able to enable and disable targets based on their ability or inability to serve requests. The configuration for the health checker is stored in the upstream object, and applies to all of its targets.

algorithm, 'consistent-hashing' | 'latency' | 'least-connections' | 'round-robin' | 'sticky-sessions' nullable

Which load balancing algorithm to use.

client_certificate, object nullable

If set, the certificate to be used as client certificate while TLS handshaking to the upstream server.

created_at, integer nullable

Unix epoch when the resource was created.

hash_fallback, 'consumer' | 'cookie' | 'header' | 'ip' | 'none' | 'path' | 'query_arg' | 'uri_capture' nullable

What to use as hashing input if the primary hash_on does not return a hash (eg. header is missing, or no Consumer identified). Not available if hash_on is set to cookie.

hash_fallback_header, string nullable

The header name to take the value from as hash input. Only required when hash_fallback is set to header.

hash_fallback_query_arg, string nullable

The name of the query string argument to take the value from as hash input. Only required when hash_fallback is set to query_arg.

hash_fallback_uri_capture, string nullable

The name of the route URI capture to take the value from as hash input. Only required when hash_fallback is set to uri_capture.

hash_on, 'consumer' | 'cookie' | 'header' | 'ip' | 'none' | 'path' | 'query_arg' | 'uri_capture' nullable

What to use as hashing input. Using none results in a weighted-round-robin scheme with no hashing.

hash_on_cookie, string nullable

The cookie name to take the value from as hash input. Only required when hash_on or hash_fallback is set to cookie. If the specified cookie is not in the request, Kong will generate a value and set the cookie in the response.

hash_on_cookie_path, string nullable

The cookie path to set in the response headers. Only required when hash_on or hash_fallback is set to cookie.

hash_on_header, string nullable

The header name to take the value from as hash input. Only required when hash_on is set to header.

hash_on_query_arg, string nullable

The name of the query string argument to take the value from as hash input. Only required when hash_on is set to query_arg.

hash_on_uri_capture, string nullable

The name of the route URI capture to take the value from as hash input. Only required when hash_on is set to uri_capture.

healthchecks, object nullable

The array of healthchecks.

host_header, string nullable

The hostname to be used as Host header when proxying requests through Kong.

id, string nullable

A string representing a UUID (universally unique identifier).

name, string required

This is a hostname, which must be equal to the host of a Service.

slots, integer nullable

The number of slots in the load balancer algorithm. If algorithm is set to round-robin, this setting determines the maximum number of slots. If algorithm is set to consistent-hashing, this setting determines the actual number of slots in the algorithm. Accepts an integer in the range 10-65536.

sticky_sessions_cookie, string nullable

The cookie name to keep sticky sessions.

sticky_sessions_cookie_path, string nullable

A string representing a URL path, such as /path/to/resource. Must start with a forward slash (/) and must not contain empty segments (i.e., two consecutive forward slashes).

tags, string[] nullable

An optional set of strings associated with the Upstream for grouping and filtering.

updated_at, integer nullable

Unix epoch when the resource was last updated.

use_srv_name, boolean nullable

If set, the balancer will use SRV hostname(if DNS Answer has SRV record) as the proxy upstream Host.

Example response

{
  "algorithm": "round-robin",
  "hash_fallback": "none",
  "hash_on": "none",
  "hash_on_cookie_path": "/",
  "healthchecks": {
    "active": {
      "concurrency": 10,
      "healthy": {
        "http_statuses": [
          200,
          302
        ],
        "interval": 0,
        "successes": 0
      },
      "http_path": "/",
      "https_verify_certificate": true,
      "timeout": 1,
      "type": "http",
      "unhealthy": {
        "http_failures": 0,
        "http_statuses": [
          429,
          404,
          500,
          501,
          502,
          503,
          504,
          505
        ],
        "interval": 0,
        "tcp_failures": 0,
        "timeouts": 0
      }
    },
    "passive": {
      "healthy": {
        "http_statuses": [
          200,
          201,
          202,
          203,
          204,
          205,
          206,
          207,
          208,
          226,
          300,
          301,
          302,
          303,
          304,
          305,
          306,
          307,
          308
        ],
        "successes": 0
      },
      "type": "http",
      "unhealthy": {
        "http_failures": 0,
        "http_statuses": [
          429,
          500,
          503
        ],
        "tcp_failures": 0,
        "timeouts": 0
      }
    },
    "threshold": 0
  },
  "id": "6eed5e9c-5398-4026-9a4c-d48f18a2431e",
  "name": "api.example.internal",
  "slots": 10000
}

Changes

    • breaking

      the healthchecks/active/healthy/successes request property's max was decreased to 254.00

    • breaking

      the healthchecks/active/unhealthy/http_failures request property's max was decreased to 254.00

    • breaking

      the healthchecks/active/unhealthy/tcp_failures request property's max was decreased to 254.00

    5 more changes in this revision