Chapter 2. Client Side

Now that you have a basic understanding of why Kubernetes’ extensibility is so helpful in providing a solid user experience (UX) for Ops, in this chapter we explore the Kubernetes API and the provided software development kits (SDKs)—in particular the Golang SDK. We also look at how to write a kubectl plug-in.

kubectl Plug-Ins

The first way to extend Kubernetes is via kubectl plug-ins. Plug-ins are a kubectl feature marked as stable in Kubernetes 1.14; you can verify your version by using kubectl version to run the appropriate binary. These are binaries in your $PATH that have the prefix kubectl-. I think Ops people deserve love and appreciation; here’s a plug-in that everyone should deliver to their laptop:


# argument handling
if [[ "$1" == "version" ]]
    echo "stable-as-you"
    exit 0

echo "Remember. You are awesome!"

As you can see, this is nothing more than a Bash script. Let’s call it kubectl-awesome and make it executable:

$ chmod +x ./kubectl-awesome
$ mv ./kubectl-awesome /usr/local/bin
$ kubectl awesome
Remember. You are awesome!
$ kubectl awesome version

You cannot override kubectl commands using this trick. A binary called kubectl-create-awesomeness won’t work because you cannot override the kubectl create command. Usually the common path here is to prefix your command with the subject of the plug-in. I am increasing the coefficient of awesomeness! My plug-in is called kubectl-awesomeness-create and it simply increments ...

Get Extending Kubernetes now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.