Introduction to plugin development
If you are looking to start developing plugins for kubectl
, read the
Kubernetes
documentation
on this topic.
To summarize the documentation, the procedure is to:
- Create an executable binary, named
kubectl-foo
(for example) to have a plugin that can be
invoked as kubectl foo
.
- Place the executable in a directory that is listed in the user’s
PATH
environment
variable. (You don’t have to do this for plugins distributed with Krew).
- You can’t overwrite a built-in
kubectl
command with a plugin.
Note: If you are writing a plugin in Go, consider using the cli-runtime project,
which is designed to provide the same command-line arguments, kubeconfig
parser, Kubernetes API REST client, and printing logic. Look at
sample-cli-plugin for an example of a kubectl plugin.
Also, see the unofficial GitHub template
repo for a Krew plugin
in Go that implements some best practices covered later in this guide, and helps
you automate releases using GoReleaser to create a release when a tag is pushed.
When developing your own plugins, make sure you check out:
After you develop a plugin with a good name following the best practices, you
can develop a Krew plugin manifest and
submit your plugin to Krew.