New: K8sGPT works with Claude Desktop!

Back to Documentation

CLI Reference

Comprehensive reference for K8sGPT's command-line interface

Overview

The K8sGPT CLI is the primary interface for interacting with K8sGPT. It provides commands for analyzing your Kubernetes cluster, configuring settings, and managing integrations.

Installation

Install K8sGPT CLI using one of the following methods:

# Using Homebrew (macOS)
brew install k8sgpt

# Using curl
curl -sSfL https://raw.githubusercontent.com/k8sgpt-ai/k8sgpt/main/install.sh | sh

# Using wget
wget -q -O - https://raw.githubusercontent.com/k8sgpt-ai/k8sgpt/main/install.sh | sh

Basic Commands

Analyze

k8sgpt analyze [flags]

Flags:
  -a, --analyzer string[]   Analyzer to use
  -f, --format string      Output format (text, json, yaml)
  -n, --namespace string   Namespace to analyze
  -o, --output string      Output file
  -s, --silent            Run in silent mode

Configure

k8sgpt config [command]

Available Commands:
  add         Add a new configuration
  delete      Delete a configuration
  list        List all configurations
  set         Set a configuration value

Version

k8sgpt version

Display the version of K8sGPT

Advanced Commands

Generate

k8sgpt generate [command]

Available Commands:
  analyzer    Generate a new analyzer
  integration Generate an integration configuration

Serve

k8sgpt serve [flags]

Flags:
  -p, --port int         Port to listen on (default 8080)
  -h, --host string      Host to listen on (default "0.0.0.0")

Configuration

K8sGPT can be configured using a YAML file or environment variables:

# config.yaml
ai:
  provider: openai
  model: gpt-3.5-turbo
  temperature: 0.7
  max_tokens: 150

filters:
  namespace: default
  severity: warning

output:
  format: text
  file: analysis.txt

Environment Variables

  • K8SGPT_AI_PROVIDER - AI provider to use
  • K8SGPT_AI_MODEL - AI model to use
  • K8SGPT_OPENAI_API_KEY - OpenAI API key
  • K8SGPT_ANALYZERS - Comma-separated list of analyzers
  • K8SGPT_NAMESPACE - Default namespace

Troubleshooting

Common issues and solutions:

  • Check Kubernetes context and permissions
  • Verify AI provider configuration
  • Ensure analyzers are properly installed
  • Check network connectivity
  • Review logs for detailed error messages