kubesql, Experimental tool to query K8s API using plain SQL

Overview

kubesql

An experimental tool for querying your Kubernetes API Server using SQL

MIT GitHub release


kubesql, an experimental tool for querying your Kubernetes API Server using simple and smallest SQL syntax.

$ kubesql -q "SELECT namespace FROM context WHERE pod.status.phase = 'Running'"

Screenshot

Installation

Docker

$ docker pull furkanturkal/kubesql:0.1.0

From Source

$ cargo install --path . # local
# - or -
$ cargo install --git https://github.com/Dentrax/kubesql # remote

Usage

asciicast

USAGE:
    kubesql [OPTIONS]

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
    -f, --file <FILE>      
    -q, --query <query>

Evaluate

$ kubesql --file ./kube.sql
$ kubesql --query "SELECT namespace FROM context WHERE pod.status.phase = 'Running'"

With Docker

$ docker container run -v ~/.kube/config/:/home/nonroot/.kube/config kubesql:0.1.0 --query "SELECT namespace FROM context WHERE pod.status.phase = 'Running'"

Quick Start

SQL Syntax

Single Context

SELECT namespace
FROM context
WHERE pod.status.phase = 'Running'

Multiple Context-Namespace

SELECT namespace1, namespace2
FROM context1, context2
WHERE pod.status.phase = 'Running' AND deployment.metadata.name = 'my-awesome-deployment'

Supported Statements

STATEMENT REQUIRED
SELECT
FROM
WHERE

Supported Operators

OPERATOR WHERE ACTION
AND Panic if no result found
OR Continue

Special Thanks

Package Author License
sqlparser ballista-compute Apache License 2.0
kube clux Apache License 2.0
prettytable phsym MIT
  • Thanks to everyone who contributed these libraries and others that made this project possible.

License

kubesql was created by Furkan 'Dentrax' Türkal

The base project code is licensed under MIT unless otherwise specified. Please see the LICENSE file for more information.

FOSSA Status

Best Regards

You might also like...
A SQL query parser written using nom.

sqlparser-nom A SQL query parser written using nom. Query Select From Where Order by Limit CTE Group by Having Aggregate Window Pratt Parsing Friendly

qsv - Performant CLI tool to query CSVs through SQL

qsv Performant CLI tool to query CSVs through SQL Installation After cloning the repository, you can install a binary locally using cargo install --pa

Rust version of the Haskell ERD tool. Translates a plain text description of a relational database schema to dot files representing an entity relation diagram.

erd-rs Rust CLI tool for creating entity-relationship diagrams from plain text markup. Based on erd (uses the same input format and output rendering).

🧰 The Rust SQL Toolkit. An async, pure Rust SQL crate featuring compile-time checked queries without a DSL. Supports PostgreSQL, MySQL, SQLite, and MSSQL.

SQLx 🧰 The Rust SQL Toolkit Install | Usage | Docs Built with ❤️ by The LaunchBadge team SQLx is an async, pure Rust† SQL crate featuring compile-tim

Cost saving K8s controller to scale down and up of resources during non-business hours

Kube-Saver Motivation Scale down cluster nodes by scaling down Deployments, StatefulSet, CronJob, Hpa during non-business hours and save $$, but if yo

A K8s-optimized operating system, based on CoreOS

Kanopy Ultramarine Kanopy is a lightweight and easy to setup operating system optimized for Kubernetes. It is based on Ultramarine Linux, a Fedora rem

Rust based Kubernetes Operator to deploy K8s objects minimally.

kube-nimble nimble /ˈnɪmbl/ - quick and light in movement or action; agile. This project began from a place of curiosity about Kubernetes CRDs and the

Query LDAP and AD with SQL

SQLDAP Ever wanted to query AD or LDAP with SQL like queries ? I'm going to answer this question myself: yes ! Why ? Because I never could remember al

An object-relational in-memory cache, supports queries with an SQL-like query language.

qlcache An object-relational in-memory cache, supports queries with an SQL-like query language. Warning This is a rather low-level library, and only p

Fully typed SQL query builder for Rust [deprecated]

What is Deuterium? Deuterium is a fancy SQL builder for Rust. It's designed to provide a DSL to easily build SQL queries in safe and typed way. Like R

Type-safe SQL query wrappers

fnsql   The fnsql crate provides simple type-safe optional wrappers around SQL queries. Instead of calling type-less .query() and .execute(), you call

A Toy Query Engine & SQL interface
A Toy Query Engine & SQL interface

Naive Query Engine (Toy for Learning) 😄 This is a Query Engine which support SQL interface. And it is only a Toy for learn query engine only. You can

A query-building & utility crate for SurrealDB and its SQL querying language that aims to be simple

Surreal simple querybuilder A simple query-builder for the Surreal Query Language, for SurrealDB. Aims at being simple to use and not too verbose firs

