I recently discovered nushell. It is similar to shells like bash and zsh, but every command works on structured data. Here are some examples of using nushell with kubectl
to explore your kubernetes cluster more ergonomically.
kubectl get pods
“Normal” kubectl get pods
looks like this.
You can use nushell to parse this data into a tabular format. The trick is to have kubectl respond with json, then use nushell to parse the json.
From there, you can build more complex queries.
One challenge is that when kubectl returns JSON, there is a lot of data. You can use the nushell columns
command to understand all of the available columns.
Now that we can access this metadata, we can do all sorts of interesting queries on our data.
Sorting
Sort by the created date.
Yes, it is true that you could do all of this with kubectl, but I can never remember the correct way to use jsonpath and/or jq. I find the nushell syntax a lot easier to work with.
Filtering
Get all of the pods created in June.
This is pretty verbose. But, I like that I can read the command and pretty easily parse out what is happening. I am also very new to nushell, so there is probably a more efficient way to do this.
Wrap up
Hopefully this post gives you an idea of how nushell can help you interact with your Kubernetes cluster. As I come across more handy snippets I will update this blog post with them.