This guide provides detailed instructions for configuring K8sMed with various AI providers, including step-by-step examples for using Gemma and other open-source models.
OpenAI’s GPT models provide high-quality analysis capabilities for Kubernetes troubleshooting.
export OPENAI_API_KEY="your-api-key-here"
export K8SMED_AI_PROVIDER="openai"
export K8SMED_AI_MODEL="gpt-4" # or gpt-3.5-turbo
kubectl-k8smed analyze "why is my pod in CrashLoopBackOff" --explain
LocalAI is an API-compatible alternative to OpenAI that can run open-source models locally.
export K8SMED_AI_PROVIDER="localai"
export K8SMED_AI_ENDPOINT="http://localhost:8080/v1" # Adjust port as needed
export K8SMED_AI_MODEL="your-model-name" # As configured in LocalAI
kubectl-k8smed analyze pod mypod --explain
Gemma is Google’s lightweight open-source model that can be used with K8sMed through LocalAI or similar providers.
# Using Ollama
ollama pull gemma:3b
export K8SMED_AI_PROVIDER="localai"
export K8SMED_AI_ENDPOINT="http://localhost:11434/api/chat" # Ollama endpoint
export K8SMED_AI_MODEL="gemma:3b" # Model name as configured
To use a locally hosted Gemma model with K8sMed deployed in Kubernetes:
ngrok http 11434 # Port depends on your implementation
apiVersion: v1
data:
ai_endpoint: "https://your-ngrok-url.ngrok-free.app/v1/chat/completions" # Note the full path
ai_model: "gemma-3-4b-it" # Exact model name is implementation-specific
ai_provider: "localai"
kind: ConfigMap
metadata:
name: k8smed-config
namespace: k8smed-system
kubectl apply -f deploy/manifests/
K8SMED_POD=$(kubectl get pods -n k8smed-system -o jsonpath='{.items[0].metadata.name}')
kubectl exec -it -n k8smed-system $K8SMED_POD -- kubectl-k8smed analyze "pod test-pod has ImagePullBackOff"
K8sMed can work with various open-source models as long as they’re exposed through an OpenAI-compatible API.
# Using Ollama with Llama 2 (7B)
export K8SMED_AI_PROVIDER="localai"
export K8SMED_AI_ENDPOINT="http://localhost:11434/api/chat"
export K8SMED_AI_MODEL="llama2"
# Using Ollama with Mistral
export K8SMED_AI_PROVIDER="localai"
export K8SMED_AI_ENDPOINT="http://localhost:11434/api/chat"
export K8SMED_AI_MODEL="mistral"
When using K8sMed in Kubernetes with locally hosted models, you have several options:
Pros:
Cons:
apiVersion: v1
data:
ai_endpoint: "http://localai-service.ai-namespace.svc.cluster.local/v1/chat/completions"
ai_model: "gemma-3-4b-it"
ai_provider: "localai"
kind: ConfigMap
metadata:
name: k8smed-config
namespace: k8smed-system
Pros:
Cons:
For development/testing purposes:
kubectl port-forward -n k8smed-system deployment/k8smed 8080:8080
Different models offer different performance characteristics:
| Model | Size | Analysis Quality | Speed | Resource Requirements |
|---|---|---|---|---|
| GPT-4 | Large | Excellent | Moderate | API-only (cloud) |
| GPT-3.5-Turbo | Medium | Very Good | Fast | API-only (cloud) |
| Gemma-3-4B-IT | Small | Good for common issues | Fast | 4-8GB RAM |
| Llama-2-7B | Medium | Good | Moderate | 8-16GB RAM |
| Mistral-7B | Medium | Good | Moderate | 8-16GB RAM |
--explain flag to get more context for the model