A Slack bot for Kubernetes troubleshooting with HolmesGPT and GitHub repository integration. This bot helps teams quickly identify and diagnose Kubernetes issues by combining real-time cluster monitoring with repository context analysis.
- π Pod Troubleshooting: Analyze failed pods with AI-powered insights
- π Cluster Monitoring: Get real-time status of your Kubernetes cluster
- π Flux Integration: Monitor GitOps workflows and identify sync issues
- π€ HolmesGPT Integration: AI-powered analysis and recommendations
- οΏ½ GitHub Repository Integration: Cross-reference issues with your Flux/GitOps repository
- οΏ½π¬ Interactive Slack Interface: Easy-to-use commands and buttons
- π Log Analysis: Automated log collection and analysis
- π Context-Aware Troubleshooting: Leverage repository configuration and history
Before installation, please read SECURITY.md for important information about protecting your API keys and credentials.
- Node.js 16+
- Access to a Kubernetes cluster
- Slack app with bot permissions
- HolmesGPT instance (optional - fallback analysis available)
- GitHub repository with Flux/GitOps configurations (optional)
- GitHub Personal Access Token (for repository integration)
-
Clone and install dependencies:
git clone <repository-url> cd k8s-bot npm install
-
Set up environment variables:
cp .env.example .env # Edit .env with your configuration -
Configure your Slack app:
- Create a new Slack app at https://api.slack.com/apps
- Enable Socket Mode
- Add bot scopes:
app_mentions:read,channels:read,chat:write,commands,im:read,im:write - Install the app to your workspace
- Copy the tokens to your
.envfile
-
Set up Kubernetes access:
- Ensure your
kubeconfigis properly configured - The bot uses the default kubeconfig location or the path specified in
KUBECONFIG_PATH
- Ensure your
-
Configure GitHub Integration (Optional):
./setup-github-integration.sh
Or see the detailed guide: GITHUB_INTEGRATION.md
| Variable | Description | Required |
|---|---|---|
SLACK_BOT_TOKEN |
Bot User OAuth Token from Slack | Yes |
SLACK_SIGNING_SECRET |
Signing Secret from Slack | Yes |
SLACK_APP_TOKEN |
App-Level Token for Socket Mode | Yes |
HOLMESGPT_API_URL |
HolmesGPT API endpoint | No |
HOLMESGPT_API_KEY |
HolmesGPT API key | No |
KUBECONFIG_PATH |
Path to kubeconfig file | No |
K8S_NAMESPACE |
Default namespace | No |
PORT |
Server port | No |
GIT_REPO |
GitHub repository (owner/repo) for integration | No |
GIT_CREDENTIALS |
GitHub Personal Access Token | No |
GIT_BRANCH |
GitHub branch to analyze | No |
-
Create a new Slack app:
- Go to https://api.slack.com/apps
- Click "Create New App" β "From scratch"
- Name your app and select your workspace
-
Configure Socket Mode:
- Go to "Socket Mode" in the sidebar
- Enable Socket Mode
- Generate an App-Level Token with
connections:writescope
-
Set up Bot User:
- Go to "OAuth & Permissions"
- Add these Bot Token Scopes:
app_mentions:readchannels:readchat:writecommandsim:readim:write
- Install the app to your workspace
-
Create Slash Commands:
- Go to "Slash Commands"
- Create these commands:
/k8s-pods- List pods in namespace/k8s-debug- Debug specific pod/k8s-flux- Check Flux resources/k8s-help- Show help
-
Configure Event Subscriptions:
- Go to "Event Subscriptions"
- Subscribe to these bot events:
app_mentionmessage.im
# List pods in default namespace
/k8s-pods
# List pods in specific namespace
/k8s-pods production
# Debug a specific pod
/k8s-debug my-app-pod production
# Check Flux resources
/k8s-flux
# Get help
/k8s-help# Find failed pods across all namespaces
@k8s-bot failed pods
# Check Flux status
@k8s-bot flux issues
# Ask general questions
@k8s-bot why is my pod crashing?
# Get help
@k8s-bot helpSend a direct message to the bot for private troubleshooting sessions.
The bot integrates with HolmesGPT for advanced AI-powered analysis. If HolmesGPT is not available, the bot provides fallback analysis based on:
- Pod status and conditions
- Container restart counts
- Kubernetes events
- Resource requirements
- Common failure patterns
- Deploy HolmesGPT in your cluster or as a standalone service
- Configure the
HOLMESGPT_API_URLin your environment - If authentication is required, set
HOLMESGPT_API_KEY
The bot can integrate with your Flux/GitOps repository to provide enhanced troubleshooting context.
- Configuration Analysis: Cross-references cluster issues with repository manifests
- Change History: Analyzes recent commits that might affect deployments
- Best Practices: Suggests fixes based on repository patterns
- Pull Request Management: Can create PRs for fixes (future feature)
# Run the setup script
./setup-github-integration.sh-
Create GitHub Personal Access Token:
- Go to GitHub Settings > Developer settings > Personal access tokens
- Create token with appropriate scopes
-
Configure HolmesGPT:
# Edit ~/.holmes/config.yaml toolsets: git: enabled: true config: git_repo: "your-org/your-flux-repo" git_credentials: "your-github-token" git_branch: "main"
-
Refresh Toolsets:
holmes toolset refresh
For detailed setup instructions, see GITHUB_INTEGRATION.md
When GitHub integration is active:
/k8s-debugincludes repository analysis- General questions automatically use repo context for deployment-related issues
- Bot provides richer context by referencing your actual configurations
# Development mode with auto-reload
npm run dev
# Production mode
npm startsrc/
βββ app.js # Main application entry point
βββ services/
β βββ kubernetes.js # Kubernetes API interactions
β βββ holmesgpt.js # HolmesGPT API integration
βββ handlers/
βββ slack.js # Slack event handlers
- New Kubernetes Resources: Extend
KubernetesServiceclass - New Slack Commands: Add handlers in
SlackHandlersclass - New Analysis Types: Extend
HolmesGPTServiceclass
-
Bot not responding:
- Check Slack tokens in
.env - Verify Socket Mode is enabled
- Check bot permissions
- Check Slack tokens in
-
Kubernetes connection failed:
- Verify kubeconfig path
- Check cluster connectivity
- Ensure proper RBAC permissions
-
HolmesGPT integration issues:
- Check API URL and connectivity
- Verify API key if required
- Bot works with fallback analysis if HolmesGPT is unavailable
The bot provides detailed logging for troubleshooting:
# View logs in development
npm run dev
# Production logs
npm start- Store sensitive tokens in environment variables
- Use Kubernetes RBAC to limit bot permissions
- Consider network policies for HolmesGPT communication
- Regularly rotate API keys and tokens
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
MIT License - see LICENSE file for details
For issues and questions:
- Create an issue in the repository
- Check the troubleshooting section
- Review Slack API documentation