k8sgpt

repository·main·Indexed 27 days ago

https://github.com/k8sgpt-ai/k8sgpt

A tool for scanning Kubernetes clusters to diagnose and triage issues using SRE-informed analyzers and AI backends such as OpenAI, Azure, and Google Gemini. It features a CLI for cluster analysis, an MCP (Model Context Protocol) server for integration with tools like Claude Desktop, and support for remote caching via AWS S3, Azure Blob storage, and Google Cloud Storage.

Tokens
14.2K
Snippets
20
Records
127
Agent score
92%

What's inside k8sgpt

  1. CNCF and Tool Integrations Overview

    main

    k8sgpt integrates with several cloud-native tools and platforms:

    Observability & Monitoring

    • Prometheus: Export analysis results via Exporter/Metrics.
    • Prometheus Operator: Service discovery and alerting integration.
    • Alertmanager: Send analysis alerts directly to Alertmanager.
    • OpenTelemetry: Export analysis metrics and traces.
    • Grafana: Visualize results in Grafana dashboards.

    Kubernetes & Packaging

    • Kubernetes: Native resource analysis and diagnostics.
    • Helm: Available as a Helm chart in the k8sgpt-ai/charts repository.
    • Krew: Distributed as a kubectl plugin.

    Platforms & GitOps

    • OpenShift: Support for OpenShift-specific resources (e.g., CatalogSource, ClusterCatalog).
    • Kubeblocks: Analyzer support for KubeBlocks-managed databases.
    • FluxCD / ArgoCD: Compatible with GitOps workflows.
  2. Identify k8sgpt use cases and limitations

    main

    Primary Use Case

    Real-time cluster diagnostics: scan a Kubernetes cluster to receive AI-powered explanations of issues in plain English.

    Additional Use Cases

    • Continuous monitoring: via the k8sgpt operator.
    • Alerting: integration with Slack, Teams, Prometheus, and Alertmanager.
    • Extensibility: custom analyzer framework for new diagnostic logic.
    • AI Workflows: MCP server integration for AI assistants (e.g., Claude Desktop).

    Unsupported Use Cases (Limitations)

    • No Remediation: k8sgpt is read-only by design and does not modify or remediate cluster state.
    • No Security Scanning: It focuses on operational issues, not security posture/vulnerability scanning.
    • No Native AI Model: It consumes external AI APIs rather than providing its own model.
    • No Persistent Storage: It does not store cluster data (except for optional remote caching).
  3. Understand k8sgpt security architecture and data handling

    main

    k8sgpt is a read-only tool designed to scan Kubernetes clusters and diagnose issues. It uses a suite of analyzers to query the Kubernetes API and can optionally use AI backends (like OpenAI, Azure, or local models like Ollama) to provide natural language explanations.

    Key Security Features:

    • Read-only Access: k8sgpt only reads from the Kubernetes API and does not modify cluster state.
    • Data Anonymization: By default, k8sgpt masks sensitive Kubernetes resource data (names, labels, etc.) before sending it to AI backends to prevent accidental exposure.
    • Secure Communication: All communication with AI backends is performed over HTTPS/TLS.
    • Local AI Options: For maximum privacy, users can use local AI providers like Ollama or LocalAI to keep data within their own network.
  4. Implement and use Custom Analyzers

    main

    You can extend k8sgpt by writing custom analyzers that follow the required protobuf schema. Once defined in the k8sgpt configuration, they can be included in the scanning process.

    Configuration Example

    To add a local analyzer (e.g., a Rust service running on localhost:8080) to your config:

    custom_analyzers:
      - name: host-analyzer
        connection:
          url: localhost
          port: 8080

    Running Analysis with Custom Analyzers

    You must include the --custom-analysis flag when running the analyze command: k8sgpt analyze --custom-analysis

    Managing Custom Analyzers via CLI

    • List configured analyzers: k8sgpt custom-analyzer list
    • Add analyzer (without install): k8sgpt custom-analyzer add --name <name> --port <port>
    • Remove analyzers: k8sgpt custom-analyzer remove --names "<name1>,<name2>"
    k8sgpt analyze --custom-analysis
    k8sgpt custom-analyzer add --name my-custom-analyzer --port 8085
    k8sgpt custom-analyzer remove --names "my-custom-analyzer,my-custom-analyzer-2"
  5. Quick Start with k8sgpt

    main

    Follow these steps to perform your first Kubernetes cluster scan:

    1. Authenticate with an AI provider: By default, k8sgpt uses OpenAI. Run k8sgpt generate to get a browser link for an API key, then use k8sgpt auth add to save it (you can use the --password flag to provide it directly).
    2. Manage filters: Use k8sgpt filters to manage which analyzers are active.
    3. Run analysis:
      • k8sgpt analyze: Run a standard scan.
      • k8sgpt analyze --explain: Get detailed AI-powered explanations of issues.
      • k8sgpt analyze --with-doc: Include official Kubernetes documentation in the analysis.
  6. Start the k8sgpt Model Context Protocol (MCP) server

    main

    k8sgpt provides an MCP server that exposes Kubernetes operations as tools for AI assistants like Claude or ChatGPT.

    Stdio Mode

    Use this for local AI assistants running on your machine: k8sgpt serve --mcp

    HTTP Mode

    Use this for network access or stateless one-off invocations: k8sgpt serve --mcp --mcp-http --mcp-port 8089

    k8sgpt serve --mcp
    k8sgpt serve --mcp --mcp-http --mcp-port 8089
  7. Integrate k8sgpt with Claude Desktop via MCP

    main

    You can use k8sgpt as a Model Context Protocol (MCP) server to allow Claude Desktop to analyze your Kubernetes clusters. Requires k8sgpt v0.4.14 or later.

    Setup

    1. Ensure k8sgpt is installed and authenticated (k8sgpt auth).
    2. Start the MCP server: k8sgpt serve --mcp.
    3. In Claude Desktop, add a new integration with the following configuration:
    {
      "mcpServers": {
        "k8sgpt": {
          "command": "k8sgpt",
          "args": [
            "serve",
            "--mcp"
          ]
        }
      }
    }

    Usage

    You can then ask Claude questions like:

    • "Analyze my Kubernetes cluster"
    • "What's the health status of my cluster?"
    • "Show me any issues in the default namespace"
  8. Run the K8sGPT MCP Client Example

    main

    Run the compiled MCP client example by providing the path to your kubeconfig and the target Kubernetes namespace.

    Prerequisites:

    • Go 1.16 or later
    • Access to a Kubernetes cluster
    • kubectl configured to access your cluster
    ./mcp-client-example --kubeconfig=/path/to/kubeconfig --namespace=default
  9. Report a security vulnerability in k8sgpt

    main

    If you discover a security vulnerability, please use one of the following responsible disclosure methods:

    1. Email: Send details to contact@k8sgpt.ai
    2. Slack: Contact a maintainer in the #k8sgpt Slack channel
    3. GitHub: Use the "Report a vulnerability" button on the official GitHub repository