INSTALLATION PROCESS:
Configure Kong so it can connect to your database. Kong supports both PostgreSQL 9.4+ and Cassandra 3.x.x as its datastore.
If you are using Postgres, please provision a database and a user before starting Kong, ie:
CREATE USER kong; CREATE DATABASE kong OWNER kong;
START KONG:
VERIFY THAT KONG HAS STARTED SUCCESSFULLY :
The previous step runs migrations to prepare your database. Once these have finished you should see a message (Kong started) informing you that Kong is running.
By default Kong listens on the following ports:
:8000 on which Kong listens for incoming HTTP traffic from your clients, and forwards it to your upstream services.
:8443 on which Kong listens for incoming HTTPS traffic. This port has a similar behavior as the :8000 port, except that it expects HTTPS traffic only. This port can be disabled via the configuration file.
:8001 on which the Admin API used to configure Kong listens.
:8444 on which the Admin API listens for HTTPS traffic.
Stop Kong.
AS NEEDED YOU CAN STOP THE KONG PROCESS BY ISSUING THE FOLLOWING COMMAND:
Reload Kong.
ISSUE THE FOLLOWING COMMAND TO RELOAD KONG WITHOUT DOWNTIME:
ADDING YOUR API:
In this section, you'll be adding your API to the Kong layer. This is the first step to having Kong manage your API. For purposes of this Getting Started guide, we suggest adding the Mockbin API to Kong, as Mockbin is helpful for learning how Kong proxies your API requests.
Kong exposes a RESTful Admin API on port :8001 for managing the configuration of your Kong instance or cluster.
Add your API using the Admin API
Issue the following cURL request to add your first API (Mockbin) to Kong:
You should see a similar response from that request:
Forward your requests through Kong
Issue the following cURL request to verify that Kong is properly forwarding requests to your API. Note that by default Kong handles proxy requests on port :8000:
Host: <given host>
CONFIGURATION LOADING :
Kong comes with a default configuration file that can be found at /etc/kong/kong.conf.default if you installed Kong via one of the official packages. To start configuring Kong, you can copy this file:
/etc/kong/kong.conf
/etc/kong.conf
You can override this behavior by specifying a custom path for your configuration file using the -c / --conf argument in the CLI:
Back to TOC
Verifying your configuration
You can verify the integrity of your settings with the check command:
This command will take into account the environment variables you have currently set, and will error out in case your settings are invalid.
Additionally, you can also use the CLI in debug mode to have more insight as to what properties Kong is being started with:
$ sudo apt-get update $ sudo apt-get install openssl libpcre3 procps perl $ sudo dpkg -i kong-0.10.3.*.debCONFIGURE YOUR DATABASE :
Configure Kong so it can connect to your database. Kong supports both PostgreSQL 9.4+ and Cassandra 3.x.x as its datastore.
If you are using Postgres, please provision a database and a user before starting Kong, ie:
CREATE USER kong; CREATE DATABASE kong OWNER kong;
START KONG:
$ kong start# Kong is running
$ curl 127.0.0.1:8001ISSUE THE FOLLOWING COMMAND TO START KONG:
$ kong startNote: The CLI also accepts a configuration (-c <path_to_config>) option allowing you to point to different configurations.
VERIFY THAT KONG HAS STARTED SUCCESSFULLY :
The previous step runs migrations to prepare your database. Once these have finished you should see a message (Kong started) informing you that Kong is running.
By default Kong listens on the following ports:
:8000 on which Kong listens for incoming HTTP traffic from your clients, and forwards it to your upstream services.
:8443 on which Kong listens for incoming HTTPS traffic. This port has a similar behavior as the :8000 port, except that it expects HTTPS traffic only. This port can be disabled via the configuration file.
:8001 on which the Admin API used to configure Kong listens.
:8444 on which the Admin API listens for HTTPS traffic.
Stop Kong.
AS NEEDED YOU CAN STOP THE KONG PROCESS BY ISSUING THE FOLLOWING COMMAND:
$ kong stop
Reload Kong.
ISSUE THE FOLLOWING COMMAND TO RELOAD KONG WITHOUT DOWNTIME:
$ kong reload
ADDING YOUR API:
In this section, you'll be adding your API to the Kong layer. This is the first step to having Kong manage your API. For purposes of this Getting Started guide, we suggest adding the Mockbin API to Kong, as Mockbin is helpful for learning how Kong proxies your API requests.
Kong exposes a RESTful Admin API on port :8001 for managing the configuration of your Kong instance or cluster.
Add your API using the Admin API
Issue the following cURL request to add your first API (Mockbin) to Kong:
$ curl -i -X POST \ --url http://localhost:8001/apis/ \ --data 'name=example-api' \ --data 'hosts=example.com' \ --data 'upstream_url=http://httpbin.org' Verify that your API has been added
You should see a similar response from that request:
HTTP/1.1 201 Created Content-Type: application/json Connection: keep-alive
{ "created_at": 1488830759000, "hosts": [ "example.com" ], "http_if_terminated": true, "https_only": false, "id": "6378122c-a0a1-438d-a5c6-efabae9fb969", "name": "example-api", "preserve_host": false, "retries": 5, "strip_uri": true, "upstream_connect_timeout": 60000, "upstream_read_timeout": 60000, "upstream_send_timeout": 60000, "upstream_url": "http://httpbin.org" }Kong is now aware of your API and ready to proxy requests.
Forward your requests through Kong
Issue the following cURL request to verify that Kong is properly forwarding requests to your API. Note that by default Kong handles proxy requests on port :8000:
$ curl -i -X GET \ --url http://localhost:8000/ \ --header 'Host: example.com'A successful response means Kong is now forwarding requests made to http://localhost:8000 to the upstream_url we configured in step #1, and is forwarding the response back to us. Kong knows to do this through the header defined in the above cURL request:
Host: <given host>
CONFIGURATION LOADING :
Kong comes with a default configuration file that can be found at /etc/kong/kong.conf.default if you installed Kong via one of the official packages. To start configuring Kong, you can copy this file:
$ cp /etc/kong/kong.conf.default /etc/kong/kong.confKong will operate with default settings should all the values in your configuration be commented-out. Upon starting, Kong looks for several default locations that might contain a configuration file:
/etc/kong/kong.conf
/etc/kong.conf
You can override this behavior by specifying a custom path for your configuration file using the -c / --conf argument in the CLI:
$ kong start --conf /path/to/kong.confThe configuration format is straightforward: simply uncomment any property (comments are defined by the # character) and modify it to your needs. Booleans values can be specified as on/off or true/false for convenience.
Back to TOC
Verifying your configuration
You can verify the integrity of your settings with the check command:
$ kong check <path/to/kong.conf>configuration at <path/to/kong.conf> is valid
This command will take into account the environment variables you have currently set, and will error out in case your settings are invalid.
Additionally, you can also use the CLI in debug mode to have more insight as to what properties Kong is being started with:
$ kong start -c <kong.conf> --vv 2016/08/11 14:53:36 [verbose] no config file found at /etc/kong.conf 2016/08/11 14:53:36 [verbose] no config file found at /etc/kong/kong.conf 2016/08/11 14:53:36 [debug] admin_listen = "0.0.0.0:8001" 2016/08/11 14:53:36 [debug] cluster_listen = "0.0.0.0:7946" 2016/08/11 14:53:36 [debug] cluster_listen_rpc = "127.0.0.1:7373" 2016/08/11 14:53:36 [debug] cluster_profile = "wan" 2016/08/11 14:53:36 [debug] cluster_ttl_on_failure = 3600 2016/08/11 14:53:36 [debug] database = "postgres" 2016/08/11 14:53:36 [debug] log_level = "notice" [...]
Comments
Post a Comment