Custom Analyzers
Learn how to create and use custom analyzers with K8sGPT
Overview
Custom analyzers allow you to extend K8sGPT's capabilities by creating your own analysis rules and checks. This enables you to add domain-specific knowledge and custom validation logic to your Kubernetes cluster analysis.
Creating a Custom Analyzer
Custom analyzers are written in Go and follow a simple interface. Here's a basic example:
package analyzers
import (
"context"
"fmt"
"k8s.io/client-go/kubernetes"
)
type CustomAnalyzer struct {
client *kubernetes.Clientset
}
func (a *CustomAnalyzer) Analyze(ctx context.Context) ([]Analysis, error) {
// Your analysis logic here
return []Analysis{
{
Name: "custom-check",
Message: "Custom analysis result",
Severity: "warning",
},
}, nil
}
Analyzer Interface
Every custom analyzer must implement the following interface:
Analyze(ctx context.Context) ([]Analysis, error)
Name() string
Description() string
Configuration
To use your custom analyzer:
- Build your analyzer as a Go plugin
- Place the plugin in the analyzers directory
- Configure K8sGPT to load your analyzer
- Enable the analyzer in your analysis configuration
Best Practices
- Keep analyzers focused and single-purpose
- Include clear documentation and examples
- Handle errors gracefully
- Use appropriate severity levels
- Test thoroughly before deploying
Example Use Cases
- Custom resource validation rules
- Organization-specific best practices
- Integration with internal tools
- Specialized security checks
- Performance optimization rules
Next Steps
After creating your custom analyzer:
- Test it in the playground
- Deploy it to your cluster
- Monitor its performance
- Share it with the community
PlaygroundSlack Integration