Extending scope of kubectl with plugins

Before diving into the topic, lets have look at few terminologies.

Kubernetes and kubectl

Kubernetes, also known as k8s, is opensource container-orchestration tool which is generally used manage the containers, application deployments, services. If you run your workload on containers then kubernetes is best option to choose. Best thing about kubernetes is its opensource. You can deploy it on your on-premise servers or cloud managed server, you don't have to pay for anything for software. Once you cluster is up and running, kubectl, is tool with whom you spend your most of the time. Its a command line tool which used to manage kubernetes cluster in terms of deploying application, services, inspecting containers, checking logs etc. kubectl comes with lots of sub-command. Each sub-command has its own use. In this blog, we are going to create our own sub-command, which is known as plugin.

kubectl Plugins

Kubectl plugins are standalone scripts. Scripts can be written in any programming language. These executable scripts are stored in your PATH and whose names start with kubectl-. PATH is where all you commands are present. You can see PATH by following command :

# echo $PATH

Just place your executable script anywhere in your PATH and you are good to go.

How to write Plugin

Create file starting with kubectl-. For example, kubectl-greetings which will create kubectl greetings command. To install plugin, you must save this file anywhere in you PATH. Following is example of plugin that will greet user

Save this in kubectl-greetings and run following command to make it executable. After that move this file anywhere in you PATH with mv command.

# chmod +x kubectl-greetings

Now you are all set to run kubectl greetings command which will output Hello with username. Output of command from above script shown below

You can check all installed plugins by running following command:

# kubectl plugin list


It is not possible to create plugins which will overwrite existing kubectl command. For example, if you create kubectl-create script and try to run it, kubectl create command will always take precedence over it and your script will be ignored.




Astrophile | Technophile | Opensource enthusiast

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Why I Started to Learn Software Engineering

Reduce Cost and Increase Productivity with Value Added IT Services from buzinessware — {link} -

Visual AI Improves Test Automation

Build your own Google

How to get started with C++ on Mac / Windows

Awesome GUI’s built with Streamlit

How hybrid integration platforms can help to enable Data Mesh

15 Python tips and tricks, so you don’t have to look them up on Stack Overflow

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Rahul Waykos

Rahul Waykos

Astrophile | Technophile | Opensource enthusiast

More from Medium

Zero Downtime Deployment of BusinessWorks Container Edition with Kubernetes — Part 5

Practical tracing: a final recap

Theoretical of Docker

Building containers without Docker