Kubernetes Copilot powered by LLM, which leverages advanced language models to streamline and enhance Kubernetes cluster management. This tool integrates seamlessly with your existing Kubernetes setup, providing intelligent automation, diagnostics, and manifest generation capabilities. By utilizing the power of AI, Kubernetes Copilot simplifies complex operations and helps maintain the health and security of your Kubernetes workloads.
- Automate Kubernetes cluster operations using ChatGPT (GPT-4 or GPT-3.5).
- Diagnose and analyze potential issues for Kubernetes workloads.
- Generate Kubernetes manifests based on provided prompt instructions.
- Utilize native
kubectl
andtrivy
commands for Kubernetes cluster access and security vulnerability scanning. - Access the web and perform Google searches without leaving the terminal.
Install the kube-copilot CLI with the following command:
go install github.com/feiskyer/kube-copilot/cmd/kube-copilot@latest
Setup the following environment variables:
- 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 (only required for theaudit
command). - Set the OpenAI API key as the
OPENAI_API_KEY
environment variable to enable ChatGPT functionality.
Then run the following commands directly in the terminal:
Kubernetes Copilot powered by OpenAI
Usage:
kube-copilot [command]
Available Commands:
analyze Analyze issues for a given resource
audit Audit security issues for a Pod
completion Generate the autocompletion script for the specified shell
diagnose Diagnose problems for a Pod
execute Execute operations based on prompt instructions
generate Generate Kubernetes manifests
help Help about any command
version Print the version of kube-copilot
Flags:
-c, --count-tokens Print tokens count
-h, --help help for kube-copilot
-x, --max-iterations int Max iterations for the agent running (default 10)
-t, --max-tokens int Max tokens for the GPT model (default 2048)
-m, --model string OpenAI model to use (default "gpt-4")
-v, --verbose Enable verbose output
--version version for kube-copilot
Use "kube-copilot [command] --help" for more information about a command.
OpenAI
Set the OpenAI API key as the OPENAI_API_KEY
environment variable to enable OpenAI functionality.
Azure OpenAI
For Azure OpenAI service, set the following environment variables:
AZURE_OPENAI_API_KEY=<your-api-key>
AZURE_OPENAI_API_BASE=https://<replace-this>.openai.azure.com/
AZURE_OPENAI_API_VERSION=2025-02-01-preview
Ollama or other OpenAI compatible LLMs
For Ollama or other OpenAI compatible LLMs, set the following environment variables:
OPENAI_API_KEY=<your-api-key>
OPENAI_API_BASE='http://localhost:11434/v1'
(or your own base URL)
Analyze issues for a given kubernetes resource
kube-copilot analyze [--resource pod] --name <resource-name> [--namespace <namespace>]
will analyze potential issues for the given resource object:
Analyze issues for a given resource
Usage:
kube-copilot analyze [flags]
Flags:
-h, --help help for analyze
--name string Resource name
-n, --namespace string Resource namespace (default "default")
-r, --resource string Resource type (default "pod")
Global Flags:
-c, --count-tokens Print tokens count
-x, --max-iterations int Max iterations for the agent running (default 10)
-t, --max-tokens int Max tokens for the GPT model (default 2048)
-m, --model string OpenAI model to use (default "gpt-4")
-v, --verbose Enable verbose output
Audit Security Issues for Pod
kube-copilot audit --name <pod-name> [--namespace <namespace>]
will audit security issues for a Pod:
Audit security issues for a Pod
Usage:
kube-copilot audit [flags]
Flags:
-h, --help help for audit
--name string Pod name
-n, --namespace string Pod namespace (default "default")
Global Flags:
-c, --count-tokens Print tokens count
-x, --max-iterations int Max iterations for the agent running (default 10)
-t, --max-tokens int Max tokens for the GPT model (default 2048)
-m, --model string OpenAI model to use (default "gpt-4")
-v, --verbose Enable verbose output
Diagnose Problems for Pod
kube-copilot diagnose --name <pod-name> [--namespace <namespace>]
will diagnose problems for a Pod:
Diagnose problems for a Pod
Usage:
kube-copilot diagnose [flags]
Flags:
-h, --help help for diagnose
--name string Pod name
-n, --namespace string Pod namespace (default "default")
Global Flags:
-c, --count-tokens Print tokens count
-x, --max-iterations int Max iterations for the agent running (default 10)
-t, --max-tokens int Max tokens for the GPT model (default 2048)
-m, --model string OpenAI model to use (default "gpt-4")
-v, --verbose Enable verbose output
Execute operations based on prompt instructions
kube-copilot execute --instructions <instructions>
will execute operations based on prompt instructions.
It could also be used to ask any questions.
Execute operations based on prompt instructions
Usage:
kube-copilot execute [flags]
Flags:
-h, --help help for execute
--instructions string instructions to execute
Global Flags:
-c, --count-tokens Print tokens count
-x, --max-iterations int Max iterations for the agent running (default 10)
-t, --max-tokens int Max tokens for the GPT model (default 2048)
-m, --model string OpenAI model to use (default "gpt-4")
-v, --verbose Enable verbose output
Generate Kubernetes Manifests
Use the kube-copilot generate --prompt <prompt>
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.
Generate Kubernetes manifests
Usage:
kube-copilot generate [flags]
Flags:
-h, --help help for generate
-p, --prompt string Prompts to generate Kubernetes manifests
Global Flags:
-c, --count-tokens Print tokens count
-x, --max-iterations int Max iterations for the agent running (default 10)
-t, --max-tokens int Max tokens for the GPT model (default 2048)
-m, --model string OpenAI model to use (default "gpt-4")
-v, --verbose Enable verbose output
Google Search
Large language models are trained with outdated data, and hence may lack the most current information or miss out on recent developments. This is where Google Search becomes an optional tool. By integrating real-time search capabilities, LLMs can access the latest data, ensuring that responses are not only accurate but also up-to-date.
To enable it, set GOOGLE_API_KEY
and GOOGLE_CSE_ID
(obtain API key from Google Cloud and CSE ID from Google CSE).
Please refer feiskyer/kube-copilot-python for the Python implementation of the same project.
The project is opensource at github feiskyer/kube-copilot (Go) and feiskyer/kube-copilot-python (Python) 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.