Become a Kubernetes Jedi with Alfred Workflows

Eldar Damari
FairFly
Published in
4 min readMar 1, 2018

It’s all about productivity.

“A barista pouring coffee to four cups at once” by Nathan Dumlao on Unsplash

In the past few years here at FairFly, we’ve been working with Kubernetes, a great container orchestration tool that is helping us manage all of our services and deployments.

Kubernetes is an open-source system for automating deployment, scaling and management of containerized applications that was originally designed by Google (source: Wikipedia)

In this post I would like to introduce how we’ve managed to gain mastery and more efficiently manage all of our kubernetes assets by using a great tool called Alfred workflows which we extensively use and care about here at FairFly. This, and our passion for productivity and efficiency, has lead our R&D team to a faster and more productive era.

From this point and on I will assume you are familiar with the technology and you have some intermediate experience.

In the dark ages… there was only kubectl

Kubernetes gives you a nice CLI tool named:kubectl

Kubectl — A command line interface for running commands against Kubernetes clusters (from kubernetes.io kubectl overview page)

We found ourselves performing various daily tasks using kubectl, in such a non-productive way; that includes viewing logs, ‘exec’ing into pods, watching deployment initialization process, deleting assets or just visiting our Kubernetes Dashboard.

Moreover, kubectl has auto-completion but its super slow, the search is not good enough and it doesn’t provide enough information on the context such as how many pods are active for the deployment? what’s its status? etc.

For example, in order to fetch logs, the kubectl command logs requires <pod-name>as an argument. Now we have to find the pod name we want either by typing $ kubectl get pods or by using the auto-completion.

This process is super slow so I had to find a way to make this process more efficient (did I mention we are productivity freaks?), so I started using labels which helped me find a subset of resources a bit faster, but even that wasn’t fast enough. Even bash history navigation (CTRL+R) didn’t satisfy my efficiency needs.

And then it hit me!

Introducing Alfred Workflow.

For those who are not familiar with Alfred, you guys are missing out.
Alfred (alternatives you can check: Wox, Hain) is a Mac OS task runner that that greatly extends what Spotlight can do, let’s you be more productive with custom actions, for example, open apps, run scripts and use most of your OS features as you desire; being faster than ever! And most importantly, lets you design completely custom workflows.

Simple To-Do List workflow example - www.alfredapp.com

Kubernetes Alfred Workflow

I decided to build a custom workflow to make the magic happen
(download here) by building a set of commands that wrap kubectl and provide the completion and search capabilities that we so badly missed. These commands include our most common day-to-day operations such as tailing logs, ‘exec’ing into containers etc.

Step 1 — Quick Setup ⚙️

ksetenv — will open a menu to
- Your dashboard URL (must!)
- Your kubectl local path
(default:/usr/local/bin/kubectl)

  • Install kubetail (must!) — Bash script to tail Kubernetes logs from multiple pods at the same time. ($ brew install kubetail)

Step 2 — Use the Force 🚀

A list of the available commands.
kl (logs)

kl — Get resources logs.
ks — Access any pod shell.
kw — Watch & describe resources.
kr — Remove assets quickly. Don’t worry, hitting ⏎ won’t remove anything, you will have to hold SHIFT + ⏎ to execute.
kre — Remove evicted pods.
kd — Go to dashboard.
kds — Explore your assets in dashboard.

Bonus: DataDog Monitor Pods (kdm command)

We monitor our assets with DataDog, fetching metrics like memory/CPU takes some time, you need to navigate to DataDog→Metrics→Explorer, in Graph section choose all the metrics you’d like to view and then from Over pick your resources…. it’s frustrating.
For this specific use, I have created the kdm Alfred command, where you choose your resource from the list and get an instant summary in DataDog.

kdm

Explorer your assets metrics in DataDog.

Conclusion

As you’ve probably seen, we at Fairfly are kind of productivity freaks! We use Alfred custom workflows for pretty much everything and constantly seek to improve and make our teamwork and infrastructure better and faster. I hope you will find the time to use this workflow, we created this toolbox for you — It’s FREE.
Please feel free to contact for any feedback, workflows suggestions and more at eldar@fairfly.com.

--

--

Eldar Damari
FairFly
Editor for

Pythonist, Kotlinist & Triathlonist! Scalable Systems Jedi & DL passionate. I pursue efficiency. Currently Co-Founder & CTO@Entor