Fgr - Find & Grep utility with SQL-like query language

fgr Find & Grep utility with SQL-like query language. Examples # Find all files with name equal to sample under the current directory: fgr -e name=sam

Query system statistics with SQL.

pg_stat_sysinfo Collects system statistics. ---- CREATE EXTENSION pg_stat_sysinfo; CREATE EXTENSION ---- SELECT * FROM pg_stat_sysinfo_collect();

ReefDB is a minimalistic, in-memory and on-disk database management system written in Rust, implementing basic SQL query capabilities and full-text search.
ReefDB is a minimalistic, in-memory and on-disk database management system written in Rust, implementing basic SQL query capabilities and full-text search.

ReefDB ReefDB is a minimalistic, in-memory and on-disk database management system written in Rust, implementing basic SQL query capabilities and full-

Searching for plain-text files for lines that match a given string. Built with Rust.

Getting Started This is a minimal grep command-line utility built on Rust. It provides searching for plain-text files for lines that match a given str

Plain Rust wrapper of Ableton Link's C 11 extension

rusty_link rusty_link is a Rust wrapper of abl_link, which is a C 11 extension for Ableton Link, provided by Ableton. This library attempts to be most

A plain-text Issue and PR tracking system

Markrequests A plain-text Issue and PR tracking system. An example of a file to track these is in prs/example.md Rationale I am unsatisfied with the c

Comments
  • Don't work if context isn't called

    Don't work if context isn't called "context"

    I've installed from cargo and tried query from readme

    # RUST_BACKTRACE=1 kubesql --query "SELECT namespace FROM context WHERE pod.status.phase = 'Running'"
    thread 'main' panicked at 'Given contexts ["context"] not found in your KUBECONFIG!', src/validator.rs:29:9
    stack backtrace:
       0: rust_begin_unwind
                 at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/std/src/panicking.rs:483
       1: std::panicking::begin_panic_fmt
                 at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/std/src/panicking.rs:437
       2: kubesql::validator::validate_contexts
       3: kubesql::main::{{closure}}
       4: std::thread::local::LocalKey<T>::with
       5: tokio::park::thread::CachedParkThread::block_on
       6: tokio::runtime::thread_pool::ThreadPool::block_on
       7: tokio::runtime::Runtime::block_on
       8: kubesql::main
    

    It seems application is trying to find context with name context, not using current-context that is set with kubectl config use-context

    ~/.kube/config

      11   │ contexts:
      12   │ - context:
      13   │     cluster: XXXXXXXXXXXXXXXXXXX
      14   │     user: XXXXXXXXXXXXXXXX
      15   │   name: org_name-kube-dev
      16   │ - context:
      17   │     cluster: YYYYYYYYYYYYYYYYYYYY
      18   │     user: YYYYYYYYYYYYYYYYY
      19   │   name: org_name-kube-prod
      20   │ current-context: org_name-kube-dev
    
    opened by Mart-Bogdan 5
  • Add Azure AKS support

    Add Azure AKS support

    This is an awesome project! Would love if azure support could be added. If I had lots of time could potentially help here.

    thread 'main' panicked at 'an error occurred during creating kube client: failed to create the kube client with context
    
    Caused by:
        0: Error loading kubeconfig: Failed exec auth: Authentication with provider azure not supported
        1: Failed exec auth: Authentication with provider azure not supported
    
    Stack backtrace:
       0: std::backtrace_rs::backtrace::libunwind::trace
                 at /rustc/07e0e2ec268c140e607e1ac7f49f145612d0f597/library/std/src/../../backtrace/src/backtrace/libunwind.rs:90:5
          std::backtrace_rs::backtrace::trace_unsynchronized
                 at /rustc/07e0e2ec268c140e607e1ac7f49f145612d0f597/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
          std::backtrace::Backtrace::create
                 at /rustc/07e0e2ec268c140e607e1ac7f49f145612d0f597/library/std/src/backtrace.rs:327:13
       1: std::backtrace::Backtrace::capture
                 at /rustc/07e0e2ec268c140e607e1ac7f49f145612d0f597/library/std/src/backtrace.rs:295:9
       2: kubesql::main::{{closure}}
       3: tokio::park::thread::CachedParkThread::block_on
       4: tokio::runtime::thread_pool::ThreadPool::block_on
       5: tokio::runtime::Runtime::block_on
       6: kubesql::main
       7: std::sys_common::backtrace::__rust_begin_short_backtrace
       8: std::rt::lang_start::{{closure}}
       9: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once
                 at /rustc/07e0e2ec268c140e607e1ac7f49f145612d0f597/library/core/src/ops/function.rs:259:13
          std::panicking::try::do_call
                 at /rustc/07e0e2ec268c140e607e1ac7f49f145612d0f597/library/std/src/panicking.rs:379:40
          std::panicking::try
    
    
    opened by velvia 6
