MCPcopy Index your code
hub / github.com/k8sgpt-ai/k8sgpt

github.com/k8sgpt-ai/k8sgpt @v0.4.35 sqlite

repository ↗ · DeepWiki ↗ · release v0.4.35 ↗
961 symbols 3,348 edges 186 files 144 documented · 15% 71 cross-repo links
README

Text changing depending on mode. Light: 'So light!' Dark: 'So dark!'

GitHub code size in bytes GitHub Workflow Status GitHub release (latest by date) OpenSSF Best Practices Link to documentation License Go version codecov GitHub last commit (branch)

k8sgpt is a tool for scanning your Kubernetes clusters, diagnosing, and triaging issues in simple English.

It has SRE experience codified into its analyzers and helps to pull out the most relevant information to enrich it with AI.

Out of the box integration with OpenAI, Azure, Cohere, Amazon Bedrock, Google Gemini and local models.

Sister project: Check out sympozium for managing agents in Kubernetes.

K8sGPT - K8sGPT gives Kubernetes Superpowers to everyone | Product Hunt Featured|HelloGitHub

Table of Contents

CLI Installation

Linux/Mac via brew

brew install k8sgpt

or

brew tap k8sgpt-ai/k8sgpt
brew install k8sgpt

RPM-based installation (RedHat/CentOS/Fedora)

32 bit:

sudo rpm -ivh https://github.com/k8sgpt-ai/k8sgpt/releases/download/v0.4.35/k8sgpt_386.rpm

64 bit:

sudo rpm -ivh https://github.com/k8sgpt-ai/k8sgpt/releases/download/v0.4.35/k8sgpt_amd64.rpm

DEB-based installation (Ubuntu/Debian)

32 bit:

curl -LO https://github.com/k8sgpt-ai/k8sgpt/releases/download/v0.4.35/k8sgpt_386.deb
sudo dpkg -i k8sgpt_386.deb

64 bit:

curl -LO https://github.com/k8sgpt-ai/k8sgpt/releases/download/v0.4.35/k8sgpt_amd64.deb
sudo dpkg -i k8sgpt_amd64.deb

APK-based installation (Alpine)

32 bit:

wget https://github.com/k8sgpt-ai/k8sgpt/releases/download/v0.4.35/k8sgpt_386.apk apk add --allow-untrusted k8sgpt_386.apk

64 bit:

wget https://github.com/k8sgpt-ai/k8sgpt/releases/download/v0.4.35/k8sgpt_amd64.apk apk add --allow-untrusted k8sgpt_amd64.apk

Failing Installation on WSL or Linux (missing gcc)

When installing Homebrew on WSL or Linux, you may encounter the following error:

==> Installing k8sgpt from k8sgpt-ai/k8sgpt Error: The following formula cannot be installed from a bottle and must be
built from the source. k8sgpt Install Clang or run brew install gcc.

If you install gcc as suggested, the problem will persist. Therefore, you need to install the build-essential package.

   sudo apt-get update
   sudo apt-get install build-essential

Windows

  • Download the latest Windows binaries of k8sgpt from the Release tab based on your system architecture.
  • Extract the downloaded package to your desired location. Configure the system PATH environment variable with the binary location

Operator Installation

To install within a Kubernetes cluster please use our k8sgpt-operator with installation instructions available here

This mode of operation is ideal for continuous monitoring of your cluster and can integrate with your existing monitoring such as Prometheus and Alertmanager.

Quick Start

  • Currently, the default AI provider is OpenAI, you will need to generate an API key from OpenAI
  • You can do this by running k8sgpt generate to open a browser link to generate it
  • Run k8sgpt auth add to set it in k8sgpt.
  • You can provide the password directly using the --password flag.
  • Run k8sgpt filters to manage the active filters used by the analyzer. By default, all filters are executed during analysis.
  • Run k8sgpt analyze to run a scan.
  • And use k8sgpt analyze --explain to get a more detailed explanation of the issues.
  • You also run k8sgpt analyze --with-doc (with or without the explain flag) to get the official documentation from Kubernetes.

Using with Claude Desktop

K8sGPT can be integrated with Claude Desktop to provide AI-powered Kubernetes cluster analysis. This integration requires K8sGPT v0.4.14 or later.

Prerequisites

  1. Install K8sGPT v0.4.14 or later: sh brew install k8sgpt

  2. Install Claude Desktop from the official website

  3. Configure K8sGPT with your preferred AI backend: sh k8sgpt auth

Setup

  1. Start the K8sGPT MCP server: sh k8sgpt serve --mcp

  2. In Claude Desktop:

  3. Open Settings
  4. Navigate to the Integrations section
  5. Add K8sGPT as a new integration
  6. The MCP server will be automatically detected

  7. Configure Claude Desktop with the following JSON:

json { "mcpServers": { "k8sgpt": { "command": "k8sgpt", "args": [ "serve", "--mcp" ] } } }

