/docker-kong-service

Extension of the official Docker image for Kong, with Rancher and extra Env Vars support

Primary LanguageShell

Kong as a Docker Service

This an extension of the official Docker image for Kong, with support to for Rancher, Kubernetes, or Tutum/Docker Cloud.

You can also spin this up by adding in my custom Rancher Catalog

Justifications

The official docker-kong image allows for:

1. linking `Cassandra` or `Postgres` database containers
2. connecting to external databases via custom `kong.yml` config file by replacing the `/etc/kong/` volume.

However when using Rancher or Kubernetes, containers are organised into Services deployed across multiple machine node clusters. Therefore it's not feasible to mount custom config files into volumes on each machine which are spun up and down on demand. See related question here

Also there is no need to explicitly link containers since internal DNS resolutions for Services comes out of the box in platforms such as Rancher or Tutum.

By configuring Cassandra and Postgres purely using Environment Variables, it is a lot easier to point to either an external database instance or an internal database service. Without having to build a custom kong config.

Supported tags and respective Dockerfile links

How to use this image

Existing docker-kong usages still applies. The following extra Environment Variables are added:

Kong Environment Variables:

Env Var Default Description
DATABASE cassandra either cassandra or postgres as per official image
CLUSTER_LISTEN 0.0.0.0:7946 host ip and port. When rancher is specified, uses the Rancher Meta Data Service to work out the correct container ip address for cluster_listen. Other platforms can be extended quite easily.

Cassandra Environment Variables:

Env Var Default Description
CASSANDRA_CONTACT_POINTS kong-database:9046 Mandatory. Specify custom values in the format of \"ip1:9046\",\"ip2:9046\" or use a internal service name
CASSANDRA_KEYSPACE kong Optional
CASSANDRA_USER kong Optional
CASSANDRA_PASSWORD kong Optional

Example:

$ docker run -d --name kong \
    -e DATABASE=cassandra \
    -e CASSANDRA_CONTACT_POINTS='\"52.5.149.55:9042\",\"52.5.149.56:9042\"' \
    -p 8000:8000 -p 8443:8443 -p 8001:8001 -p 7946:7946 -p 7946:7946/udp \
    littlebaydigital/kong

or:

$ docker run -d --name kong \
    -e DATABASE=cassandra \
    -e CASSANDRA_CONTACT_POINTS='\"cassandra-service.kong-stack:9042\"' \
    -p 8000:8000 -p 8443:8443 -p 8001:8001 -p 7946:7946 -p 7946:7946/udp \
    littlebaydigital/kong

Sample Docker Compose: https://github.com/yunspace/my-docker-stacks/tree/master/kong/cassandra

Postgres Environment Variables:

Env Var Default Description
POSTGRES_HOST kong-database Mandatory. Either a external hostname or internal service name
POSTGRES_PORT 5432 Optional.
POSTGRES_DATABASE kong Optional.
POSTGRES_USER kong Optional.
POSTGRES_PASSWORD kong Optional.

Example:

$ docker run -d --name kong \
    -e DATABASE=postgres \
    -e POSTGRES_HOST=127.0.0.1 \
    -p 8000:8000 -p 8443:8443 -p 8001:8001 -p 7946:7946 -p 7946:7946/udp \
    --security-opt seccomp:unconfined \
    littlebaydigital/kong

or:

$ docker run -d --name kong \
    -e DATABASE=postgres \
    -e POSTGRES_HOST=postgres-service.kong-stack \
    -p 8000:8000 -p 8443:8443 -p 8001:8001 -p 7946:7946 -p 7946:7946/udp \
    --security-opt seccomp:unconfined \
    littlebaydigital/kong

Sample Docker Compose: https://github.com/yunspace/my-docker-stacks/tree/master/kong/postgres