Releases(v0.1.0)
  • v0.1.0(Apr 12, 2021)

    v0.1.0

    • Implement sqlparser
    • Implement kube-rs
    • Implement prettytable-rs
    • Validate if given namespace(s) and context(s) are really exist
    • Implement base CLI flags -f, --file and -q, --query
    $ k8sql --file kube.sql
    $ k8sql --query "SELECT namespace FROM context WHERE pod.status.phase = 'Running'"
    
    • This should work:
    SELECT namespace1, namespace2
    FROM context1, context2
    WHERE pod.status.phase = 'Running' AND deployment.metadata.name = 'my-awesome-deployment'
    
    • It should print:
    +----------------+---------------------------------+---------------------------------+
    | KIND / CONTEXT | context1                        | context2                        |
    +----------------+---------------------------------+---------------------------------+
    | pod            | +-------+-------+               | +-------+-------+               |
    |                | | ns1   | ns2   |               | | ns1   | ns2   |               |
    |                | +-------+-------+               | +-------+-------+               |
    |                | | pod-1 | pod-1 |               | | pod-2 | pod-2 |               |
    |                | +-------+-------+               | +-------+-------+               |
    +----------------+---------------------------------+---------------------------------+
    | deployment     | +--------------+--------------+ | +--------------+--------------+ |
    |                | | ns1          | ns2          | | | ns1          | ns2          | |
    |                | +--------------+--------------+ | +--------------+--------------+ |
    |                | | deployment-1 | deployment-1 | | | deployment-2 | deployment-2 | |
    |                | +--------------+--------------+ | +--------------+--------------+ |
    +----------------+---------------------------------+---------------------------------+
    
    • Print conditions:
    1. Printer should not insert pod row if does not given in WHERE statement
    2. Printer should not insert deployment row if does not given in WHERE statement
    Source code(tar.gz)
    Source code(zip)
Owner
Furkan Türkal
Trying to learn something new every day and still finding new mistakes to make... (SDÜ - Computer Science)
Furkan Türkal
A Rust SQL query builder with a pleasant fluent API closely imitating actual SQL

Scooby An SQL query builder with a pleasant fluent API closely imitating actual SQL. Meant to comfortably build dynamic queries with a little bit of s

Aleksei Voronov 100 Nov 11, 2022
Gh-sql - Query GitHub Projects (beta) with SQL

gh-sql: Query GitHub Projects (beta) with SQL Installation gh extension install KOBA789/gh-sql Features SELECT items DELETE items UPDATE item fields

Hidekazu Kobayashi 108 Dec 7, 2022
rust_arango enables you to connect with ArangoDB server, access to database, execute AQL query, manage ArangoDB in an easy and intuitive way, both async and plain synchronous code with any HTTP ecosystem you love.

rust_arango enables you to connect with ArangoDB server, access to database, execute AQL query, manage ArangoDB in an easy and intuitive way, both async and plain synchronous code with any HTTP ecosystem you love.

Foretag 3 Mar 24, 2022
Kubernetes leader election using the coordination.k8s.io API.

Kube Coordinate Kubernetes leader election using the coordination.k8s.io API. Kube Coordinate builds upon the kube-rs ecosystem, and implements a stre

Anthony Dodd 4 Dec 14, 2023
A tool that allow you to run SQL-like query on local files instead of database files using the GitQL SDK.

FileQL - File Query Language FileQL is a tool that allow you to run SQL-like query on local files instead of database files using the GitQL SDK. Sampl

Amr Hesham 39 Mar 12, 2024
ClangQL is a tool that allow you to run SQL-like query on C/C++ Code instead of database files using the GitQL SDK

ClangQL - Clang AST Query Language ClangQL is a tool that allow you to run SQL-like query on C/C++ Code instead of database files using the GitQL SDK.

Amr Hesham 490 Oct 23, 2024
mdzk is a plain text Zettelkasten system that is based on the mdBook API.

mdzk A lovingly designed system and static publishing tool for your plain text Zettelkasten mdzk is a plain text Zettelkasten system that is based on

mdzk 176 Jan 4, 2023
SQL validator tool for BigQuery standard SQL.

bqvalid What bqvalid does bqvalid is the SQL validator tool for BigQuery standard SQL. bqvalid fails with error message if there's the expression that

null 10 Dec 25, 2022
Sleek is a CLI tool for formatting SQL. It helps you maintain a consistent style across your SQL code, enhancing readability and productivity.

Sleek: SQL Formatter ✨ Sleek is a CLI tool for formatting SQL. It helps you maintain a consistent style across your SQL code, enhancing readability an

Nick Rempel 40 Apr 20, 2023
Rust library to parse, deparse and normalize SQL queries using the PostgreSQL query parser

This Rust library uses the actual PostgreSQL server source to parse SQL queries and return the internal PostgreSQL parse tree.

pganalyze 37 Dec 18, 2022