I’ll pick Python as my language choice. It's simple & has a robust set of libraries to play with.

There’s no installation or pre-loading of the plugin that is required. Plugin executables receive the inherited environment from the kubectl binary.

A plugin determines which command path it wishes to implement based on its name. For example, a plugin wanting to provide a new command kubectl foo , would simply be named kubectl-foo , and live somewhere in your PATH .

An example (Bash implementation), as listed on the Kubernetes website is shown below.

### FILE (savvy)$ sudo cat <<EOF>> /usr/local/bin/kubectl-foo

#!/bin/bash



if [[ "$1" == "version" ]]

then

echo "1.0.0"

exit 0

fi



echo "I am a plugin named kubectl-foo"

EOF ### TEST (savvy)$ chmod +x /usr/local/bin/kubectl-foo (savvy)$ kubectl foo

I am a plugin named kubectl-foo (savvy)$ kubectl foo version

1.0.0

Easy right? Time to start coding…

We’ll call the plugin Tesla (You can call it whatever you want). Following the plugin naming convention, we’ll name the plugin file kubectl-tesla . I’m also going to use the requests library to make REST calls & click , a Python package to build CLI interfaces. It’s very similar to argparse , but takes away some of the complexity.

Following the same approach as above,

(savvy)$ pip install click requests (savvy)$ sudo cat <<EOF>> /usr/local/bin/kubectl-mycar #!/usr/bin/env python import os, requests, click

headers={"Authorization": "Bearer {0}".format(os.getenv("MYCARTOKEN"))} url="{0} /api/1/vehicles/{1}/command /".format(os.getenv("MYCARURL"), os.getenv("MYCARID"))headers={"Authorization": "Bearer {0}".format(os.getenv("MYCARTOKEN"))}

.option("--honk", help="Honks the horn twice.", is_flag=True) @click .command() @click .option("--honk", help="Honks the horn twice.", is_flag=True) def execute(**kwargs):

""" KUBECTL PLUGIN TO INTERACT WITH TESLA """ for key, value in kwargs.items():

if value == None:

continue

if key == "honk":

honk(value) def honk(flag):

""" FUNCTION TO POST HONK REQUEST TO TESLA API SERVER """ if flag:

response = requests.post(url + "/honk_horn",headers=headers)

if response.status_code == 200:

click.echo("Honking twice...") if __name__ == "__main__":

execute()

EOF

Let’s export the secrets (carID & clientToken) & make the script an executable. Then we can run, kubectl tesla --help to display the help screen.

(savvy)$ export MYCARURL=

(savvy)$ export MYCARID=<YOUR-CAR-ID>

(savvy)$ export MYCARTOKEN=<API-TOKEN> export MYCARURL= https://owner-api.teslamotors.com export MYCARID=export MYCARTOKEN= (savvy)$ chmod +x /usr/local/bin/kubectl-tesla (savvy)$ kubectl tesla --help

Usage: kubectl tesla [OPTIONS] KUBECTL PLUGIN TO INTERACT WITH TESLA Options:

--honk Honks the horn twice.

--help Show this message and exit.

And finally, let’s honk…