Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
K

kubectl-ai

> 云原生
Open source

AI powered Kubernetes Assistant

7.5K stars0 likes8 views
WebsiteGitHub

About

AI powered Kubernetes Assistant

kubectl-ai

kubectl-ai acts as an intelligent interface, translating user intent into precise Kubernetes operations, making Kubernetes management more accessible and efficient.

Table of Contents

  • Quick Start
    • Installation
    • Usage
  • Configuration
  • Tools
  • Docker Quick Start
  • MCP Client Mode
  • Extras
  • MCP Server Mode
  • Start Contributing
  • Learning Resources

Quick Start

First, ensure that kubectl is installed and configured.

Installation

Quick Install (Linux & MacOS only)

bash
curl -sSL https://raw.githubusercontent.com/GoogleCloudPlatform/kubectl-ai/main/install.sh | bash
Other Installation Methods

Manual Installation (Linux, MacOS and Windows)

  1. Download the latest release from the releases page for your target machine.

  2. Untar the release, make the binary executable and move it to a directory in your $PATH (as shown below).

bash
tar -zxvf kubectl-ai_Darwin_arm64.tar.gz
chmod a+x kubectl-ai
sudo mv kubectl-ai /usr/local/bin/

Install with Krew (Linux/macOS/Windows)

First of all, you need to have krew installed, refer to krew document for more details Then you can install with krew

bash
kubectl krew install ai

Now you can invoke kubectl-ai as a kubectl plugin like this: kubectl ai.

Install on NixOS

There are multiple ways to install kubectl-ai on NixOS. For a permanent installation add the following to your NixOS-Configuration:

nix
  environment.systemPackages = with pkgs; [
    kubectl-ai
  ];

For a temporary installation, you can use the following command:

bash
nix-shell -p kubectl-ai

Usage

kubectl-ai supports AI models from gemini, vertexai, azopenai, openai, grok, bedrock and local LLM providers such as ollama and llama.cpp.

Using Gemini (Default)

Set your Gemini API key as an environment variable. If you don't have a key, get one from Google AI Studio.

bash
export GEMINI_API_KEY=your_api_key_here
kubectl-ai

# Use different gemini model
kubectl-ai --model gemini-2.5-pro-exp-03-25

# Use 2.5 flash (faster) model
kubectl-ai --quiet --model gemini-2.5-flash-preview-04-17 "check logs for nginx app in hello namespace"
Use other AI models

Using AI models running locally (ollama or llama.cpp)

You can use kubectl-ai with AI models running locally. kubectl-ai supports ollama and llama.cpp to use the AI models running locally.

Additionally, the modelserving directory provides tools and instructions for deploying your own llama.cpp-based LLM serving endpoints locally or on a Kubernetes cluster. This allows you to host models like Gemma directly in your environment.

An example of using Google's gemma3 model with ollama:

bash
# assuming ollama is already running and you have pulled one of the gemma models
# ollama pull gemma3:12b-it-qat

# if your ollama server is at remote, use OLLAMA_HOST variable to specify the host
# export OLLAMA_HOST=http://192.168.1.3:11434/

# enable-tool-use-shim because models require special prompting to enable tool calling
kubectl-ai --llm-provider ollama --model gemma3:12b-it-qat --enable-tool-use-shim

# you can use `models` command to discover the locally available models
>> models

Using Grok

You can use X.AI's Grok model by setting your X.AI API key:

bash
export GROK_API_KEY=your_xai_api_key_here
kubectl-ai --llm-provider=grok --model=grok-3-beta

Using AWS Bedrock

You can use AWS Bedrock Claude models with your AWS credentials:

bash
# Configure AWS credentials using AWS SSO
aws sso login --profile your-profile-name
# Or use other AWS credential methods (IAM roles, environment variables, etc.)

# Use Claude 4 Sonnet (default)
kubectl-ai --llm-provider=bedrock --model=us.anthropic.claude-sonnet-4-20250514-v1:0

# Use Claude 3.7 Sonnet
kubectl-ai --llm-provider=bedrock --model=us.anthropic.claude-3-7-sonnet-20250219-v1:0

