Skip to content

Instantly share code, notes, and snippets.

@nguyenhoang2009
Forked from montanaflynn/kong-dns.md
Created October 10, 2021 19:18
Show Gist options
  • Save nguyenhoang2009/d3faa98535ded28ca6721e00ad8d39b8 to your computer and use it in GitHub Desktop.
Save nguyenhoang2009/d3faa98535ded28ca6721e00ad8d39b8 to your computer and use it in GitHub Desktop.

Revisions

  1. Montana Flynn revised this gist Jun 4, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions kong-dns.md
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,8 @@
    # Kong

    Kong is a powerful proxy built on nginx. By taking a request and passing it to an upstream server and then returning the result to the client Kong can perform his magic. To know which requests go to which service Kong looks for a `host` header to match against. There's a few other ways Kong can match requests to services but for now that's the most basic route. Pun intended.
    Kong is a powerful proxy built on nginx. By taking a request and passing it to an upstream server and then returning the result to the client Kong can perform his magic. To know which requests go to which service Kong looks for a `Host` header to match against. There's a few other ways Kong can match requests to services but for now that's the most basic route. Pun intended.

    # Kong Start
    # Start

    Assuming everything has been installed and setup, such as dependencies and config files which can be found in the docs, it's time to turn Kong on. The first time Kong runs you'll see some Kong config values and initial migrations to the datastore.

  2. Montana Flynn revised this gist Jun 4, 2015. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions kong-dns.md
    Original file line number Diff line number Diff line change
    @@ -4,14 +4,12 @@ Kong is a powerful proxy built on nginx. By taking a request and passing it to a

    # Kong Start

    Assuming everything has been installed and setup, such as dependencies and config files which can be found in the docs, it's time to turn Kong on.
    Assuming everything has been installed and setup, such as dependencies and config files which can be found in the docs, it's time to turn Kong on. The first time Kong runs you'll see some Kong config values and initial migrations to the datastore.

    ```
    kong start
    ```

    You'll see some Kong config values run the first migrations to a datastore.

    # Add API

    Now we can add our APIs and Microservices to Kong. To do that we'll use Kong's RESTful admin API. Let's say you have a service that returns countries in JSON. It's a simple REST API and it's running on port 4444. You own the domain `restcountries.io` so let's use that as the `public_dns`.
  3. Montana Flynn revised this gist Jun 4, 2015. 1 changed file with 7 additions and 6 deletions.
    13 changes: 7 additions & 6 deletions kong-dns.md
    Original file line number Diff line number Diff line change
    @@ -10,11 +10,11 @@ Assuming everything has been installed and setup, such as dependencies and confi
    kong start
    ```

    You'll see some Kong config values run the first migrations to a datastore. Hopefully it ended with an [OK], if not we're on gitter.
    You'll see some Kong config values run the first migrations to a datastore.

    # Kong Add API
    # Add API

    Now we can add our APIs and Microservices to Kong. To do that we'll use Kong's RESTful admin API. Let's say you have a service that returns countries and other meta data. It's a simple REST API and it's running on port 4444. You own the domain `restcountries.io` so let's use that as the `public_dns`.
    Now we can add our APIs and Microservices to Kong. To do that we'll use Kong's RESTful admin API. Let's say you have a service that returns countries in JSON. It's a simple REST API and it's running on port 4444. You own the domain `restcountries.io` so let's use that as the `public_dns`.

    ```
    curl -i -X POST \
    @@ -24,17 +24,18 @@ curl -i -X POST \
    --data 'public_dns=restcountries.io'
    ```

    # Kong Request
    # Verify

    Now that it's added we can verify that Kong is serving it by making a request to Kong's proxy and suppyling the `Host` header which Kong will try to match any APIs with the same as the `public_dns` to know where to send the request upstream. Here's an example:

    ```
    curl http://127.0.0.1:8000 -H "host:restcountries.io"
    ```

    # DNS
    # Set DNS

    Now most likely you'll not want to add a host header manually with each request, so let's use our domain and have DNS take care of that for us. Set an A record for the domain pointing to your Kong installation. You can also modify `kong.yml` to use port 80 for the proxy and do a quick `kong restart` to have the effects take place. Now we can make a request directly to the domain and it will forward the correct `Host` header.

    ```
    curl http://restcountries.io

    ```
  4. Montana Flynn created this gist Jun 4, 2015.
    40 changes: 40 additions & 0 deletions kong-dns.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    # Kong

    Kong is a powerful proxy built on nginx. By taking a request and passing it to an upstream server and then returning the result to the client Kong can perform his magic. To know which requests go to which service Kong looks for a `host` header to match against. There's a few other ways Kong can match requests to services but for now that's the most basic route. Pun intended.

    # Kong Start

    Assuming everything has been installed and setup, such as dependencies and config files which can be found in the docs, it's time to turn Kong on.

    ```
    kong start
    ```

    You'll see some Kong config values run the first migrations to a datastore. Hopefully it ended with an [OK], if not we're on gitter.

    # Kong Add API

    Now we can add our APIs and Microservices to Kong. To do that we'll use Kong's RESTful admin API. Let's say you have a service that returns countries and other meta data. It's a simple REST API and it's running on port 4444. You own the domain `restcountries.io` so let's use that as the `public_dns`.

    ```
    curl -i -X POST \
    --url http://localhost:8001/apis/ \
    --data 'name=restcountries' \
    --data 'target_url=http://127.0.0.1:4444' \
    --data 'public_dns=restcountries.io'
    ```

    # Kong Request

    Now that it's added we can verify that Kong is serving it by making a request to Kong's proxy and suppyling the `Host` header which Kong will try to match any APIs with the same as the `public_dns` to know where to send the request upstream. Here's an example:

    ```
    curl http://127.0.0.1:8000 -H "host:restcountries.io"
    ```

    # DNS

    Now most likely you'll not want to add a host header manually with each request, so let's use our domain and have DNS take care of that for us. Set an A record for the domain pointing to your Kong installation. You can also modify `kong.yml` to use port 80 for the proxy and do a quick `kong restart` to have the effects take place. Now we can make a request directly to the domain and it will forward the correct `Host` header.

    curl http://restcountries.io