New: K8sGPT works with Claude Desktop!

Back to Documentation

Integration

Learn how to integrate K8sGPT with other tools and systems

Overview

K8sGPT is designed to integrate seamlessly with your existing Kubernetes ecosystem and tools. This page covers various integration options to help you incorporate K8sGPT into your workflows.

CNCF Project: K8sGPT is an open source project hosted by the Cloud Native Computing Foundation (CNCF). It was accepted to CNCF at the Sandbox maturity level on December 19, 2023. Learn more at CNCF K8sGPT project page.

CI/CD Integration

Integrate K8sGPT into your CI/CD pipelines to catch issues before they reach production:

GitHub Actions

name: K8sGPT Analysis
on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  analyze:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Install K8sGPT
        run: |
          curl -sSfL https://raw.githubusercontent.com/k8sgpt-ai/k8sgpt/main/install.sh | sh
      - name: Run Analysis
        run: |
          k8sgpt analyze --namespace=default
        env:
          K8SGPT_OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
          KUBECONFIG: ${{ secrets.KUBECONFIG }}

GitLab CI

analyze:
  image: ubuntu:latest
  before_script:
    - apt-get update && apt-get install -y curl
    - curl -sSfL https://raw.githubusercontent.com/k8sgpt-ai/k8sgpt/main/install.sh | sh
  script:
    - k8sgpt analyze --namespace=default
  environment:
    name: production
  variables:
    K8SGPT_OPENAI_API_KEY: "$OPENAI_API_KEY"
    KUBECONFIG: "$KUBECONFIG"

Monitoring Integration

Connect K8sGPT with your monitoring stack:

Prometheus

apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: k8sgpt
  labels:
    release: prometheus
spec:
  selector:
    matchLabels:
      app.kubernetes.io/name: k8sgpt
  endpoints:
  - port: metrics
    interval: 30s

Grafana Dashboard

Import the K8sGPT dashboard into Grafana:

# Dashboard ID: 12345
# Available at: https://grafana.com/grafana/dashboards/12345

Notification Systems

Send K8sGPT analysis results to various notification systems:

Slack

apiVersion: v1
kind: Secret
metadata:
  name: k8sgpt-slack-secret
type: Opaque
stringData:
  SLACK_TOKEN: "xoxb-your-token"
  SLACK_CHANNEL: "#kubernetes-alerts"

Email

apiVersion: v1
kind: ConfigMap
metadata:
  name: k8sgpt-email-config
data:
  SMTP_SERVER: "smtp.example.com"
  SMTP_PORT: "587"
  FROM_EMAIL: "k8sgpt@example.com"
  TO_EMAIL: "team@example.com"

Webhooks

apiVersion: v1
kind: ConfigMap
metadata:
  name: k8sgpt-webhook-config
data:
  WEBHOOK_URL: "https://api.example.com/webhook"
  WEBHOOK_METHOD: "POST"
  WEBHOOK_HEADERS: '{"Content-Type": "application/json"}'

Service Mesh Integration

Integrate K8sGPT with service mesh solutions:

Istio

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: k8sgpt
spec:
  hosts:
  - k8sgpt
  http:
  - route:
    - destination:
        host: k8sgpt
        port:
          number: 8080

Linkerd

apiVersion: linkerd.io/v1alpha2
kind: ServiceProfile
metadata:
  name: k8sgpt
  namespace: default
spec:
  routes:
  - name: k8sgpt-api
    condition:
      pathRegex: "/api/.*"
    isRetryable: true
    timeout: 5000ms

Logging Integration

Connect K8sGPT with your logging infrastructure:

Elasticsearch

apiVersion: v1
kind: ConfigMap
metadata:
  name: k8sgpt-elasticsearch-config
data:
  ELASTICSEARCH_URL: "http://elasticsearch:9200"
  ELASTICSEARCH_INDEX: "k8sgpt-analysis"

Fluentd

<match k8sgpt.**>
  @type elasticsearch
  host elasticsearch
  port 9200
  logstash_format true
  logstash_prefix k8sgpt
  <buffer>
    @type memory
    flush_interval 5s
  </buffer>
</match>

Custom Integrations

Create custom integrations using K8sGPT's API:

REST API

# Start the API server
k8sgpt serve --port=8080

# Example API call
curl -X POST http://localhost:8080/api/analyze \
  -H "Content-Type: application/json" \
  -d '{"namespace": "default", "analyzers": ["pod"]}'

Webhook Integration

apiVersion: v1
kind: ConfigMap
metadata:
  name: k8sgpt-webhook-config
data:
  WEBHOOK_URL: "https://your-service.com/webhook"
  WEBHOOK_SECRET: "your-secret"
  WEBHOOK_EVENTS: "analysis.completed,issue.detected"

Best Practices

  • Use appropriate authentication for all integrations
  • Implement rate limiting to prevent overloading
  • Set up proper error handling and retries
  • Monitor integration performance
  • Keep integration configurations in version control
  • Regularly test integrations to ensure they work