Symptoms:
Solutions:
# Verify kubeconfig exists and is readable
ls -la $KUBECONFIG
# or
ls -la ~/.kube/config
# Test with kubectl first
kubectl get namespaces
# If kubectl works, check the context
kubectl config current-context
# Explicitly set kubeconfig path
export KUBECONFIG=/path/to/your/kubeconfig
# Set context if needed
export KUBE_CONTEXT=your-context-name
# Start the server
go run ./cmd/api
# Verify you have permissions to list namespaces
kubectl auth can-i list namespaces
# Check RBAC permissions
kubectl get clusterrolebinding | grep your-user
# List all contexts
kubectl config get-contexts
# Verify your context is in the list
kubectl config view
kubectl config view --raw > /tmp/test-config.yaml
# Check if file is valid YAML
kubectl config get-contexts
# Use the exact context name from the output
kubectl get namespaces# Look for "Warning: Failed to initialize Kubernetes client" in logs
# Check server startup logs
go run ./cmd/api 2>&1 | tee server.log
curl http://localhost:8080/api/v1/health
# Should show kubernetes status
curl http://localhost:8080/api/v1/namespaces
# Check error message for details
# Check if kubeconfig is valid
kubectl --kubeconfig=$KUBECONFIG config view
Make sure these are set correctly:
# Required for Kubernetes access
export KUBECONFIG=/path/to/kubeconfig
# Optional: specify context
export KUBE_CONTEXT=my-context
# Optional: Ollama for AI-powered explanations
export OLLAMA_URL=http://localhost:11434
export OLLAMA_MODEL=granite4:latest
# Optional: API server port
export PORT=8080
If running inside Kubernetes (as a pod):
KUBECONFIG - it will use in-cluster config automaticallyKUBE_CONTEXT - contexts don’t apply in-cluster# Test the Kubernetes client directly
go run -tags debug ./cmd/api
# Or test via API
curl http://localhost:8080/api/v1/health
# Check the "kubernetes" field in response
Symptoms:
Solutions:
# Check if AWS credentials are configured
aws sts get-caller-identity
pricing:GetProducts permissionSymptoms:
Solutions:
curl http://localhost:11434/api/tags
# Should return list of available models
# Set correct Ollama URL
export OLLAMA_URL=http://localhost:11434
# Or if running in cluster
export OLLAMA_URL=http://ollama-service:11434
# List available models
curl http://localhost:11434/api/tags
# Pull model if needed
curl http://localhost:11434/api/pull -d '{"name": "gemma2:2b"}'
The server logs initialization status:
Starting Karpenter Optimizer API
Port: 8080
Kubeconfig: /path/to/kubeconfig
Kube Context: my-context
Successfully connected to Kubernetes cluster
Or if there’s an error:
Warning: Failed to initialize Kubernetes client: <error details>
Kubernetes features will be disabled.
curl http://localhost:8080/api/v1/health
Response shows connection status:
{
"status": "healthy",
"service": "karpenter-optimizer",
"kubernetes": "connected", // or "not configured"
"prometheus": "not supported" // Prometheus support removed - uses Kubernetes API directly
}
Note: Prometheus is no longer used. The tool analyzes Kubernetes resource requests and node usage data directly from the Kubernetes API. This provides more accurate recommendations based on actual pod resource allocations.
The tool uses a Kubernetes-native approach that doesn’t require Prometheus:
Symptoms:
Solutions:
# Check if pods have resource requests set
kubectl get pods -A -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.spec.containers[*].resources.requests}{"\n"}{end}'
# Verify nodes have allocatable resources
kubectl get nodes -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.status.allocatable.cpu}{"\t"}{.status.allocatable.memory}{"\n"}{end}'
# Only scheduled pods (with nodeName) are counted
kubectl get pods -A -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.spec.nodeName}{"\n"}{end}' | grep -v "^$"
# Verify NodePools exist and have nodes
kubectl get nodepools
kubectl get nodes -l karpenter.sh/nodepool
Symptoms:
Solutions:
# Check if NodePools are configured
kubectl get nodepools
# Verify nodes have NodePool labels
kubectl get nodes --show-labels | grep karpenter.sh/nodepool
# Test NodePool endpoint directly
curl http://localhost:8080/api/v1/nodepools
Symptoms:
Solutions:
# Check actual instance types in cluster
kubectl get nodes -o jsonpath='{range .items[*]}{.metadata.labels.node\.kubernetes\.io/instance-type}{"\n"}{end}' | sort -u
# Verify spot vs on-demand nodes
kubectl get nodes -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.metadata.labels.karpenter\.sh/capacity-type}{"\n"}{end}'