# Override model via environment variable
export BEDROCK_MODEL=us.anthropic.claude-sonnet-4-20250514-v1:0
kubectl-ai --llm-provider=bedrock

AWS Bedrock uses the standard AWS SDK credential chain, supporting:

  • AWS SSO profiles
  • IAM roles (for EC2/ECS/Lambda)
  • Environment variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)
  • AWS CLI configuration files

Using Azure OpenAI

You can also use Azure OpenAI deployment by setting your OpenAI API key and specifying the provider:

bash
export AZURE_OPENAI_API_KEY=your_azure_openai_api_key_here
export AZURE_OPENAI_ENDPOINT=https://your_azure_openai_endpoint_here
kubectl-ai --llm-provider=azopenai --model=your_azure_openai_deployment_name_here
# or
az login
kubectl-ai --llm-provider=openai://your_azure_openai_endpoint_here --model=your_azure_openai_deployment_name_here

Using OpenAI

You can also use OpenAI models by setting your OpenAI API key and specifying the provider:

bash
export OPENAI_API_KEY=your_openai_api_key_here
kubectl-ai --llm-provider=openai --model=gpt-4.1

Using OpenAI Compatible API

For example, you can use aliyun qwen-xxx models as follows.

bash
export OPENAI_API_KEY=your_openai_api_key_here
export OPENAI_ENDPOINT=https://dashscope.aliyuncs.com/compatible-mode/v1
kubectl-ai --llm-provider=openai --model=qwen-plus

Run interactively:

bash
kubectl-ai

The interactive mode allows you to have a chat with kubectl-ai, 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.

Or, run with a task as input:

bash
kubectl-ai --quiet "fetch logs for nginx app in hello namespace"

Combine it with other unix commands:

bash
kubectl-ai < query.txt
# OR
echo "list 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:

bash
cat error.log | kubectl-ai "explain the error"

We also support persistence between runs with an opt-in. This lets you save a session to the local filesystem, and resume it to maintain previous context. It even works between different interfaces!

bash
kubectl-ai --new-session # start a new session
kubectl-ai --list-sessions # list all saved sessions
kubectl-ai --resume-session 20250807-510872 # resume session 20250807-510872
kubectl-ai --delete-session 20250807-510872 # delete session 20250807-510872

Configuration

You can also configure kubectl-ai using a YAML configuration file at ~/.config/kubectl-ai/config.yaml:

bash
mkdir -p ~/.config/kubectl-ai/
cat <<EOF > ~/.config/kubectl-ai/config.yaml
model: gemini-2.5-flash-preview-04-17
llmProvider: gemini
toolConfigPaths: ~/.config/kubectl-ai/tools.yaml
EOF

Verify your configuration:

bash
kubectl-ai --quiet model
More configuration Options

Here's a complete configuration file with all available options and their default values:

…

All these settings can be configured through either:

  1. Command line flags (e.g., --model=gemini-2.5-pro)
  2. Configuration file (~/.config/kubectl-ai/config.yaml)
  3. Environment variables (e.g., GEMINI_API_KEY)

Command line flags take precedence over configuration file settings.

Tools

kubectl-ai leverages LLMs to suggest and execute Kubernetes operations using a set of powerful tools. It comes with built-in tools like kubectl and bash.

You can also extend its capabilities by defining your own custom tools. By default, kubectl-ai looks for your tool configurations in ~/.config/kubectl-ai/tools.yaml.

To specify tools configuration files or directories containing tools configuration files, use:

bash
./kubectl-ai --custom-tools-config=<path-to-tools-directory> "your prompt here"

For further details on how to configure your own tools, go here.

Docker Quick Start

This project provides a Docker image that gives you a standalone environment for running kubectl-ai, including against a GKE cluster.

Running the container against GKE

Step 1: Build the Image

Clone the repository and build the image with the following command

bash
git clone https://github.com/GoogleCloudPlatform/kubectl-ai.git
cd kubectl-ai
docker build -t kubectl-ai:latest -f images/kubectl-ai/Dockerfile .

Step 2: Connect to Your GKE Cluster

Set up application default credentials and connect to your GKE cluster.

bash
gcloud auth application-default login # If in a gcloud shell this is not necessary
gcloud container clusters get-credentials <cluster-name> --zone <zone>

