This guide provides detailed instructions for integrating Gemma with K8sMed, based on hands-on experience. It covers both local setup and Kubernetes deployment with ngrok.
Gemma is Google’s family of lightweight, state-of-the-art open models designed for various tasks, including troubleshooting and technical assistance. This guide demonstrates how to use Gemma with K8sMed for Kubernetes troubleshooting.
Download and configure the Gemma model:
# Using Ollama
ollama pull gemma:3b-instruct
Start your LocalAI server:
# For Ollama, it typically runs as a service
# For other implementations, follow their specific instructions
Verify the model is working:
# With Ollama
ollama run gemma:3b-instruct "What is Kubernetes?"
Set the required environment variables:
export K8SMED_AI_PROVIDER="localai"
export K8SMED_AI_MODEL="gemma:3b-instruct" # Match the model name in your LocalAI server
export K8SMED_AI_ENDPOINT="http://localhost:11434/api/chat" # Adjust based on your setup
Run a basic analysis:
kubectl-k8smed analyze "why would a pod have ImagePullBackOff status" --explain
Install ngrok if not already installed:
# macOS with Homebrew
brew install ngrok
# Linux
curl -s https://ngrok-agent.s3.amazonaws.com/ngrok.asc | \
sudo tee /etc/apt/trusted.gpg.d/ngrok.asc >/dev/null && \
echo "deb https://ngrok-agent.s3.amazonaws.com buster main" | \
sudo tee /etc/apt/sources.list.d/ngrok.list && \
sudo apt update && sudo apt install ngrok
Sign up for an ngrok account at ngrok.com if you don’t have one
Authenticate ngrok:
ngrok config add-authtoken YOUR_AUTH_TOKEN
Start ngrok and expose your LocalAI endpoint:
# For Ollama (default port 11434)
ngrok http 11434
Note the HTTPS URL provided by ngrok (e.g., https://abcd-123-456-789-10.ngrok-free.app)
Create a namespace for K8sMed if it doesn’t exist:
kubectl apply -f deploy/manifests/namespace.yaml
Create/update the ConfigMap:
cat > deploy/manifests/configmap.yaml << EOF
apiVersion: v1
data:
ai_endpoint: "https://your-ngrok-url.ngrok-free.app/v1/chat/completions"
ai_model: "gemma-3-4b-it"
ai_provider: "localai"
kind: ConfigMap
metadata:
name: k8smed-config
namespace: k8smed-system
EOF
Important: Make sure to include the full path to the chat completions endpoint (
/v1/chat/completions). The exact model name may vary based on your LocalAI implementation.
Create a placeholder Secret (even though LocalAI might not need an API key):
kubectl create secret generic k8smed-secrets \
--namespace=k8smed-system \
--from-literal=openai_api_key=placeholder \
--dry-run=client -o yaml > deploy/manifests/secret.yaml
kubectl apply -f deploy/manifests/secret.yaml
Apply RBAC configurations:
kubectl apply -f deploy/manifests/rbac.yaml
Deploy K8sMed:
kubectl apply -f deploy/manifests/deployment.yaml
Verify the pod is running:
kubectl get pods -n k8smed-system
Test K8sMed with Gemma:
# Get the pod name
K8SMED_POD=$(kubectl get pods -n k8smed-system -o jsonpath='{.items[0].metadata.name}')
# Run a test query
kubectl exec -it -n k8smed-system $K8SMED_POD -- kubectl-k8smed analyze "pod test-pod has ImagePullBackOff"
/v1/chat/completionsGemma performs best with:
--explain flag - Provides more context for the model to work withHere are some effective queries that work well with Gemma and K8sMed:
# Specific issue analysis
kubectl-k8smed analyze "pod mypod has ImagePullBackOff status" --explain
# General Kubernetes concepts
kubectl-k8smed analyze "explain how Kubernetes networking works with services and pods"
# Troubleshooting workflows
kubectl-k8smed analyze "how to debug a pod that won't start" --explain
Here’s a complete example of deploying and using K8sMed with Gemma, based on our testing:
ollama serve
ngrok http 11434
# Update ConfigMap with ngrok URL
kubectl apply -f deploy/manifests/namespace.yaml
kubectl apply -f deploy/manifests/configmap.yaml
kubectl apply -f deploy/manifests/secret.yaml
kubectl apply -f deploy/manifests/rbac.yaml
kubectl apply -f deploy/manifests/deployment.yaml
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-error-pod has ImagePullBackOff"