Skip to main content

Kubernetes Copilot

Project description

Kubernetes Copilot

Kubernetes Copilot powered by OpenAI.

Features:

  • Automate Kubernetes cluster operations using ChatGPT (GPT-4 or GPT-3.5).
  • 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 copilot with pip command 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-copilot

# Option 2: use venv to install the copilot
python3 -m venv copilotenv
source copilotenv/bin/activate
pip install kube-copilot

# Option 3: Use pip to install the copilot (not recommended)
pip install kube-copilot

Setup:

  • Ensure kubectl is installed on the local machine and the kubeconfig file is configured for Kubernetes cluster access.
  • Install trivy to assess container image security issues (for the audit command).
  • Set the OpenAI API key as the OPENAI_API_KEY environment variable to enable ChatGPT functionality.
    • For Azure OpenAI service, please set AZURE_OPENAI_API_KEY=<your-key> and AZURE_OPENAI_ENDPOINT=https://<replace-this>.openai.azure.com/.

Run in Kubernetes

Option 1: Web UI with Helm (recommended)

# Option 1: OpenAI
export OPENAI_API_KEY="<replace-this>"
helm install kube-copilot kube-copilot \
  --repo https://feisky.xyz/kube-copilot \
  --set openai.apiModel=gpt-4 \
  --set openai.apiKey=$OPENAI_API_KEY

# Option 2: Azure OpenAI Service
export AZURE_OPENAI_API_KEY="<replace-this>"
export AZURE_OPENAI_ENDPOINT="<replace-this>"
helm install kube-copilot kube-copilot \
  --repo https://feisky.xyz/kube-copilot \
  --set openai.apiModel=gpt-4 \
  --set openai.apiKey=$AZURE_OPENAI_API_KEY \
  --set openai.apiBase=$AZURE_OPENAI_ENDPOINT

# Forwarding requests to the service
kubectl port-forward service/kube-copilot 8080:80
echo "Visit http://127.0.0.1:8080 to use the copilot"

Option 2: CLI with kubectl

kubectl run -it --rm copilot \
  --env="OPENAI_API_KEY=$OPENAI_API_KEY" \
  --restart=Never \
  --image=ghcr.io/feiskyer/kube-copilot \
  -- 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-copilot \
  -- execute --verbose 'What Pods are using max memory in the cluster'

Refer kubernetes.md for more detailed steps.

How to use web UI

image-20230707191237629

How to use CLI

Running directly in the terminal:

Usage: kube-copilot [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-copilot audit POD [NAMESPACE] will audit security issues for a Pod:

Usage: kube-copilot 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-copilot diagnose POD [NAMESPACE] will diagnose problems for a Pod:

Usage: kube-copilot 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-copilot analyze RESOURCE NAME [NAMESPACE] will analyze potential issues for the given resource object:

Usage: kube-copilot 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-copilot execute INSTRUCTIONS will execute operations based on prompt instructions. It could also be used to ask any questions.

Usage: kube-copilot 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-copilot 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-copilot 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-copilot-python with Apache License. The Go version of this project is maintained at feiskyer/kube-copilot with same license.

If you would like to contribute to the project, please follow these guidelines:

  1. Fork the repository and clone it to your local machine.
  2. Create a new branch for your changes.
  3. Make your changes and commit them with a descriptive commit message.
  4. Push your changes to your forked repository.
  5. Open a pull request to the main repository.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kube_copilot-0.2.1.tar.gz (22.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kube_copilot-0.2.1-py3-none-any.whl (24.3 kB view details)

Uploaded Python 3

File details

Details for the file kube_copilot-0.2.1.tar.gz.

File metadata

  • Download URL: kube_copilot-0.2.1.tar.gz
  • Upload date:
  • Size: 22.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.11.13 Darwin/24.5.0

File hashes

Hashes for kube_copilot-0.2.1.tar.gz
Algorithm Hash digest
SHA256 d5890d889ddc3e4cf62e571f7f009c61ff6cb2c1ff7bf8911bcaa23475cfe80f
MD5 3800c87f192fd61a3c119c792291cafe
BLAKE2b-256 e47ccf1262b47a4d3c2b98f9d914aa8a581dd5e7399178da66e8f2146e0279f7

See more details on using hashes here.

File details

Details for the file kube_copilot-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: kube_copilot-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 24.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.11.13 Darwin/24.5.0

File hashes

Hashes for kube_copilot-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 34c5ea7ba1f4a07b10baca646b87c78bc1f2c929f38af7533cc004fe3d0125ec
MD5 6a4435135449b69b0d000eb7642da92a
BLAKE2b-256 cf9df32369c91ab383ef786fdbc959cbab226a17240589202e00afdd3534ea2f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page