Concurrent Kubectl

The primary objective of my team is to empower other engineering teams in our company to take ownership of their services. Like many companies we chose Kubernetes as the platform to help us achieve our goals.

For our architecture it was clear that the benefits of Kubernetes far outweigh the complexity overhead—an easy justification for a team of devops pros.

I mean seriously, it does so many things. But there are some pain points. With the understanding that there are numerous approaches to using Kubernetes and that your workflow is not the same as my workflow I would like to introduce a small CLI tool which has helped alleviate some of the pain points encountered when using Kubernetes everyday.

ckube is a small utility to simplify and streamline working with Kubernetes from the cli. kubectl is extremely powerful but I find that I generally use a very small subset of its features, namely logs and exec. Let's use my-app as an example.

my-app is a very cool web application (not really, it is actually just nginx).

Getting logs for my-app is easy enough with kubectl

$ kubectl logs my-app-775df4f94b-l2kqc

The problem is that I don't think of my-app as a pod but rather a service. Even more concerning, my-app is super popular so I have scaled up my deployment to 5 replicas. In reality when I want to see the logs for my-app I want to see the logs for all 5 of these pods.

$ kubectl get pods
NAME                          READY     STATUS    RESTARTS   AGE  
my-app-775df4f94b-52ls4       1/1       Running   0          4h  
my-app-775df4f94b-l2kqc       1/1       Running   0          4h  
my-app-775df4f94b-srzwv       1/1       Running   0          4h  
my-app-775df4f94b-tq9kl       1/1       Running   0          4h  
my-app-775df4f94b-x866k       1/1       Running   0          4h  

ckube was created to run common kubectl commands concurrently against multiple pods. Using ckube should feel familiar if you have used kubectl. Here is ckube in action. ckube logs also accepts the -f flag to follow the logs in all of the containers.

Similar functionality exists for exec. If I need an interactive prompt to poke around in a single pod ckube will choose one for me.

Non interactive commands can easily be run against all my-app pods with -a.
ckube also supports more complex commands just like kubectl.

Check out ckube on github

Devon Moss

Read more posts by this author.