Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yaacov/kubectl-sql
kubectl-sql is a kubectl plugin that use SQL like language to query the Kubernetes cluster manager
https://github.com/yaacov/kubectl-sql
hacktoberfest k8s-client k8s-filtering k8s-search kubectl kubectl-plugin kubectl-sql kubernetes plugin query resources search sql
Last synced: about 2 months ago
JSON representation
kubectl-sql is a kubectl plugin that use SQL like language to query the Kubernetes cluster manager
- Host: GitHub
- URL: https://github.com/yaacov/kubectl-sql
- Owner: yaacov
- License: apache-2.0
- Created: 2020-02-17T12:39:54.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2023-10-31T11:52:42.000Z (about 1 year ago)
- Last Synced: 2024-10-14T08:14:32.867Z (2 months ago)
- Topics: hacktoberfest, k8s-client, k8s-filtering, k8s-search, kubectl, kubectl-plugin, kubectl-sql, kubernetes, plugin, query, resources, search, sql
- Language: Go
- Homepage:
- Size: 296 KB
- Stars: 56
- Watchers: 4
- Forks: 3
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
[![Go Report Card](https://goreportcard.com/badge/github.com/yaacov/kubectl-sql)](https://goreportcard.com/report/github.com/yaacov/kubectl-sql)
[![Build Status](https://travis-ci.org/yaacov/kubectl-sql.svg?branch=master)](https://travis-ci.org/yaacov/kubectl-sql)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
# kubectl-sql
kubectl-sql is a [kubectl plugin](https://kubernetes.io/docs/tasks/extend-kubectl/kubectl-plugins/) that use SQL like language to query the [Kubernetes](https://kubernetes.io/) cluster manager
- [Install](#install)
- [What can I do with it ?](#what-can-i-do-with-it-)
- [Alternatives](#alternatives)## More docs
- [kubectl-sql's query language](https://github.com/yaacov/kubectl-sql/blob/master/README_language.md)
- [More kubectl-sql examples](https://github.com/yaacov/kubectl-sql/blob/master/README_examples.md)
- [Using the config file](https://github.com/yaacov/kubectl-sql/blob/master/README_config.md)## Install
Using [krew](https://sigs.k8s.io/krew) plugin manager to install:
```
kubectl krew install sql
kubectl sql --help
```Using Fedora Copr:
```
dnf copr enable yaacov/kubesql
dnf install kubectl-sql
```
From source:``` bash
git clone [email protected]:yaacov/kubectl-sql.git
cd kubectl-sqlmake
```## What can I do with it ?
kubectl-sql let you select Kubernetes resources based on the value of one or more resource fields, using
human readable easy to use SQL like query language. It is also posible to find connected resources useing the
`join` command.[More kubectl-sql examples](https://github.com/yaacov/kubectl-sql/blob/master/README_examples.md)
``` bash
# Get all pods from current namespace scope, that has a name starting with "virt-" and
# IP that ends with ".84"
kubectl-sql get pods where "name ~= '^virt-' and status.podIP ~= '[.]84$'"
AMESPACE NAME PHASE hostIP CREATION_TIME(RFC3339)
default virt-launcher-test-bdw2p-lcrwx Running 192.168.126.56 2020-02-12T14:14:01+02:00
...
`````` bash
# Get all persistant volume clames that are less then 20Gi, and output as json.
kubectl-sql -o json get pvc where "spec.resources.requests.storage < 20Gi"
...
```
``` bash
# Display non running pods by nodes for all namespaces.
kubectl-sql join nodes,pods on \
"nodes.status.addresses.1.address = pods.status.hostIP and not pods.phase ~= 'Running'" -A
...
`````` bash
# Filter replica sets with less ready-replicas then replicas"
kubectl-sql --all-namespaces get rs where "status.readyReplicas < status.replicas"
```#### Output formats:
| --output flag | Print format |
|----|---|
| table | Table |
| name | Names only |
| yaml | YAML |
| json | JSON |## Alternatives
#### jq
`jq` is a lightweight and flexible command-line JSON processor. It is possible to
pipe the kubectl command output into the `jq` command to create complicated searches ( [Illustrated jq toturial](https://github.com/MoserMichael/jq-illustrated) )https://stedolan.github.io/jq/manual/#select(boolean_expression)
#### kubectl --field-selector
Field selectors let you select Kubernetes resources based on the value of one or more resource fields. Here are some examples of field selector queries.
https://kubernetes.io/docs/concepts/overview/working-with-objects/field-selectors/