-
Notifications
You must be signed in to change notification settings - Fork 175
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.
ls <resource-name> select (property1, property2, property3) where (propery1=value1 and property2=value2) sort property3