Dump Kong Gateway configuration

The simplest way to dump a Kong Gateway configuration is deck gateway dump. However, I sometimes find myself working with a dataplane that does not have an admin API exposed.

Here's a one-liner that dumps the config from the running process (enterprise only).

Important: This dumps in DB-less format, not deck format. Use deck file format to convert between them.

bash
docker exec -i "${docker_hash}" sh -c \
'echo "require([[kong.db.declarative]]).export_from_db({write=function(_,s) io.write(s) end})" | kong runner /dev/stdin' \
> "${output_file}"

Or for kubectl:

bash
kubectl exec -n kong -i deploy/kong-gateway -- sh -c \
'echo "require([[kong.db.declarative]]).export_from_db({write=function(_,s) io.write(s) end})" | kong runner /dev/stdin' \
> "${output_file}"