Skip to main content

How to Installation Kong Service

INSTALLATION PROCESS:

$ sudo apt-get update 
$ sudo apt-get install openssl libpcre3 procps perl 
$ sudo dpkg -i kong-0.10.3.*.deb
CONFIGURE 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:8001
ISSUE THE FOLLOWING COMMAND TO START KONG:
$ kong start
Note: 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.conf
Kong 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.conf
The 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

Popular posts from this blog

Java Currency Formatter Solution

Given a  double-precision  number,  , denoting an amount of money, use the  NumberFormat  class'  getCurrencyInstance  method to convert   into the US, Indian, Chinese, and French currency formats. Then print the formatted values as follows: US: formattedPayment India: formattedPayment China: formattedPayment France: formattedPayment where   is   formatted according to the appropriate  Locale 's currency. Note:  India does not have a built-in Locale, so you must  construct one  where the language is  en  (i.e., English). Input Format A single double-precision number denoting  . Constraints Output Format On the first line, print  US: u  where   is   formatted for US currency.  On the second line, print  India: i  where   is   formatted for Indian currency.  On the third line...

Java Loops II print each element of our series as a single line of space-separated values.

We use the integers  ,  , and   to create the following series: You are given   queries in the form of  ,  , and  . For each query, print the series corresponding to the given  ,  , and   values as a single line of   space-separated integers. Input Format The first line contains an integer,  , denoting the number of queries.  Each line   of the   subsequent lines contains three space-separated integers describing the respective  ,  , and   values for that query. Constraints Output Format For each query, print the corresponding series on a new line. Each series must be printed in order as a single line of   space-separated integers. Sample Input 2 0 2 10 5 3 5 Sample Output 2 6 14 30 62 126 254 510 1022 2046 8 14 26 50 98 Explanation We have two queries: We use  ...

Java Static Initializer Block

Static initialization blocks are executed when the class is loaded, and you can initialize static variables in those blocks. It's time to test your knowledge of  Static initialization blocks . You can read about it  here. You are given a class  Solution  with a  main  method. Complete the given code so that it outputs the area of a parallelogram with breadth   and height  . You should read the variables from the standard input. If   or    , the output should be  "java.lang.Exception: Breadth and height must be positive"  without quotes. Input Format There are two lines of input. The first line contains  : the breadth of the parallelogram. The next line contains  : the height of the parallelogram. Constraints Output Format If both values are greater than zero, then the  main  method must output the area of the  parallelogram . Otherwise, pri...