Sponsored by Deepsite.site

Kubernetes AI Ops Agent

Created By
jhzhu899 months ago
AI-powered assistant that enables natural language interactions with Kubernetes clusters. Simplifies DevOps workflows using Model Context Protocol (MCP) servers for executing K8s operations through conversational interfaces.
Content

Kubernetes AI Ops Agent

An AI-powered assistant for Kubernetes operations and management through natural language interactions.

Overview

Kubernetes AI Ops Agent is an intelligent agent that helps DevOps engineers and Kubernetes administrators manage Kubernetes clusters through conversational interfaces. The project leverages Large Language Models (LLMs) to interpret user intents and execute Kubernetes operations using specialized MCP (Model Context Protocol) servers.

Kubernetes AI Ops Agent Demo

Project Status

Note: This project is currently in an experimental stage. It serves primarily as a proof of concept to validate the capabilities and potential benefits of integrating Large Language Models (LLMs) with Kubernetes, Prometheus, and other MCP (Model Context Protocol) servers. Features and functionality may change significantly as the project evolves.

Features

  • 🤖 AI-Powered Assistance: Interact with your Kubernetes clusters using natural language
  • 🧰 Tool Integration: Execute Kubernetes operations through specialized tools
  • 🚀 Deployment Ready: Packaged with Docker and Helm charts for easy deployment
  • 📊 Web Interface: Built with Chainlit for an interactive chat experience

Prerequisites

  • Python 3.10+
  • Docker
  • Kubernetes cluster access
  • Helm (for deployment)

Installation

Local Development

  1. Clone the repository:

    git clone https://github.com/yourusername/kubernetes-ai-ops-agent.git
    cd kubernetes-ai-ops-agent
    
  2. Install the dependencies:

    pip install -r requirements.txt
    
  3. Install the required MCP servers:

    # Install the Kubernetes MCP server
    npm install -g @kubernetes-ai/mcp-server-kubernetes
    
    # Install the Prometheus MCP server
    pip install prometheus-mcp-server
    

    Note: Do not use the MCP servers located in the deps/ directory for local development. These are customized versions:

    • The Kubernetes MCP server in deps/ is modified to use loadFromCluster for proper initialization in a Pod environment.
    • The MCP servers in deps/ are included to be packaged directly into the container image rather than downloaded at runtime.
  4. Configure your Kubernetes access:

    • Ensure your kubeconfig is properly set up
    • The agent will use your current kubectl context
  5. Start the application:

    chainlit run src/main.py
    

Helm Chart Deployment

  1. Build and push the Docker image:
# Build the Docker image
docker build -t <YOUR_CONTAINER_REGISTRY>/kubernetes-ai-ops-agent:<TAG> .

# Push the image to your container registry
docker push <YOUR_CONTAINER_REGISTRY>/kubernetes-ai-ops-agent:<TAG>
  1. Create a customized.values.yaml file with your specific configuration:
# Customized values for kubernetes-ai-ops-agent
image:
  repository: <YOUR_CONTAINER_REGISTRY>/kubernetes-ai-ops-agent

# Configure the secrets
secrets:
  data:
    # Option 1: For Azure OpenAI configuration
    AZURE_OPENAI_ENDPOINT: "https://<YOUR_OPENAI_SERVICE>.openai.azure.com/"
    AZURE_OPENAI_API_KEY: "<YOUR_AZURE_OPENAI_API_KEY>"
    AZURE_OPENAI_MODEL: "<YOUR_DEPLOYMENT_NAME>"
    OPENAI_API_VERSION: "<API_VERSION>"
    
    # Option 2: For standard OpenAI configuration
    # OPENAI_API_KEY: "<YOUR_OPENAI_API_KEY>"
    # OPENAI_MODEL: "<YOUR_MODEL_NAME>" # e.g., "gpt-4o"
    
    # Prometheus configuration
    PROMETHEUS_URL: "http://<YOUR_PROMETHEUS_SERVICE>.<NAMESPACE>:9090"
  1. Install the chart using your customized values:
cd deploy/helm
helm install kubernetes-ai-ops ./kubernetes-ai-ops-agent -f customized.values.yaml
  1. Access the application using port-forward:
# Port-forward the service to access it locally
# Use the namespace where you installed the chart (default used here as example)
kubectl port-forward svc/kubernetes-ai-ops-agent 9000:9000 -n <NAMESPACE>

# Now you can access the web interface at http://localhost:9000

Note: Replace <NAMESPACE> with the namespace where you installed the Helm chart. If you installed without specifying a namespace (-n flag), the current context's namespace will be used (usually "default").

Architecture

The application is built with the following components:

  • Chainlit Interface: Web UI for interacting with the AI assistant
  • Agent Layer: Processes natural language, plans operations, and executes them
  • MCP Servers:
    • Kubernetes MCP Server: Handles Kubernetes API operations
    • Prometheus MCP Server: Provides monitoring metrics and data

Model Support

This project currently supports only OpenAI models. You can configure the agent to use either:

  • OpenAI API directly
  • Azure OpenAI API

Configuration details for both options are provided in the deployment settings.

Usage Examples

Basic Cluster Information

User: "Show me all pods in the default namespace"

Troubleshooting

User: "Why is my pod in CrashLoopBackOff state?"

Project Structure

  • src/: Main application code
    • main.py: Main entry point for the Chainlit application
    • chainlit_session_manager.py: Manages Chainlit user sessions
    • chainlit_session_storage.py: Handles session data storage
    • interfaces.py: Defines interfaces and abstractions
    • kubernetes_ai_ops_agent_provider.py: Provider implementation for Kubernetes operations
    • mcp_server_provider_impl.py: Implementation for MCP server provider
    • openai_client_factory_impl.py: Factory for OpenAI client configuration
  • deps/: Dependencies and MCP servers
    • mcp-server-kubernetes/: Kubernetes MCP server
    • prometheus-mcp-server/: Prometheus MCP server
  • deploy/: Deployment configurations
    • helm/: Helm charts for Kubernetes deployment

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
ChatWiseThe second fastest AI chatbot™
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.
WindsurfThe new purpose-built IDE to harness magic
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
Y GuiA web-based graphical interface for AI chat interactions with support for multiple AI models and MCP (Model Context Protocol) servers.
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
Playwright McpPlaywright MCP server
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
Amap Maps高德地图官方 MCP Server
Tavily Mcp
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题; Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"
DeepChatYour AI Partner on Desktop
CursorThe AI Code Editor
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Serper MCP ServerA Serper MCP Server