New: K8sGPT Auto Remediation!

Back to Documentation

Operator Reference

Comprehensive reference for K8sGPT's Kubernetes operator

Overview

The K8sGPT operator is a Kubernetes controller that manages K8sGPT deployments in your cluster. It provides a declarative way to configure and run K8sGPT, making it easier to integrate with your Kubernetes workflows.

Installation

Install the K8sGPT operator using Helm:

# Add the K8sGPT Helm repository
helm repo add k8sgpt https://charts.k8sgpt.ai
helm repo update

# Install the operator
helm install k8sgpt-operator k8sgpt/k8sgpt-operator --namespace k8sgpt --create-namespace

Custom Resources

K8sGPT

The main custom resource that defines a K8sGPT deployment:

apiVersion: k8sgpt.ai/v1alpha1
kind: K8sGPT
metadata:
  name: k8sgpt
  namespace: k8sgpt
spec:
  ai:
    provider: openai
    model: gpt-3.5-turbo
    temperature: 0.7
    maxTokens: 150
  filters:
    namespace: default
    severity: warning
  analyzers:
    - name: pod
    - name: deployment
  schedule: "*/5 * * * *"  # Run every 5 minutes
  secretRef:
    name: k8sgpt-secret

Secret

Store sensitive information like API keys:

apiVersion: v1
kind: Secret
metadata:
  name: k8sgpt-secret
  namespace: k8sgpt
type: Opaque
stringData:
  OPENAI_API_KEY: "sk-..."

Configuration Options

AI Configuration

  • provider - AI provider (openai, azure, etc.)
  • model - Model to use
  • temperature - Response creativity (0.0-1.0)
  • maxTokens - Maximum response length

Filters

  • namespace - Target namespace
  • severity - Minimum severity level
  • excludeNamespaces - Namespaces to ignore

Analyzers

  • name - Analyzer name
  • enabled - Whether the analyzer is active
  • config - Analyzer-specific configuration

Scheduling

The operator supports cron-style scheduling for periodic analysis:

# Run every hour
schedule: "0 * * * *"

# Run every day at midnight
schedule: "0 0 * * *"

# Run every 15 minutes
schedule: "*/15 * * * *"

Status and Events

The operator provides status information and events:

kubectl describe k8sgpt k8sgpt -n k8sgpt

# View operator logs
kubectl logs -n k8sgpt -l app.kubernetes.io/name=k8sgpt-operator

Integration with Other Tools

The operator can integrate with various tools:

  • Prometheus for metrics
  • Grafana for dashboards
  • Slack for notifications
  • Custom webhooks
  • Service mesh integration

Troubleshooting

Common issues and solutions:

  • Check operator logs for errors
  • Verify secret configuration
  • Ensure proper RBAC permissions
  • Check network connectivity
  • Verify cron schedule format