kubectl
You can customize the plug-in, allowing you to use any language, as long as you generate an executable file and kubectl-
start with it,
we can customize a simple j using the shellhello kubectl
vim kubectl-hello
Enter, save and exit
#! /bin/sh
echo hello kubectl
chomd a+x kubectl-hello
mv ./kubectl-hello /usr/local/bin
Then execute it and you can see the output, a simple plugin is made
~# kubectl hello
hello kubectl
Then we can use the following command to list all the plugins
~# kubectl plugin list
The following compatible plugins are available:
/usr/local/bin/kubectl-hello
Next, let's be a little more complicated
vim kubectl-whoami
Enter the following
#!/bin/bash
# this plugin makes use of the `kubectl config` command in order to output
# information about the current user, based on the currently selected context
kubectl config view --template='{
{ range .contexts }}{
{ if eq .name "'$(kubectl config current-context)'" }}Current user: {
{ printf "%s\n" .context.user }}{
{ end }}{
{ end }}'
Then execute authorization and copy to the /usr/local/bin directory
chmod a+x kubectl-whoami
mv ./kubectl-whoami /usr/local/bin
Then execute
~# kubectl whoami
Current user: kubernetes-admin
The plug-in can repackage a batch of command sets, and do a complex operation without having to type one command after another. Isn’t it thoughtful?