mercredi 21 juillet 2021

Kubectl plugins the easy way

You know kubectl is today the Cloud console tool, the new SSH and bash and much more.

I use it every day and as always I only rely on my bash history and CTRL+R to find the last correct use.

For a long time, I read Ahmet Alp Balkan tweets about kubectl plugin but it sounds difficult.

Kubernetes the hard way, right?😁

(if you don't already follow Ahmet on Twitter)

So I was happy with my kubectl history until I assist to Paris Containers Day, especially 

GaĂ«lle Acas & AurĂ©lie Vache's presentation check their video Kubectl plugin in a minute ! (in french)

Incroyable, it's super easy to create your kubectl plugin and they demonstrate in 4 steps :

  1. Create a file named kubectl-myfantasticplugin
  2. Make it executable, chmod +x kubectl-myfantasticplugin
  3. Move it into your PATH, mv kubectl-myfantasticplugin /usr/local/bin
  4. Run "kubectl myfantasticplugin"
You can create your plugin with any language and especially Go, Python, Rust, Quarkus or Bash.

Test yourself :
  1. copy kubectl-halloween bash script from their Github, 
  2. chmod +x kubectl-halloween 
  3. sudo mv kubectl-halloween /usr/local/bin/kubectl-halloween
  4.  kubectl halloween pod
  5. Get your emoji

NAME                                READY   STATUS    RESTARTS   AGE
🎃 my-nginx-5d59d67564-5q4mk           1/1     Running   0          4h52m
🎃 my-nginx-5d59d67564-5shv7           1/1     Running   0          4h52m
🎃 my-nginx-5d59d67564-nwrwk           1/1     Running   0          4h52m
🎃 nginx-deployment-66b6c48dd5-m9rdt   1/1     Running   0          11d
🎃 nginx-deployment-66b6c48dd5-vzw48   1/1     Running   0          11d

It's Awesome.
The best is to come. Now you know how to create kubectl plugins. 
You can create your own, use existing ones and share yours using Krew.

You can also create your own Krew index to share your kubectl plugin in your team, project or company.

And what to do with kubectl plugins ?
Everything ! View secrets, view certificate, resources utilizations, logs, and more.
Plugins are a great way to increase your agility and productivity.

Remember your old bash script, now it's a kubectl plugin and you can share it.

Find Gaelle and Aurelie slide deck, they explain everything better. 
Thank you for the inspiration.

Official documentation

And check Ahmet famous plugin