Skip to content

Commit

Permalink
Added
Browse files Browse the repository at this point in the history
  • Loading branch information
ajeetraina committed Jun 6, 2024
1 parent 6140366 commit 1431b1c
Show file tree
Hide file tree
Showing 12 changed files with 1,123 additions and 0 deletions.
211 changes: 211 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
# Kubetools Recommender System


<img width="117" alt="image" src="https://github.com/KrsGPTs/krs/assets/313480/582cf437-5dcf-4039-9c59-397db6e8b644">

![Twitter](https://img.shields.io/twitter/follow/kubetools?style=social)

A GenAI-powered Kubetools Recommender system for your Kubernetes cluster. It comes with the following capabilities:

- Ability to scan your existing Kubernetes cluster
- Available in the form of CLI tool as well as listed on the [Kubetools](https://kubetools.io) webpage
- Ability to recommend you with the best tool and categories based on your running workloads
- Support OpenAI and Hugging Face

<img width="300" alt="image" src="https://github.com/KrsGPTs/krs/assets/313480/ea071bb8-1282-4b06-8bb6-01f082e4cce0">


## Prerequisites:

1. A Kubernetes cluster up and running locally or in the Cloud.
2. Python 3.6+

Note: If the kube config path for your cluster is not the default *(~/.kube/config)*, ensure you are providing it during `krs init`

## Tested Environment

- Docker Desktop(Mac, Linux and Windows)
- Minikube


## Getting Started


## Clone the repository

```
git clone https://github.com/KrsGPTs/krs.git
```

### Install the Tool

Change directory to /krs and run the following command to install krs locally on your system:

```
pip install .
````
## Krs CLI
```

Usage: krs [OPTIONS] COMMAND [ARGS]...

╭─ Options ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ --install-completion Install completion for the current shell. │
│ --show-completion Show completion for the current shell, to copy it or customize the installation. │
│ --help Show this message and exit. │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Commands ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ exit Ends krs services safely and deletes all state files from system. Removes all cached data. │
│ export Exports pod info with logs and events. │
│ health Starts an interactive terminal to chat with user. │
│ init Initializes the services and loads the scanner. │
│ namespaces Lists all the namespaces. │
│ pods Lists all the pods with namespaces, or lists pods under a specified namespace. │
│ recommend Generates a table of recommended tools from our ranking database and their CNCF project status. │
│ scan Scans the cluster and extracts a list of tools that are currently used. │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
```
## Initialise and load the scanner
Run the following command to initialize the services and loads the scanner.
```
krs init
```
## Scan your cluster
Run the following command to scan the cluster and extract a list of tools that are currently used.
```
krs scan
```
```
krs scan

Scanning your cluster...

Cluster scanned successfully...

Extracted tools used in cluster...


The cluster is using the following tools:

+-------------+--------+-----------------------------+---------------+
| Tool Name | Rank | Category | CNCF Status |
+=============+========+=============================+===============+
| kubeview | 30 | Cluster with Core CLI tools | unlisted |
+-------------+--------+-----------------------------+---------------+
| | 3 | Cluster Management | unlisted |
+-------------+--------+-----------------------------+---------------+
```
## Lists all the namespaces
```
krs namespaces
Namespaces in your cluster are:

1. default
2. kube-node-lease
3. kube-public
4. kube-system
5. ns1
```
## List pods under a specified namespace
```
krs pods --namespace ns1

Pods in namespace 'ns1':

1. nginx-pod
```
## krs recommend
Generates a table of recommended tools from our ranking database and their CNCF project status.
```
krs recommend

Our recommended tools for this deployment are:

+-----------------------------+------------------+-------------+---------------+
| Category | Recommendation | Tool Name | CNCF Status |
+=============================+==================+=============+===============+
| Cluster with Core CLI tools | Recommended tool | k9s | unlisted |
+-----------------------------+------------------+-------------+---------------+
| Cluster Management | Recommended tool | rancher | unlisted |
+-----------------------------+------------------+-------------+---------------+
```
## Krs health
```
krs health

Starting interactive terminal...


Choose the model provider for healthcheck:

[1] OpenAI
[2] Huggingface

>>
```
Let's say you choose 1, the it will install necessary libraries.
```
Enter your OpenAI API key: sk-3im1ZgCbKXXXXXXXXegTpTyyOq2mR

Enter the OpenAI model name: gpt-3.5-turbo
API key and model are valid.

Namespaces in the cluster:

1. default
2. kube-node-lease
3. kube-public
4. kube-system
5. ns1

Which namespace do you want to check the health for? Select a namespace by entering its number: >> 5

Pods in the namespace ns1:

1. nginx-pod

Which pod from ns1 do you want to check the health for? Select a pod by entering its number: >>
Checking status of the pod...

Extracting logs and events from the pod...

Logs and events from the pod extracted successfully!


Interactive session started. Type 'end chat' to exit from the session!

>> The provided log entries are empty, as there is nothing between the curly braces {}. Therefore, everything looks good and there are no warnings or errors to report.
```
Empty file added krs/__init__.py
Empty file.
101 changes: 101 additions & 0 deletions krs/krs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#!/usr/bin/env python3

import typer, os
from krs.main import KrsMain
from krs.utils.constants import KRSSTATE_PICKLE_FILEPATH, KRS_DATA_DIRECTORY

app = typer.Typer()
krs = KrsMain()

def check_initialized():
if not os.path.exists(KRSSTATE_PICKLE_FILEPATH):
typer.echo("KRS is not initialized. Please run 'krs init' first.")
raise typer.Exit()

if not os.path.exists(KRS_DATA_DIRECTORY):
os.mkdir(KRS_DATA_DIRECTORY)

@app.command()
def init():
"""
Initializes the services and loads the scanner.
"""
krs.initialize()
typer.echo("Services initialized and scanner loaded.")

@app.command()
def scan():
"""
Scans the cluster and extracts a list of tools that are currently used.
"""
check_initialized()
krs.scan_cluster()


@app.command()
def namespaces():
"""
Lists all the namespaces.
"""
check_initialized()
namespaces = krs.list_namespaces()
typer.echo("Namespaces in your cluster are: \n")
for i, namespace in enumerate(namespaces):
typer.echo(str(i+1)+ ". "+ namespace)

@app.command()
def pods(namespace: str = typer.Option(None, help="Specify namespace to list pods from")):
"""
Lists all the pods with namespaces, or lists pods under a specified namespace.
"""
check_initialized()
if namespace:
pods = krs.list_pods(namespace)
if pods == 'wrong namespace name':
typer.echo(f"\nWrong namespace name entered, try again!\n")
raise typer.Abort()
typer.echo(f"\nPods in namespace '{namespace}': \n")
else:
pods = krs.list_pods_all()
typer.echo("\nAll pods in the cluster: \n")

for i, pod in enumerate(pods):
typer.echo(str(i+1)+ '. '+ pod)

@app.command()
def recommend():
"""
Generates a table of recommended tools from our ranking database and their CNCF project status.
"""
check_initialized()
krs.generate_recommendations()

@app.command()
def health(change_model: bool = typer.Option(False, help="Option to reinitialize/change the LLM, if set to True")):
"""
Starts an interactive terminal to chat with user.
"""
check_initialized()
typer.echo("\nStarting interactive terminal...\n")
krs.health_check(change_model)

@app.command()
def export():
"""
Exports pod info with logs and events.
"""
check_initialized()
krs.export_pod_info()
typer.echo("Pod info with logs and events exported. Json file saved to current directory!")

@app.command()
def exit():
"""
Ends krs services safely and deletes all state files from system. Removes all cached data.
"""
check_initialized()
krs.exit()
typer.echo("Krs services closed safely.")

if __name__ == "__main__":
app()
Loading

0 comments on commit 1431b1c

Please sign in to comment.