CLI Reference

Introduction

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:

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

Back to top

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

Back to top


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.

Back to top


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

Back to top


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)

Back to top


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
  8. after 'up'.
  9. list List executed migrations.
  10. reset Reset the database.
  11. migrate-community-to-enterprise Migrates Kong Community entities to
  12. Kong Enterprise in the default
  13. workspace.
  14. upgrade-workspace-table Outputs a script to be run on the db to
  15. upgrade the entity for 2.x workspaces
  16. implementation.
  17. reinitialize-workspace-entity-counters Resets the entity counters from the
  18. database entities.
  19. Options:
  20. -y,--yes Assume "yes" to prompts and run
  21. non-interactively.
  22. -q,--quiet Suppress all output.
  23. -f,--force Run migrations even if database
  24. reports as already executed.
  25. With 'migrate-community-to-enterprise',
  26. it disables the workspace entities
  27. check.
  28. --db-timeout (default 60) Timeout, in seconds, for all database
  29. operations (including schema consensus
  30. for Cassandra).
  31. --lock-timeout (default 60) Timeout, in seconds, for nodes waiting
  32. on the leader node to finish running
  33. migrations.
  34. -c,--conf (optional string) Configuration file.

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

Back to top


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

Back to top


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

Back to top


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 (default 60)
  12. --lock-timeout (default 60)

Back to top


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 (default 60) Timeout, in seconds, for all database
  10. operations (including schema consensus for
  11. Cassandra).
  12. --lock-timeout (default 60) When --run-migrations is enabled, timeout,
  13. in seconds, for nodes waiting on the
  14. leader node to finish running migrations.

Back to top


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

Back to top


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

Back to top