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

Writing a regex to detect a range of numbers? Why not just parse the string to integers instead

Why Fluentd stopped to send logs to ElasticSearch on Kubernetes (Related To SSL)

On The Business of Chrome Extensions and Sensitive Information

Undestanding Apache Spark Architecture

A Swift extension for String and HTML

Recent Parallel Processing Computer System Technology

Cluster Federation and Global Load Balancing on Kubernetes and Google Cloud — Part 1

Add navigation to your on-demand delivery app

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

Is Kubernetes That Important?

Kubernetes CRD Versioning for Operators Developers

COVID and Technology — What is so common?

Circle CI while waiting for ADO