Usage

Once connected, you can use Claude Desktop to: - Analyze your Kubernetes cluster - Get detailed insights about cluster health - Receive recommendations for fixing issues - Query cluster information

Example commands in Claude Desktop: - "Analyze my Kubernetes cluster" - "What's the health status of my cluster?" - "Show me any issues in the default namespace"

Troubleshooting

If you encounter connection issues: 1. Ensure K8sGPT is running with the MCP server enabled 2. Verify your Kubernetes cluster is accessible 3. Check that your AI backend is properly configured 4. Restart both K8sGPT and Claude Desktop

For more information, visit our documentation.

Analyzers

K8sGPT uses analyzers to triage and diagnose issues in your cluster. It has a set of analyzers that are built in, but you will be able to write your own analyzers.

Built in analyzers

Enabled by default

  • [x] podAnalyzer
  • [x] pvcAnalyzer
  • [x] rsAnalyzer
  • [x] serviceAnalyzer
  • [x] eventAnalyzer
  • [x] ingressAnalyzer
  • [x] statefulSetAnalyzer
  • [x] deploymentAnalyzer
  • [x] jobAnalyzer
  • [x] cronJobAnalyzer
  • [x] nodeAnalyzer
  • [x] mutatingWebhookAnalyzer
  • [x] validatingWebhookAnalyzer
  • [x] configMapAnalyzer

Optional

  • [x] hpaAnalyzer
  • [x] pdbAnalyzer
  • [x] networkPolicyAnalyzer
  • [x] gatewayClass
  • [x] gateway
  • [x] httproute
  • [x] logAnalyzer
  • [x] storageAnalyzer
  • [x] securityAnalyzer
  • [x] CatalogSource
  • [x] ClusterCatalog
  • [x] ClusterExtension
  • [x] ClusterService
  • [x] ClusterServiceVersion
  • [x] OperatorGroup
  • [x] InstallPlan
  • [x] Subscription

Examples

Run a scan with the default analyzers

k8sgpt generate
k8sgpt auth add
k8sgpt analyze --explain
k8sgpt analyze --explain --with-doc

Filter on resource

k8sgpt analyze --explain --filter=Service

Filter by namespace

k8sgpt analyze --explain --filter=Pod --namespace=default

Output to JSON

k8sgpt analyze --explain --filter=Service --output=json

Anonymize during explain

k8sgpt analyze --explain --filter=Service --output=json --anonymize

Using filters

List filters

k8sgpt filters list

Add default filters

k8sgpt filters add [filter(s)]

Examples :

  • Simple filter : k8sgpt filters add Service
  • Multiple filters : k8sgpt filters add Ingress,Pod

Remove default filters

k8sgpt filters remove [filter(s)]

Examples :

  • Simple filter : k8sgpt filters remove Service
  • Multiple filters : k8sgpt filters remove Ingress,Pod

Additional commands

List configured backends

k8sgpt auth list

Update configured backends

k8sgpt auth update $MY_BACKEND1,$MY_BACKEND2..

Remove configured backends

k8sgpt auth remove -b $MY_BACKEND1,$MY_BACKEND2..

List integrations

k8sgpt integrations list

Activate integrations

k8sgpt integrations activate [integration(s)]

Use integration

k8sgpt analyze --filter=[integration(s)]

Deactivate integrations

k8sgpt integrations deactivate [integration(s)]

Serve mode

k8sgpt serve

Serve mode with MCP (Model Context Protocol)

# Enable MCP server on default port 8089
k8sgpt serve --mcp --mcp-http

# Enable MCP server on custom port
k8sgpt serve --mcp --mcp-http --mcp-port 8089

# Full serve mode with MCP
k8sgpt serve --mcp --mcp-http --port 8080 --metrics-port 8081 --mcp-port 8089

The MCP server enables integration with tools like Claude Desktop and other MCP-compatible clients. It runs on port 8089 by default and provides: - Kubernetes cluster analysis via MCP protocol - Resource information and health status - AI-powered issue explanations and recommendations

For Helm chart deployment with MCP support, see the charts/k8sgpt/values-mcp-example.yaml file.

Analysis with serve mode

grpcurl -plaintext -d '{"namespace": "k8sgpt", "explain" : "true"}' localhost:8080 schema.v1.ServerAnalyzerService/Analyze
{
  "status": "OK"
}

Analysis with custom headers

k8sgpt analyze --explain --custom-headers CustomHeaderKey:CustomHeaderValue

Print analysis stats

k8sgpt analyze -s
The stats mode allows for debugging and understanding the time taken by an analysis by displaying the statistics of each analyzer.
- Analyzer Ingress took 47.125583ms
- Analyzer PersistentVolumeClaim took 53.009167ms
- Analyzer CronJob took 57.517792ms
- Analyzer Deployment took 156.6205ms
- Analyzer Node took 160.109833ms
- Analyzer ReplicaSet took 245.938333ms
- Analyzer StatefulSet took 448.0455ms
- Analyzer Pod took 5.662594708s
- Analyzer Service took 38.583359166s

