🤖 Kubernetes as Your AI Contr... Note

🤖 Kubernetes as Your AI Control Plane: Running Claude and Ollama Agents with kagent 🧠

kagent is a CNCF sandbox project that integrates AI agents directly into Kubernetes clusters. It allows users to run AI workloads alongside their existing pods using familiar tools like kubectl and GitOps. The core idea is to provide a unified abstraction for AI agents to interact with various language models, whether cloud-based like Claude or local ones like Ollama. This guide demonstrates building a homelab inference stack with kagent.The kagent inference stack consists of several layers: model providers, ModelConfig resources to specify model details, Agent resources defining prompts and tools, a tool server exposing Kubernetes actions, and a controller managing the system. Prerequisites include a Kubernetes cluster, kubectl, helm, an Anthropic API key, and sufficient resources for a local model. kagent is installed via Helm charts for its CRDs and controller components.The guide walks through setting up cloud inference by creating a ModelConfig for Claude, referencing an Anthropic API key stored in a Kubernetes Secret. For on-premises inference, Ollama is deployed within the cluster with a PersistentVolumeClaim and exposed via a Service. Another ModelConfig is created for Ollama, pointing to its in-cluster Service.Agents are then built as Kubernetes custom resources, specifying a system prompt, tools, and a reference to a ModelConfig. This allows the same agent to be used with different models by simply changing the ModelConfig reference. Users can interact with these agents using the kagent CLI, invoking them with specific prompts and comparing responses from different models.A crucial safety feature highlighted is the Human in the Loop capability, which allows users to set up an approval gate for specific agent tools. This prevents accidental or unintended actions by the AI agent on the cluster resources. By integrating AI agents natively into Kubernetes, kagent offers a powerful and flexible way to manage AI workloads within a familiar infrastructure.