Skip to content

Instantly share code, notes, and snippets.

@toopay
Last active September 1, 2020 09:44
Show Gist options
  • Save toopay/a3d9892db38f1eed10a80c196e2da31c to your computer and use it in GitHub Desktop.
Save toopay/a3d9892db38f1eed10a80c196e2da31c to your computer and use it in GitHub Desktop.
Kongfig Schema

Overview

Kongfig allow declarative configuration. We can define our list of APIs and consumers in json/yaml and then run kongfig to ensure that our Kong is configured correctly. At the simplest form, your config.yml can be just :

---
  apis:
    -
      name: "mockbin"
      attributes:
        upstream_url: "http://mockbin.com/"
        request_host: "mockbin.com"

Schema Reference

There are 4 top level keys available :

Key Description
apis List all of your micros APIs
consumers List of required consumers
plugins List of global plugins
host Kong Admin API Host
headers List of custom headers to be included with every request made by Kongfig

Most of the time, you will only need to specifiy apis and consumers, and we'll walkthrough them below.

apis

The apis contains an array of your APIs definition. There are 4 top level keys available for each API definition :

Key Description
name The API name.
ensure The flag of the API. Available values are present and removed, default to present
attributes List of API attributes
plugins List of API plugins

attributes

You can define more deeply about your API attributes, available keys are :

Key Requirement Description
upstream_url required The base target URL that points to your API server. This URL will be used for proxying requests. For example: https://example.com.
hosts semi-optional A list of domain names that point to your API. For example: example.com. At least one of hosts, uris, or methods should be specified.
uris semi-optional A list of URIs prefixes that point to your API. For example: /my-path. At least one of hosts, uris, or methods should be specified.
methods semi-optional A list of HTTP methods that point to your API. For example: GET,POST. At least one of hosts, uris, or methods should be specified.
strip_uri optional When matching an API via one of the uris prefixes, strip that matching prefix from the upstream URI to be requested. Default: true.
preserve_host optional When matching an API via one of the hosts domain names, make sure the request Host header is forwarded to the upstream service. By default, this is false, and the upstream Host header will be extracted from the configured upstream_url.
retries optional The number of retries to execute upon failure to proxy. The default is 5.
upstream_connect_timeout optional The timeout in milliseconds for establishing a connection to your upstream service. Defaults to 60000.
upstream_send_timeout optional The timeout in milliseconds between two successive write operations for transmitting a request to your upstream service Defaults to 60000.
upstream_read_timeout optional The timeout in milliseconds between two successive read operations for transmitting a request to your upstream service Defaults to 60000.
https_only optional To be enabled if you wish to only serve an API through HTTPS, on the appropriate port (8443 by default). Default: false.
http_if_terminated optional Consider the X-Forwarded-Proto header when enforcing HTTPS only traffic. Default: false.

plugins

consumers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment