You are browsing documentation for an older version. See the latest documentation here.

CLI Reference

The provided CLI (Command Line Interface) allows you to start, stop, and manage your Kong instances. The CLI manages your local node (as in, on the current machine).

If you haven’t yet, we recommend you read the configuration reference.

Global flags

All commands take a set of special, optional flags as arguments:

  • -h, --help: print the command’s help message
  • --v: enable verbose mode
  • --vv: enable debug mode (noisy)

Available commands

kong check

  1. Usage: kong check <conf>
  2. Check the validity of a given Kong configuration file.
  3. <conf> (default /etc/kong/kong.conf) configuration file

kong config

  1. Usage: kong config COMMAND [OPTIONS]
  2. Use declarative configuration files with Kong.
  3. The available commands are:
  4. init [<file>] Generate an example config file to
  5. get you started. If a filename
  6. is not given, ./kong.yml is used
  7. by default.
  8. db_import <file> Import a declarative config file into
  9. the Kong database.
  10. db_export [<file>] Export the Kong database into a
  11. declarative config file. If a filename
  12. is not given, ./kong.yml is used
  13. by default.
  14. parse <file> Parse a declarative config file (check
  15. its syntax) but do not load it into Kong.
  16. Options:
  17. -c,--conf (optional string) Configuration file.
  18. -p,--prefix (optional string) Override prefix directory.

Note: db_export is only supported with open-source Kong Gateway packages.


Kong Debug

  1. Usage: kong debug COMMAND [OPTIONS]
  2. Invoke various debugging features in Kong.
  3. The available commands are:
  4. For the endpoint in kong/api/routes/debug.lua,
  5. profiling cpu <start|stop|status> Generate the raw data of Lua-land CPU
  6. flamegraph.
  7. --mode (optional string default "time")
  8. The mode of CPU profiling, `time` means
  9. time-based profiling, `instruction`
  10. means instruction-counter-based
  11. profiling.
  12. --step (optional number) The initial value of the instruction
  13. counter. A sample will be taken when the
  14. counter goes to zero.
  15. (only for mode=instruction)
  16. --interval (optional number) Sampling interval in microseconds.
  17. (only for mode=time)
  18. --timeout (optional number) Profiling will be stopped automatically
  19. after the timeout (in seconds).
  20. default: 10
  21. profiling memory <start|stop|status> Generating the Lua GC heap memory
  22. tracing data (on-the-fly tracing).
  23. --stack_depth (optional number) The maximum depth of the Lua stack.
  24. --timeout (optional number) Profiling will be stopped automatically
  25. after the timeout (in seconds).
  26. default: 10
  27. profiling gc-snapshot Generate a Lua GC heap snapshot.
  28. --timeout (optional number) Profiling will be stopped automatically
  29. after the timeout (in seconds).
  30. default: 120
  31. log_level set --level <log_level> Set the logging level.
  32. It cannot work while not using a
  33. database because it needs to be
  34. protected by RBAC and RBAC is not
  35. available in DB-less.
  36. --level (optional string) It can be one of the following: debug,
  37. info, notice, warn, error, crit, alert,
  38. or emerg.
  39. --timeout (optional number) The log level will be restored to the
  40. original level after the timeout (in
  41. seconds).
  42. default: 60
  43. log_level get Get the logging level.
  44. Options:
  45. --pid (optional number) The workers PID for profiling.
  46. -f Follow mode for certain commands, such
  47. as 'profiling {cpu|memory} status'.
  48. It continuously checks the status until
  49. it completes.
  50. -c,--conf (optional string) Configuration file.
  51. -p,--prefix (optional string) Override prefix directory.
  52. EXIT CODES
  53. Various error codes and their associated messages may be returned by this
  54. command during error situations.
  55. `0` - Success. The requested operation completed successfully.
  56. `1` - Error. The requested operation failed. An error message is available in
  57. the command output.
  58. `2` - In progress. The profiling is still in progress.
  59. The following commands make use of this return value:
  60. - kong debug profiling cpu start
  61. - kong debug profiling memory start
  62. - kong debug profiling gc-snapshot

kong health

  1. Usage: kong health [OPTIONS]
  2. Check if the necessary services are running for this node.
  3. Options:
  4. -p,--prefix (optional string) prefix at which Kong should be running

kong hybrid

  1. Usage: kong hybrid COMMAND [OPTIONS]
  2. Hybrid mode utilities for Kong.
  3. The available commands are:
  4. gen_cert [<cert> <key>] Generate a certificate/key pair that is suitable
  5. for use in hybrid mode deployment.
  6. Cert and key will be written to
  7. './cluster.crt' and './cluster.key' inside
  8. the current directory unless filenames are given.
  9. Options:
  10. -d,--days (optional number) Override certificate validity duration.
  11. Default: 1095 days (3 years)

kong migrations

  1. Usage: kong migrations COMMAND [OPTIONS]
  2. Manage database schema migrations.
  3. The available commands are:
  4. bootstrap Bootstrap the database and run all
  5. migrations.
  6. up Run any new migrations.
  7. finish Finish running any pending migrations after
  8. 'up'.
  9. list List executed migrations.
  10. reset Reset the database.
  11. The `reset` command erases all of the data
  12. in Kong's database and deletes all of the schemas.
  13. migrate-community-to-enterprise Migrates Kong Community entities to
  14. Kong Enterprise in the default
  15. workspace.
  16. upgrade-workspace-table Outputs a script to be run on the db to
  17. upgrade the entity for 2.x workspaces
  18. implementation.
  19. reinitialize-workspace-entity-counters Resets the entity counters from the
  20. database entities.
  21. status Dump the database migration status in JSON format.
  22. Options:
  23. -y,--yes Assume "yes" to prompts and run
  24. non-interactively.
  25. -q,--quiet Suppress all output.
  26. -f,--force Run migrations even if database reports
  27. as already executed.
  28. With 'migrate-community-to-enterprise' it
  29. disables the workspace entities check.
  30. --db-timeout (optional number) Timeout, in seconds, for all database
  31. operations.
  32. --lock-timeout (default 60) Timeout, in seconds, for nodes waiting on
  33. the leader node to finish running
  34. migrations.
  35. -c,--conf (optional string) Configuration file.
  36. -p,--prefix (optional string) Override prefix directory.
  37. --v verbose
  38. --vv debug

kong prepare

This command prepares the Kong prefix folder, with its sub-folders and files.

  1. Usage: kong prepare [OPTIONS]
  2. Prepare the Kong prefix in the configured prefix directory. This command can
  3. be used to start Kong from the nginx binary without using the 'kong start'
  4. command.
  5. Example usage:
  6. kong migrations up
  7. kong prepare -p /usr/local/kong -c kong.conf
  8. nginx -p /usr/local/kong -c /usr/local/kong/nginx.conf
  9. Options:
  10. -c,--conf (optional string) configuration file
  11. -p,--prefix (optional string) override prefix directory
  12. --nginx-conf (optional string) custom Nginx configuration template

kong quit

  1. Usage: kong quit [OPTIONS]
  2. Gracefully quit a running Kong node (Nginx and other
  3. configured services) in given prefix directory.
  4. This command sends a SIGQUIT signal to Nginx, meaning all
  5. requests will finish processing before shutting down.
  6. If the timeout delay is reached, the node will be forcefully
  7. stopped (SIGTERM).
  8. Options:
  9. -p,--prefix (optional string) prefix Kong is running at
  10. -t,--timeout (default 10) timeout before forced shutdown
  11. -w,--wait (default 0) wait time before initiating the shutdown

kong reload

  1. Usage: kong reload [OPTIONS]
  2. Reload a Kong node (and start other configured services
  3. if necessary) in given prefix directory.
  4. This command sends a HUP signal to Nginx, which will spawn
  5. new workers (taking configuration changes into account),
  6. and stop the old ones when they have finished processing
  7. current requests.
  8. Options:
  9. -c,--conf (optional string) configuration file
  10. -p,--prefix (optional string) prefix Kong is running at
  11. --nginx-conf (optional string) custom Nginx configuration template
  12. --nginx-conf-flags (optional string) flags that can be used to control
  13. how Nginx configuration templates are rendered

kong restart

  1. Usage: kong restart [OPTIONS]
  2. Restart a Kong node (and other configured services like Serf)
  3. in the given prefix directory.
  4. This command is equivalent to doing both 'kong stop' and
  5. 'kong start'.
  6. Options:
  7. -c,--conf (optional string) configuration file
  8. -p,--prefix (optional string) prefix at which Kong should be running
  9. --nginx-conf (optional string) custom Nginx configuration template
  10. --run-migrations (optional boolean) optionally run migrations on the DB
  11. --db-timeout (optional number)
  12. --lock-timeout (default 60)
  13. --nginx-conf-flags (optional string) flags that can be used to control
  14. how Nginx configuration templates are rendered

kong runner

  1. Usage: kong runner [file] [args]
  2. Execute a lua file in a kong node. the `kong` variable is available to
  3. reach the DAO, PDK, etc. The variable `args` can be used to access all
  4. arguments (args[1] being the lua filename being run).
  5. Example usage:
  6. kong runner file.lua arg1 arg2
  7. echo 'print("foo")' | kong runner

kong start

  1. Usage: kong start [OPTIONS]
  2. Start Kong (Nginx and other configured services) in the configured
  3. prefix directory.
  4. Options:
  5. -c,--conf (optional string) Configuration file.
  6. -p,--prefix (optional string) Override prefix directory.
  7. --nginx-conf (optional string) Custom Nginx configuration template.
  8. --run-migrations (optional boolean) Run migrations before starting.
  9. --db-timeout (optional number) Timeout, in seconds, for all database
  10. operations.
  11. --lock-timeout (default 60) When --run-migrations is enabled, timeout,
  12. in seconds, for nodes waiting on the
  13. leader node to finish running migrations.
  14. --nginx-conf-flags (optional string) Flags that can be used to control
  15. how Nginx configuration templates are rendered

kong stop

  1. Usage: kong stop [OPTIONS]
  2. Stop a running Kong node (Nginx and other configured services) in given
  3. prefix directory.
  4. This command sends a SIGTERM signal to Nginx.
  5. Options:
  6. -p,--prefix (optional string) prefix Kong is running at

kong vault

  1. Usage: kong vault COMMAND [OPTIONS]
  2. Vault utilities for Kong.
  3. Example usage:
  4. TEST=hello kong vault get env/test
  5. The available commands are:
  6. get <reference> Retrieves a value for <reference>
  7. Options:
  8. -c,--conf (optional string) configuration file
  9. -p,--prefix (optional string) override prefix directory

kong version

  1. Usage: kong version [OPTIONS]
  2. Print Kong's version. With the -a option, will print
  3. the version of all underlying dependencies.
  4. Options:
  5. -a,--all get version of all dependencies