kubectl-ai is a kubernetes assistant that enhances the Kubernetes command-line experience using AI capabilities. It leverages Large Language Models (LLMs) such as Gemini to help users interact with Kubernetes clusters more efficiently.
- Go 1.23 or later
- kubectl installed and configured
- Access to a Gemini API Key (or other supported AI models)
# Clone the repository
git clone https://github.com/GoogleCloudPlatform/kubectl-ai.git
cd kubectl-ai
# Build and install
go install .
Set up Gemini API key as follows:
export GEMINI_API_KEY=your_api_key_here
Get your API key from Google AI Studio if you don't have one.
Once installed, you can use kubectl-ai in two ways:
Simply provide your query as a positional argument:
kubectl-ai "your natural language query"
You can also pipe content to kubectl-ai, and use it with other unix commands:
kubectl-ai < query.txt
# OR
echo "list all pods in the default namespace" | kubectl-ai
You can even combine a positional argument with stdin input. The positional argument will be used as a prefix to the stdin content:
cat error.log | kubectl-ai "explain the error"
If you run kubectl-ai without providing a query, it launches an interactive chat-like shell:
kubectl-ai
This interactive mode allows you to have a conversation with the AI assistant, asking multiple questions in sequence while maintaining context from previous interactions. Simply type your queries and press Enter to receive responses. To exit the interactive shell, type exit
or press Ctrl+C.
# Get information about pods in the default namespace
kubectl-ai "show me all pods in the default namespace"
# Create a new deployment
kubectl-ai "create a deployment named nginx with 3 replicas using the nginx:latest image"
# Troubleshoot issues
kubectl-ai "double the capacity for the nginx app"
The kubectl-ai
assistant will process your query, execute the appropriate kubectl commands, and provide you with the results and explanations.
Note: This is not an officially supported Google product. This project is not eligible for the Google Open Source Software Vulnerability Rewards Program.