Kube-copilot

repository·master·Indexed 42 days ago

https://github.com/feiskyer/kube-copilot

An AI-powered CLI tool that uses Large Language Models (LLMs) to automate Kubernetes cluster management, diagnose workload issues, audit security, and generate manifests. It supports various LLM providers including OpenAI, Anthropic Claude, Azure OpenAI, Google Gemini, and Ollama, and integrates external tools via the Model Context Protocol (MCP).

Tokens
3.4K
Snippets
19
Records
23
Agent score
53%

What's inside Kube-copilot

  1. Integrate external tools using Model Context Protocol (MCP)

    master

    Kube-copilot supports the Model Context Protocol (MCP) to allow the LLM to use external tools during diagnose and execute operations.

    1. Create an MCP configuration file (e.g., mcp-config.json):
    {
      "mcpServers": {
        "sequential-thinking": {
          "command": "npx",
          "args": [
            "-y",
            "@modelcontextprotocol/server-sequential-thinking"
          ]
        },
        "kubernetes": {
          "command": "uvx",
          "args": [
            "mcp-kubernetes-server"
          ]
        }
      }
    }
    1. Run kube-copilot with the config:
    kube-copilot execute --instructions "Your instructions" --mcp-config path/to/mcp-config.json
    {
      "mcpServers": {
        "sequential-thinking": {
          "command": "npx",
          "args": [
            "-y",
            "@modelcontextprotocol/server-sequential-thinking"
          ]
        }
      }
    }
  2. Configure LLM providers for kube-copilot

    master

    Kube-copilot supports various LLM providers via environment variables.

    OpenAI

    Set the OPENAI_API_KEY environment variable.

    Anthropic Claude (OpenAI Compatible)

    Set the following:

    • OPENAI_API_KEY=<your-anthropic-key>
    • OPENAI_API_BASE='https://api.anthropic.com/v1/'

    Azure OpenAI

    Set the following:

    • AZURE_OPENAI_API_KEY=<your-api-key>
    • AZURE_OPENAI_API_BASE=https://<replace-this>.openai.azure.com/
    • AZURE_OPENAI_API_VERSION=2025-03-01-preview

    Google Gemini (OpenAI Compatible)

    Set the following:

    • OPENAI_API_KEY=<your-google-ai-key>
    • OPENAI_API_BASE='https://generativelanguage.googleapis.com/v1beta/openai/'

    Ollama or other OpenAI compatible LLMs

    Set the following:

    • OPENAI_API_KEY=<your-api-key>
    • OPENAI_API_BASE='http://localhost:11434/v1' (or your own base URL)
  3. Kube-copilot Global Flags Reference

    master

    The following flags are available to all kube-copilot subcommands:

    • -c, --count-tokens: Print the token count used.
    • -x, --max-iterations <int>: Max iterations for the agent running (default: 10 or 30 depending on command context).
    • -t, --max-tokens <int>: Max tokens for the GPT model (default: 2048).
    • -m, --model <string>: OpenAI model to use (default: gpt-4o).
    • -v, --verbose: Enable verbose output.
  4. Analyze Kubernetes resource issues

    master

    Use the analyze command to identify potential issues in a specific Kubernetes resource. By default, it analyzes pod resources in the default namespace.

    Flags:

    • -n, --name <string>: The name of the resource.
    • -s, --namespace <string>: The namespace (default: default).
    • -r, --resource <string>: The resource type (default: pod).
    kube-copilot analyze --name <resource-name> --namespace <namespace> --resource pod
  5. Diagnose Pod problems

    master

    Use the diagnose command to troubleshoot problems occurring within a specific Pod. You can optionally provide an MCP configuration file to enhance diagnosis with external tools.

    Flags:

    • -n, --name <string>: The name of the Pod.
    • -s, --namespace <string>: The namespace (default: default).
    • -p, --mcp-config <string>: Path to an MCP configuration file.
    kube-copilot diagnose --name <pod-name> --namespace <namespace>
  6. Execute operations via prompt instructions

    master

    Use the execute command to perform Kubernetes operations or ask questions based on natural language instructions. This command can leverage the Model Context Protocol (MCP) for tool integration.

    Flags:

    • -i, --instructions <string>: The prompt/instructions to execute.
    • -p, --mcp-config <string>: Path to an MCP configuration file.
    kube-copilot execute --instructions "Your instructions" --mcp-config path/to/mcp-config.json
  7. Generate Kubernetes manifests from prompts

    master

    Use the generate command to create Kubernetes manifests based on a text prompt. After generation, the CLI will prompt you to confirm whether you want to apply the manifests to your cluster.

    Flags:

    • -p, --prompt <string>: The prompt used to generate the manifests.
    kube-copilot generate --prompt "Create a deployment with 3 replicas of nginx"
  8. Audit Pod security issues

    master

    Use the audit command to assess security vulnerabilities for a specific Pod. This command requires trivy to be installed on your local machine.

    Flags:

    • -n, --name <string>: The name of the Pod.
    • -s, --namespace <string>: The namespace (default: default).
    kube-copilot audit --name <pod-name> --namespace <namespace>
  9. Configure kube-copilot global flags

    master

    The following persistent flags can be used with any kube-copilot subcommand to configure the AI model behavior and execution settings:

    --model, -m string
        AI model to use (default: "gpt-4o")
    
    --max-tokens, -t int
        Max tokens for the AI model (default: 2048)
    
    --count-tokens, -c
        Print tokens count
    
    --verbose, -v
        Enable verbose output
    
    --max-iterations, -x int
        Max iterations for the agent running (default: 30)
  10. Reference: `execute` command flags

    master

    The following flags are available for the execute command:

    FlagShorthandDescription
    --instructions-iThe natural language instructions to execute (Required)
    --mcp-config-pPath to the MCP (Model Context Protocol) configuration file
    --disable-kubectl-dDisables the kubectl tool (useful when using an MCP server)