Kubectl Plugins¶
I must admit - I love tools that can be extended beyond what was initially intended for said tool. The kubectl
command is such a great example of this!
Extending kubectl
has been possible for some time and the mechanism is rather straight forward. In time, however, it was expected that there will be a number of useful extensions/plugins that many more people would want to use. The challange is that kubectl
itself never intended to also manage all these extra functionality - it's beyond the scope of it's maintainers and it was up to the community of users to solve this problem.
Enter krew
, which "... helps you discover plugins, install and manage them on your machine.".
The installation instructions is pretty straight forward and worked without any issues on my Ubuntu system.
After installation, make sure your local index is up to date:
kubectl krew update
It's very similar to apt
or brew
or other package managers you may be familiar with.
Usage Example - Something Familiar¶
A while back, I demonstrated a REST API solution that would provide useful resource capacity information. In that blog post, I showed how you could use curl
to obtain the data on the command line.
So for this very quick intro to krew
, I'm going to solve the same problem, but with a kubectl
plugin that uses information already available through the standard Kubernetes API: kube-capacity
There are several ways to search for plugins, for example the command kubectl krew search resource
may yield the following results:
NAME DESCRIPTION INSTALLED
resource-capacity Provides an overview of resource requests, limi... no
resource-snapshot Prints a snapshot of nodes, pods and HPAs resou... no
resource-versions Print supported API resource versions no
To install resource-capacity
is as easy as running the following command:
kubectl krew install resource-capacity
The output from the command is just as helpful:
Updated the local copy of plugin index.
Installing plugin: resource-capacity
Installed plugin: resource-capacity
\
| Use this plugin:
| kubectl resource-capacity
| Documentation:
| https://github.com/robscott/kube-capacity
/
WARNING: You installed plugin "resource-capacity" from the krew-index plugin repository.
These plugins are not audited for security by the Krew maintainers.
Run them at your own risk.
And a quick run of the command kubectl resource-capacity
immediately yields some useful results:
NODE CPU REQUESTS CPU LIMITS MEMORY REQUESTS MEMORY LIMITS
* 1950m (32%) 3500m (58%) 1158Mi (4%) 2218Mi (9%)
node1 700m (35%) 1000m (50%) 396Mi (4%) 682Mi (8%)
node2 500m (25%) 1000m (50%) 256Mi (3%) 512Mi (6%)
node3 750m (37%) 1500m (75%) 506Mi (6%) 1024Mi (12%)
Compare that with the JSON output from the pykles
REST service as describe in the earlier blog post:
{
"Nodes": [
{
"NodeName": "node1",
"CPU": {
"Capacity": 2000,
"Allocatable": 2000,
"Requests": {
"InstrumentedValue": 500.0,
"Percent": 25.0
},
"Limits": {
"InstrumentedValue": 1000.0,
"Percent": 50.0
}
},
"RAM": {
"Capacity": 8344223744,
"Allocatable": 8344223744,
"Requests": {
"InstrumentedValue": 341835776.0,
"Percent": 4.096675574475104
},
"Limits": {
"InstrumentedValue": 715128832.0,
"Percent": 8.570345833717855
}
}
},
{
"NodeName": "node2",
"CPU": {
"Capacity": 2000,
"Allocatable": 2000,
"Requests": {
"InstrumentedValue": 500.0,
"Percent": 25.0
},
"Limits": {
"InstrumentedValue": 1000.0,
"Percent": 50.0
}
},
"RAM": {
"Capacity": 8344223744,
"Allocatable": 8344223744,
"Requests": {
"InstrumentedValue": 268435456.0,
"Percent": 3.2170213100172598
},
"Limits": {
"InstrumentedValue": 536870912.0,
"Percent": 6.4340426200345195
}
}
},
{
"NodeName": "node3",
"CPU": {
"Capacity": 2000,
"Allocatable": 2000,
"Requests": {
"InstrumentedValue": 750.0,
"Percent": 37.5
},
"Limits": {
"InstrumentedValue": 1500.0,
"Percent": 75.0
}
},
"RAM": {
"Capacity": 8344231936,
"Allocatable": 8344231936,
"Requests": {
"InstrumentedValue": 530579456.0,
"Percent": 6.358637440444224
},
"Limits": {
"InstrumentedValue": 1073741824.0,
"Percent": 12.868072606748788
}
}
}
]
}
It's the same output, but only one is really useful for human consumption!
Tags¶
kubernetes, cli