Diagnostic information

To collect diagnostic information use the following command to create a dump_<timestamp>_json in your local directory.

k8sgpt dump

LLM AI Backends

K8sGPT uses the chosen LLM, generative AI provider when you want to explain the analysis results using --explain flag e.g. k8sgpt analyze --explain. You can use --backend flag to specify a configured provider (it's openai by default).

You can list available providers using k8sgpt auth list:

Default:
> openai
Active:
Unused:
> openai
> localai
> ollama
> azureopenai
> cohere
> amazonbedrock
> amazonsagemaker
> google
> huggingface
> noopai
> googlevertexai
> watsonxai
> customrest
> ibmwatsonxai

For detailed documentation on how to configure and use each provider see here.

To set a new default provider

k8sgpt auth default -p azureopenai
Default provider set to azureopenai

Using Amazon Bedrock Converse with inference profiles

System Inference Profile

k8sgpt auth add --backend amazonbedrockconverse --providerRegion us-east-1 --model arn:aws:bedrock:us-east-1:123456789012:inference-profile/my-inference-profile

Application Inference Profile

k8sgpt auth add --backend amazonbedrockconverse --providerRegion us-east-1 --model arn:aws:bedrock:us-east-1:123456789012:application-inference-profile/2uzp4s0w39t6

Using Amazon Bedrock with inference profiles

System Inference Profile

k8sgpt auth add --backend amazonbedrock --providerRegion us-east-1 --model arn:aws:bedrock:us-east-1:123456789012:inference-profile/my-inference-profile

Application Inference Profile

``` k8sgpt auth add --backend amazonbedrock --providerRegion us-east-1 --model arn:aws:bedrock:us-east-1:123456789012:application-inference-profile/2uzp4s0

Extension points exported contracts — how you extend this code

PodInfo (Interface)
(no doc) [8 implementers]
pkg/integration/keda/scaledobject_analyzer.go
PodInfo (Interface)
(no doc) [8 implementers]
pkg/analyzer/hpa.go
IResponse (Interface)
(no doc) [6 implementers]
pkg/ai/bedrock_support/responses.go
IAnalyzer (Interface)
(no doc) [36 implementers]
pkg/common/types.go
ICache (Interface)
(no doc) [5 implementers]
pkg/cache/cache.go
IIntegration (Interface)
(no doc) [4 implementers]
pkg/integration/integration.go
NResponse (Interface)
(no doc) [6 implementers]
pkg/ai/bedrock_support/responses.go
ICompletion (Interface)
(no doc) [22 implementers]
pkg/ai/bedrock_support/completions.go

Core symbols most depended-on inside this repo

Errorf
called by 114
pkg/server/mcp.go
MaskString
called by 80
pkg/util/util.go
Get
called by 78
pkg/integration/integration.go
List
called by 72
pkg/cache/cache.go
GetClient
called by 60
pkg/kubernetes/kubernetes.go
Run
called by 50
pkg/custom/client.go
Close
called by 45
pkg/ai/iai.go
GetApiDocV2
called by 29
pkg/kubernetes/apireference.go

Shape

Method 398
Function 360
Struct 177
Interface 15
TypeAlias 9
FuncType 2

Languages

Go100%

Modules by API surface

pkg/ai/iai.go48 symbols
pkg/common/types.go32 symbols
pkg/ai/azureopenai_test.go31 symbols
pkg/server/mcp.go24 symbols
pkg/ai/anthropic_test.go23 symbols
pkg/ai/bedrock_support/responses.go22 symbols
pkg/ai/openai_header_transport_test.go20 symbols
pkg/analysis/analysis_test.go17 symbols
pkg/util/util.go16 symbols
pkg/integration/integration.go16 symbols
pkg/cache/cache.go16 symbols
pkg/analyzer/hpa_test.go16 symbols

Dependencies from manifests, versioned

atomicgo.dev/cursorv0.2.0 · 1×
buf.build/gen/go/interplex-ai/schemas/grpc/gov1.5.1-2024111720325 · 1×
buf.build/gen/go/interplex-ai/schemas/protocolbuffers/gov1.35.2-202411172032 · 1×
buf.build/gen/go/k8sgpt-ai/k8sgpt/grpc/gov1.5.1-2024111815262 · 1×
buf.build/gen/go/k8sgpt-ai/k8sgpt/protocolbuffers/gov1.35.2-202411181526 · 1×
cel.dev/exprv0.25.1 · 1×
cloud.google.com/gov0.120.0 · 1×
cloud.google.com/go/aiv0.8.0 · 1×
cloud.google.com/go/aiplatformv1.85.0 · 1×

For agents

$ claude mcp add k8sgpt \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact