Cyphernetes
Cyphernetes turns this: 😣
# List all services exposing pods with the 'nginx' app label
kubectl get pods -l app=nginx -o json | \
jq -r '.items[].metadata.labels | to_entries[] | "\(.key)=\(.value)"' | \
xargs -I {} kubectl get services -l {} -o json | \
jq '.items[].metadata.name' | \
xargs kubectl get services
Into this: 🤩
MATCH (p:Pod {app: "nginx"})->(s:Service)
RETURN s
But how?
Cyphernetes is Cypher repurposed for working with the Kubernetes API. A mixture of ascii-art, SQL-esque keywords and jsonPaths, Cyphernetes lets us express Kubernetes CRUD operations in an efficeint, creative and fun way.
Examples
> MATCH (d:Deployment)
RETURN d.metadata.name AS name,
d.spec.replicas AS desiredReplicas,
d.status.availableReplicas AS runningReplicas;
{
"d": [
{
"desiredReplicas": 2,
"name": "coredns",
"runningReplicas": 2
}
]
}
Query executed in 9.081292ms
Cyphernetes' superpower is that it understands the relationships between Kubernetes resource kinds.
This feature lets us express highly complex operations in a natural way, and without having to worry about the underlying Kubernetes API:
# similar to `kubectl expose`
> MATCH (d:Deployment {name: "nginx"})
CREATE (d)->(s:Service);
Created services/nginx
Query executed in 30.692208ms
It has macros too
Macros are minimalistic, user-extensible & batteries included stored procedures.
> :expose_public nginx www.cyphernetes.com
Created services/nginx
Created ingresses/nginx
{
"ingresses": [
{
"Host": "www.cyphernetes.com",
"Path": "/",
"Service": "nginx"
}
],
"services": [
{
"ClusterIP": "10.96.136.90",
"Name": "nginx",
"Type": "ClusterIP"
}
]
}
Macro executed in 47.406833ms
For more usage examples, please see the Usage Guide.
But why?
Beyond the fact that writing Cypher is a delight, Cyphernetes aims to be efficient in expressing complex operations.
The more complicated an operation is, the shorter it's Cyphernetes representation would be compared to the equiavalent nested kubectl commands or API client code.
Macros take Cyphernetes from being a complimentary tool reserved for heavy tasks only to an every-day productivity tool that can replace common kubectl usage.
Get Cyphernetes
Build using go:
go install github.com/avitaltamir/cyphernetes/cmd/cyphernetes@latest
Alternatively, grab a binary from the Releases page.
Development
Cyphernetes is written in Go and utilizes a parser generated by goyacc to interpret the custom query language.
Prerequisites
- Go (1.16 or later)
- goyacc (for generating the parser)
- Make (for running make commands)
Getting Started
To get started with development:
Clone the repository:
git clone https://github.com/avitaltamir/cyphernetes.git
Navigate to the project directory:
cd cyphernetes
Building the Project
Use the Makefile commands to build the project:
make
make build
make test
- To generate the grammar parser:
make gen-parser
make clean
Contributing
Contributions are welcome! Please feel free to submit pull requests, open issues, and provide feedback.
License
Cyphernetes is open-sourced under the MIT license. See the LICENSE file for details.
Acknowledgments
- Thanks to the Neo4j community for the inspiration behind the query language.
Authors