Step 3: Run the kubectl-ai container

Below is a sample command that can be used to launch the container with a locally hosted web-ui. Be sure to replace the placeholder values with your specific Google Cloud project ID and location. Note you do not need to mount the gcloud config directory if you're on a cloudshell machine.

bash
docker run --rm -it -p 8080:8080 -v ~/.kube:/root/.kube -v ~/.config/gcloud:/root/.config/gcloud -e GOOGLE_CLOUD_LOCATION=us-central1 -e GOOGLE_CLOUD_PROJECT=my-gcp-project kubectl-ai:latest --llm-provider vertexai --ui-listen-address 0.0.0.0:8080 --ui-type web

For more info about running from the container image see CONTAINER.md

MCP Client Mode

Note: MCP Client Mode is available in kubectl-ai version v0.0.12 and onwards.

kubectl-ai can connect to external MCP Servers to access additional tools in addition to built-in tools.

Quick Start with MCP Client

Enable MCP client mode:

bash
kubectl-ai --mcp-client

MCP Client Configuration

Create or edit ~/.config/kubectl-ai/mcp.yaml to customize MCP servers:

yaml
servers:
  # Local MCP server (stdio-based)
  # sequential-thinking: Advanced reasoning and step-by-step analysis
  - name: sequential-thinking
    command: npx
    args:
      - -y
      - "@modelcontextprotocol/server-sequential-thinking"
  
  # Remote MCP server (HTTP-based)
  - name: cloudflare-documentation
    url: https://docs.mcp.cloudflare.com/mcp
    
  # Optional: Remote MCP server with authentication
  - name: custom-api
    url: https://api.example.com/mcp
    auth:
      type: "bearer"
      token: "${MCP_TOKEN}"

The system automatically:

  • Converts parameter names (snake_case → camelCase)
  • Handles type conversion (strings → numbers/booleans when appropriate)
  • Provides fallback behavior for unknown servers

No additional setup required - just use the --mcp-client flag and the AI will have access to all configured MCP tools.

For detailed configuration options, troubleshooting, and advanced features for MCP Client mode, see the MCP Client Documentation.

For multi-server orchestration and security automation examples, see the MCP Client Integration Guide.

Extras

You can use the following special keywords for specific actions:

  • model: Display the currently selected model.
  • models: List all available models.
  • tools: List all available tools.
  • version: Display the kubectl-ai version.
  • reset: Clear the conversational context.
  • clear: Clear the terminal screen.
  • exit or quit: Terminate the interactive shell (Ctrl+C also works).

Invoking as kubectl plugin

You can also run kubectl ai. kubectl

Issues· 184 open

View all issuesOpen on GitHub
  • #693

    Opt-in, environment-scoped memory for kubectl-ai

    Updated Sep 27, 2026
  • #692

    How does this compare to other agents (harnesses)?

    Updated Sep 21, 2026
  • #618

    [Bug]: initializing MCP client: unsupported protocol version: "2025-11-25

    bugUpdated Sep 9, 2026
  • #334

    Support container-based sandbox for agent execution to improve safety and portability

    enhancementUpdated Sep 5, 2026
  • #332

    Gemini rate limit error (429 code)

    documentationquestionUpdated Sep 2, 2026
  • #678

    gollm: ollama provider breaks against ollama >= 0.20 API

    Updated Jul 21, 2026
  • #667

    Use Evidra Bench for live infrastructure regression benchmarking

    Updated May 20, 2026
  • #661

    Ollama Gemma4 support

    Updated Apr 18, 2026
  • #599

    Kubectl-ai | MaxIterations Question | Bedrock Bug

    bugUpdated Apr 8, 2026
  • #628

    [Feature]: Add an option suggestOnly

    enhancementhelp wantedUpdated Mar 27, 2026

> Tags

Goaiassistantclikubernetes

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedOct 2, 2026
Category云原生
PricingOpen source

> Related tools

K
Kubernetes
容器编排事实标准
H
Helm
Kubernetes 包管理器
S
seaweedfs
SeaweedFS is a distributed storage system for object storage (S3), file systems, and Iceberg tables,