# Cluster Query Guide **Complete guide for using natural language to query your Kubernetes cluster with the DevOps AI Toolkit.** ## See It In Action [![Why Kubernetes Querying Is Broken and How I Fixed It](https://img.youtube.com/vi/uUdbQkq5c4k/maxresdefault.jpg)](https://youtu.be/uUdbQkq5c4k) > **Note**: The examples below use MCP, but this tool is also available via the [CLI](/docs/cli), [Web Dashboard](/docs/ui), and [Headlamp Plugin](/docs/headlamp). ## Prerequisites Before using this guide, complete the [Deployment Guide](../setup/deployment.md). **Optional but strongly recommended:** - Scanned capabilities - see [Capability Management](capability-management.md) - Resources synced to Vector DB - automatically handled by the [dot-ai-controller](/docs/controller) > **Note**: While the query tool technically works without capabilities and resources in the Vector DB (falling back to raw kubectl commands), AI performance and accuracy will be severely reduced. Capabilities provide semantic understanding (knowing that "database" relates to StatefulSet, CNPG, etc.), and resources provide fast inventory lookups. Without these, the AI loses its ability to answer concept-based queries and must rely solely on kubectl, resulting in slower and less intelligent responses. ## Related Projects **[dot-ai-controller](/docs/controller)** - A Kubernetes controller that automatically scans cluster capabilities and syncs resources to the Vector DB. This enables the query tool's semantic understanding and fast inventory lookups without manual setup. ## Overview The DevOps AI Toolkit query feature provides: - **Natural language cluster queries** - Ask questions about your cluster in plain English - **Semantic understanding** - Query by concept ("databases", "web servers") not just resource names - **Multi-source intelligence** - Combines Vector DB knowledge with live kubectl data - **AI-powered orchestration** - LLM decides which tools to use based on your intent - **Read-only operations** - Safe cluster exploration without risk of modifications - **MCP server integration** - Augment queries with tools from external MCP servers (e.g., Prometheus metrics). See [MCP Server Integration](../setup/deployment.md#mcp-server-integration) ### How AI-Driven Querying Works **Traditional Problem**: Finding cluster resources requires knowing kubectl syntax, label conventions, and resource types. **AI Query Solution**: Describe what you want to find in natural language, and AI orchestrates the right tools. **Query Flow**: 1. **Intent Analysis**: AI interprets your natural language query 2. **Tool Selection**: AI chooses appropriate tools (Vector DB search, kubectl commands) 3. **Data Gathering**: Tools execute and return results 4. **Response Synthesis**: AI summarizes findings in human-readable format ### Three Data Sources The query tool combines three data sources to answer your questions intelligently: | Source | What it provides | Example use | |--------|------------------|-------------| | **Capabilities** | Semantic understanding - knows that "database" relates to StatefulSet, CNPG Cluster, Crossplane RDS, etc. | "What databases are running?" | | **Resources** | Searchable inventory - find resources by name patterns, labels, or annotations without knowing kubectl syntax or exact resource locations | "Find all resources with label team=platform" | | **Kubernetes API** | Live cluster state - real-time status, events, logs, and detailed resource information via kubectl | "Describe the my-postgres cluster" | This combination enables natural language queries while providing accurate, live cluster data. ## Complete Workflow Examples > **Tip**: If your AI coding agent doesn't automatically use the query tool, add "use dot-ai" to your query (e.g., "What databases are running? Use dot-ai"). This section demonstrates common query patterns: - **[Semantic Queries](#semantic-queries)** - Find resources by concept - **[Direct Queries](#direct-queries)** - Ask about specific resources or namespaces - **[Status Queries](#status-queries)** - Check health and troubleshoot issues ### Direct Queries Direct queries ask about specific resources. The AI finds the resource and retrieves detailed information without needing you to specify the exact namespace or resource type. #### Example: Describe a specific resource ```text Describe the my-postgres cluster ``` **Response:** ```text my-postgres Cluster Type: CloudNativePG (CNPG) PostgreSQL Cluster Namespace: default Status: Healthy (1/1 instances ready) Cluster Overview | Property | Value | |--------------------|-----------------| | PostgreSQL Version | 17.4 | | Age | 22 minutes | | Instances | 1 (single node) | | Primary Pod | my-postgres-1 | | Database | app | Configuration | Setting | Value | |-----------------------|-----------------------| | Storage | 1Gi persistent volume | | Encoding | UTF8 (C locale) | | WAL Level | logical | | TLS | TLSv1.3 (min/max) | | Max Parallel Workers | 32 | | Max Replication Slots | 32 | | Superuser Access | Disabled (secure) | Services | Service | Purpose | |----------------|----------------------| | my-postgres-rw | Read-write (primary) | | my-postgres-r | Read | | my-postgres-ro | Read-only | The cluster is production-ready with enterprise features including automated failover support, backup/recovery capabilities, and secure TLS communication. ``` **What happened**: The AI searched the resources inventory to locate `my-postgres`, identified it as a CNPG Cluster in the default namespace, then used the Kubernetes API to get detailed status and configuration.