Skip to content

Proposal: SQL like query language

Murali Reddy edited this page Jul 8, 2017 · 8 revisions

Kubectl has very powerful constructs to query resources. You could use jsonpath to form rich queries as detailed in this blog. For e.g you can sort pods in all namespaces by creation timestamp and retrieve just name, timestamp with below query.

kubectl get pods --all-namespaces --sort-by='.metadata.creationTimestamp' -o jsonpath='{range .items[*]}{.metadata.name}, {.metadata.creationTimestamp}{"\n"}{end}'

You could also use -o=custom-columns option to retireve selected details in print in tabular form.

± kubectl get pods  -o=custom-columns=NAME:.metadata.name,NAMESPACE:.metadata.namespace
NAME                            NAMESPACE
frontend-3823415956-9dkvv       default
frontend-3823415956-jzjkx       default
frontend-3823415956-mk4mg       default
frontend-3823415956-qznrw       default
frontend-3823415956-r3j5j       default
redis-master-1068406935-vt23d   default
redis-slave-2005841000-ckrhv    default
redis-slave-2005841000-nkx98    default

For kubectl powerusers, this constructs are very handy. But finding the appropriate jsonpath for each propertly can get inconvenient and error prone.

Kube-shell as wrapper around kubectl can ease some of these inconveniences. This proposal below query construct in kube-shell. Auto-suggestion can hide the complexity of handling jsonpath for properties and automatically form kubctl query commands.

ls <resource-name> select (property1, property2, property3) where (propery1=value1 and property2=value2) order by property3

Here is quick showcase of the proposal from the prototype implementation. Kubernetes swagger.json is used parse the properties for each resource and form the corresponding jsonpath.

A complete ls statement is transformed into kubectl command with -o=custom-columns options.

A little variation to SQL select statement is done so that we know first the resource on which we are acting, so that auto-suggestions can be made.

Please leave your feedback or thoughts in the enhancement

Clone this wiki locally