- Go 97.5%
- Makefile 2.1%
- Dockerfile 0.4%
| yamls | ||
| .gitignore | ||
| controller.go | ||
| Dockerfile | ||
| kongclient.go | ||
| kongclient_test.go | ||
| main.go | ||
| Makefile | ||
| README.md | ||
| types.go | ||
| types_test.go | ||
| utils.go | ||
| utils_test.go | ||
KongK8
This project provides a process to watch the Kubernetes API for new services and configure Kong with the new API.
This application will watch for CREATE, UPDATE and DELETE requests for services. If the service being acted on has the "GATEWAY_UPSTREAM" annotation, the process will attempt to configure a Kong instance provided the "KONG_HOST".
Build
Build the main application into an executable called kubeconfig. The make script depends on the minikube implementation providing a registry that is accessible to outside users and building images into that registry.
For information on how to set up a registry for local dev, follow the instructions from this link, disregard the xhyve bits, unnecessary: Local dev with Kubernetes.
Once you have minikube-set up, you will need to start using the minikube docker via;
eval $(minikube docker-env)
Now that you have access to the docker within minikube, time to make your container.
make build
Run locally
To run the application locally, you will need to have a configured kubectl on your system.
Run the application by providing the kube configuration file with an absolute path.
On a Unix system, the invocation would be similar to the following;
./kongk8 --kubeconfig=/home/user/.kube/config
Run in Kubernetes
When running in Kubernetes, it is not necessary to provide a kube config, the application will automatically utilize the config that is inherently available to all kube containers.
That said, however, it is important to correctly configure the application to
communicate with your Kong host. An example is already configured in the
provided kube.yaml as http://kong.default.svc.cluster.local:8001. This is
expecting that there is a service definition that exposes port 8001 for the
Kong pod via a service with the matching port, 8001. If you expose a different
port from the service that maps to the Kong port 8001 that is also fine, adjust
your KONG_HOST url accordingly.
Below is an example configuration to run a KubeKongfig pod.
apiVersion: v1
kind: Pod
metadata:
name: kongfig
labels:
run: kongfig
spec:
containers:
- image: localhost:5000/ecsquest/konk8
imagePullPolicy: Always
name: kongfig
env:
- name: KONG_HOST
value: "http://kong.default.svc.cluster.local:8001"
Additional configuration
It is possible to further configure KubeKongfig with the following environment variables.
| Variable | Type | Default | Description |
|---|---|---|---|
| KONG_HOST | String | http://kube.local | The Kong API endpoint |
| IGNORE_NAMESPACE | String | ||
Ingress Annotations
The following annotations can be used to force certain configuration values for the Ingress->Kong mapping
| Annotation | Default | Description |
|---|---|---|
| GATEWAY_API_NAME * | "" | A unique name for the API entry |
| GATEWAY_UPSTREAM * | "" | The full URL of the upstream service to direct requests to |
| GATEWAY_PLUGINS | "" | Comma separated list of plugins to enable for the given API (Not used yet) |
| GATEWAY_URIS | "" | Comma separated list of url paths ig; "/path/foo" to match |
| GATEWAY_METHODS | "" | Comma separated list of HTTP VERBS allowed for endpoint |
| GATEWAY_STRIP_URL | "false" | If "true", will not provide the full URL path to the upstream service, ig: http://foo.com/fizz/buzz becomes http://my.ns.svc.cluster.local |
| GATEWAY_PRESERVE_HOST | "true" | |
* Required Annotation