A Kubernetes copilot agent powered by OpenAI
Project description
Autonomous Agent for Kubernetes
Autonomous Agent for Kubernetes powered by OpenAI.
Features:
- Autonomous Kubernetes cluster operations using LLM Agents powered by ChatGPT (GPT-3.5, GPT-4 and future versions).
- Diagnose and analyze the potential issues for Kubernetes workloads.
- Generate the Kubernetes manifests based on the provided prompt instructions.
- Utilize native kubectl and trivy commands for Kubernetes cluster access and security vulnerability scanning.
Install
Install locally
Install the kube-agent with the commands below. It is highly recommended to use pipx or venv to install the copilot to avoid conflicts with other Python packages.
# Option 1: use pipx to install the copilot
pipx install kube-agent
# Option 2: use venv to install the copilot
python3 -m venv agentenv
source agentenv/bin/activate
pip install kube-agent
# Option 3: Use pip to install the copilot (not recommended)
pip install kube-agent
Setup:
- Ensure
kubectlis installed on the local machine and the kubeconfig file is configured for Kubernetes cluster access. - Install
trivyto assess container image security issues (for theauditcommand). - Set the OpenAI API key as the
OPENAI_API_KEYenvironment variable to enable ChatGPT functionality.- For Azure OpenAI service, please set
AZURE_OPENAI_API_KEY=<key>andAZURE_OPENAI_ENDPOINT=https://<replace-this>.openai.azure.com/.
- For Azure OpenAI service, please set
Run in Kubernetes
kubectl run -it --rm copilot \
--env="OPENAI_API_KEY=$OPENAI_API_KEY" \
--restart=Never \
--image=ghcr.io/feiskyer/kube-agent \
-- execute --verbose 'What Pods are using max memory in the cluster'
kubectl run -it --rm copilot \
--env="AZURE_OPENAI_API_KEY=$AZURE_OPENAI_API_KEY" \
--env="AZURE_OPENAI_ENDPOINT=$AZURE_OPENAI_ENDPOINT" \
--restart=Never \
--image=ghcr.io/feiskyer/kube-agent \
-- execute --verbose 'What Pods are using max memory in the cluster'
Refer kubernetes.md for more detailed steps.
How to use
Running directly in the terminal:
Usage: kube-agent [OPTIONS] COMMAND [ARGS]...
Kubernetes Copilot powered by OpenAI
Options:
--version Show the version and exit.
--help Show this message and exit.
Commands:
analyze analyze issues for a given resource
audit audit security issues for a Pod
diagnose diagnose problems for a Pod
execute execute operations based on prompt instructions
generate generate Kubernetes manifests
Audit Security Issues for Pod
kube-agent audit POD [NAMESPACE] will audit security issues for a Pod:
Usage: kube-agent audit [OPTIONS] POD [NAMESPACE]
audit security issues for a Pod
Options:
--verbose Enable verbose information of copilot execution steps
--model MODEL OpenAI model to use for copilot execution, default is gpt-4
--help Show this message and exit.
Diagnose Problems for Pod
kube-agent diagnose POD [NAMESPACE] will diagnose problems for a Pod:
Usage: kube-agent diagnose [OPTIONS] POD [NAMESPACE]
diagnose problems for a Pod
Options:
--verbose Enable verbose information of copilot execution steps
--model MODEL OpenAI model to use for copilot execution, default is gpt-4
--help Show this message and exit.
Analyze Potential Issues for k8s Object
kube-agent analyze RESOURCE NAME [NAMESPACE] will analyze potential issues for the given resource object:
Usage: kube-agent analyze [OPTIONS] RESOURCE NAME [NAMESPACE]
analyze issues for a given resource
Options:
--verbose Enable verbose information of copilot execution steps
--model TEXT OpenAI model to use for copilot execution, default is gpt-4
--help Show this message and exit.
Execute Operations Based on Prompt Instructions
kube-agent execute INSTRUCTIONS will execute operations based on prompt instructions.
It could also be used to ask any questions.
Usage: kube-agent execute [OPTIONS] INSTRUCTIONS
execute operations based on prompt instructions
Options:
--verbose Enable verbose information of copilot execution steps
--model MODEL OpenAI model to use for copilot execution, default is gpt-4
--help Show this message and exit.
Generate Kubernetes Manifests
Use the kube-agent generate command to create Kubernetes manifests based on
the provided prompt instructions. After generating the manifests, you will be
prompted to confirm whether you want to apply them.
Usage: kube-agent generate [OPTIONS] INSTRUCTIONS
generate Kubernetes manifests
Options:
--verbose Enable verbose information of copilot execution steps
--model TEXT OpenAI model to use for copilot execution, default is gpt-4
--help Show this message and exit.
Contribution
The project is opensource at github feiskyer/kube-agent with Apache License.
If you would like to contribute to the project, please follow these guidelines:
- Fork the repository and clone it to your local machine.
- Create a new branch for your changes.
- Make your changes and commit them with a descriptive commit message.
- Push your changes to your forked repository.
- Open a pull request to the main repository.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kube_agent-0.2.0.tar.gz.
File metadata
- Download URL: kube_agent-0.2.0.tar.gz
- Upload date:
- Size: 29.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.12.3 Linux/6.8.0-47-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1342185c9e4e27e35ecff07c688292081845add12acd6908496e8d7d4360acfc
|
|
| MD5 |
a2c3cb1d4291473d685077e5356d623d
|
|
| BLAKE2b-256 |
777b4af1df1bf29aca61faa048bfe69314ac075598a3d285be1389a7aa7b10de
|
File details
Details for the file kube_agent-0.2.0-py3-none-any.whl.
File metadata
- Download URL: kube_agent-0.2.0-py3-none-any.whl
- Upload date:
- Size: 31.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.12.3 Linux/6.8.0-47-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
72c1c6d1bf1d146a30edd3e9453226335cc4ef5102590b82398d335a43265934
|
|
| MD5 |
02e539e59f239ef0208db4afb51128fb
|
|
| BLAKE2b-256 |
c01336b0ec015157d77370da387c2e3fa1dae0b9661545d0bc99635780541971
|