Skip to content

Commit 5ceddce

Browse files
authoredFeb 26, 2020
Merge pull request kubernetes#88577 from corneliusweig/w/plugin-and-krew-documentation
Add documentation around plugins
2 parents 1deac1e + ed0e035 commit 5ceddce

File tree

5 files changed

+130
-2
lines changed

5 files changed

+130
-2
lines changed
 

‎staging/src/k8s.io/kubectl/docs/book/SUMMARY.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@
3333
* [Port Forward to Pods](pages/container_debugging/port_forward_to_pods.md)
3434
* [Proxying Traffic to Services](pages/container_debugging/proxying_traffic_to_services.md)
3535

36+
## Extending Kubectl
37+
38+
* [Plugin mechanism](pages/extending_kubectl/plugin_mechanism.md)
39+
* [Discovering plugins](pages/extending_kubectl/discovering_plugins.md)
40+
3641
## App Customization
3742

3843
* [Introduction](pages/app_customization/introduction.md)
@@ -68,4 +73,4 @@
6873
* [Introduction](pages/imperative_porcelain/introduction.md)
6974
* [Creating Resources](pages/imperative_porcelain/creating_resources.md)
7075
* [Setting Fields](pages/imperative_porcelain/setting_fields.md)
71-
* [Editing Workloads](pages/imperative_porcelain/editing_workloads.md)
76+
* [Editing Workloads](pages/imperative_porcelain/editing_workloads.md)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{% panel style="success", title="Providing Feedback" %}
2+
**Provide feedback at the [survey](https://www.surveymonkey.com/r/CLQBQHR)**
3+
{% endpanel %}
4+
5+
{% panel style="info", title="TL;DR" %}
6+
- [krew.dev](https://github.com/kubernetes-sigs/krew/#installation) is a kubernetes sub-project to discover and manage plugins
7+
{% endpanel %}
8+
9+
# Krew
10+
11+
By design, `kubectl` does not install plugins. This task is left to the kubernetes sub-project
12+
[krew.dev](https://github.com/kubernetes-sigs/krew/#installation) which needs to be installed separately.
13+
Krew helps to
14+
15+
- discover plugins
16+
- get updates for installed plugins
17+
- remove plugins
18+
19+
## Installing krew
20+
21+
Krew should be used as a kubectl plugin. To set yourself up to using krew, you need to do two things:
22+
23+
1. Install git
24+
1. Install krew as described on the project page [krew.dev](https://github.com/kubernetes-sigs/krew/#installation).
25+
1. Add the krew bin folder to your `PATH` environment variable. For example, in bash `export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"`.
26+
27+
## Krew capabilities
28+
29+
{% method %}
30+
Discover plugins
31+
{% sample lang="yaml" %}
32+
```bash
33+
kubectl krew search
34+
```
35+
{% endmethod %}
36+
37+
{% method %}
38+
Install a plugin
39+
{% sample lang="yaml" %}
40+
```bash
41+
kubectl krew install access-matrix
42+
```
43+
{% endmethod %}
44+
45+
{% method %}
46+
Upgrade all installed plugins
47+
{% sample lang="yaml" %}
48+
```bash
49+
kubectl krew upgrade
50+
```
51+
{% endmethod %}
52+
53+
{% method %}
54+
Show details about a plugin
55+
{% sample lang="yaml" %}
56+
```bash
57+
kubectl krew info access-matrix
58+
```
59+
{% endmethod %}
60+
61+
{% method %}
62+
Uninstall a plugin
63+
{% sample lang="yaml" %}
64+
```bash
65+
kubectl krew uninstall access-matrix
66+
```
67+
{% endmethod %}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{% panel style="success", title="Providing Feedback" %}
2+
**Provide feedback at the [survey](https://www.surveymonkey.com/r/CLQBQHR)**
3+
{% endpanel %}
4+
5+
{% panel style="info", title="TL;DR" %}
6+
- Drop executables named `kubectl-plugin_name` on your `PATH` and invoke with `kubectl plugin-name`
7+
- `kubectl plugin list` shows available plugins
8+
{% endpanel %}
9+
10+
# Kubectl plugins
11+
12+
Kubectl plugins are a lightweight mechanism to extend `kubectl` with custom functionality to suit your needs.
13+
14+
## Plugin mechanism
15+
16+
As of version 1.12, kubectl has a simple plugin mechanism to expose binaries on your `PATH` as kubectl subcommands.
17+
When invoking an unknown subcommand `kubectl my-plugin`, kubectl starts searching for an executable named `kubectl-my_plugin` on your `PATH`.
18+
Note how the dash is mapped to an underscore. This is to enable plugins that are invoked by multiple words, for example
19+
`kubectl my plugin` would trigger a search for the commands `kubectl-my-plugin` or `kubectl-my`. The more specific match
20+
always wins over the other, so if both `kubectl-my` and `kubectl-my-plugin` exist, the latter will be called.
21+
When a matching executable is found, kubectl calls it, forwarding all extra arguments.
22+
23+
The reference on [kubernetes.io](https://kubernetes.io/docs/tasks/extend-kubectl/kubectl-plugins/) knows more.
24+
25+
{% panel style="info", title="Windows compatibility" %}
26+
On windows, the minimum required version to use the plugin mechanism is 1.14.
27+
{% endpanel %}
28+
29+
{% method %}
30+
Listing installed plugins
31+
{% sample lang="yaml" %}
32+
```bash
33+
kubectl plugin list
34+
```
35+
{% endmethod %}

‎staging/src/k8s.io/kubectl/docs/book/pages/kubectl_book/getting_started.md

+18
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,21 @@ root@nginx-deployment-5c689d88bb-s7xcv:/#
205205
```
206206

207207
{% endmethod %}
208+
209+
## Extending kubectl
210+
211+
There is a plugin mechanism to adapt `kubectl` to your particular needs.
212+
213+
{% method %}
214+
215+
Show which plugins are currently available
216+
217+
{% sample lang="yaml" %}
218+
219+
```bash
220+
kubectl plugin list
221+
```
222+
223+
{% endmethod %}
224+
225+
The easiest way to discover and install plugins is via the kubernetes sub-project [krew.dev](https://github.com/kubernetes-sigs/krew/#installation).

‎staging/src/k8s.io/kubectl/pkg/cmd/plugin/plugin.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ var (
3838
Provides utilities for interacting with plugins.
3939
4040
Plugins provide extended functionality that is not part of the major command-line distribution.
41-
Please refer to the documentation and examples for more information about how write your own plugins.`)
41+
Please refer to the documentation and examples for more information about how write your own plugins.
42+
43+
The easiest way to discover and install plugins is via the kubernetes sub-project krew.
44+
To install krew, visit [krew.dev](https://github.com/kubernetes-sigs/krew/#installation)`)
4245

4346
pluginListLong = templates.LongDesc(`
4447
List all available plugin files on a user's PATH.

0 commit comments

Comments
 (0)
Please sign in to comment.