Tutorial

Building Real-Time Kubernetes AI Agent with GenAI Platform

Building Real-Time Kubernetes AI Agent with GenAI Platform

Introduction

In today’s data-driven world, real-time AI-powered agents have become crucial for automating workflows, assisting developers, and providing intelligent insights. Whether you’re a developer, data scientist, or AI enthusiast, DigitalOcean’s GenAI platform provides an accessible and streamlined way to build intelligent agents without requiring complex infrastructure.

This tutorial walks you through building an AI-powered Kubernetes assistant that can generate and validate Kubernetes manifests, troubleshoot issues, and retrieve real-time cluster details. By following this tutorial, you’ll learn how to integrate AI with DigitalOcean Functions and knowledgebase web crawling to create an intelligent, API-driven assistant.

Prerequisites

To complete this tutorial, you will need:

Why AI Agents for Kubernetes?

Kubernetes is a powerful but complex container orchestration tool. Managing configurations, debugging errors, and ensuring best practices can be challenging. AI-driven automation can simplify this process by providing instant YAML generation, validation, and troubleshooting assistance.

Capabilities of the AI Agent

Generate Kubernetes YAML Manifests

Traditional methods of writing Kubernetes YAML files can be error-prone and time-consuming. This AI-powered assistant streamlines the process by generating valid YAML files for Deployments, Services, Ingress, ConfigMaps, Secrets, and StatefulSets while ensuring best practices such as avoiding privileged containers. When details are missing, the agent makes reasonable assumptions and includes comments for clarity.

Validate & Troubleshoot

Ensuring that Kubernetes manifests comply with API standards is essential for preventing deployment failures. The AI assistant validates YAML syntax, identifies missing or incorrect fields, and suggests necessary fixes. Additionally, it provides explanations for errors and optimization recommendations, making it easier for developers to troubleshoot misconfigurations.

Web Crawling for Troubleshooting

Debugging Kubernetes issues often requires searching through official documentation and community forums. This AI agent automates the process by extracting troubleshooting data from Kubernetes.io and Kubernetes Community resources using the GenAI web crawler, which scans up to 1000 links while respecting robots.txt rules and access restrictions.

DigitalOcean Integration

To provide real-time Kubernetes insights, the AI agent leverages DigitalOcean Functions to fetch cluster details. It retrieves kubeconfig stored in DigitalOcean Spaces, ensuring seamless and secure access to managed clusters.

By combining YAML generation, validation, troubleshooting, and real-time API integration, this AI-powered Kubernetes assistant significantly reduces the complexity of managing Kubernetes environments.

Step 1 - Preparing Your Function

First, you’ll create a function that the language model can call to retrieve data from the DigitalOcean API:

  1. In the DigitalOcean control panel, navigate to Functions and click “Create Namespace”.

  2. Select a data center location (e.g., Toronto)

  3. Use the doctl command line tool to connect to your namespace:

    doctl serverless connect
    
  4. Initialize a sample Python project:

    doctl serverless init --language python example-project
    

Step 2 - Configuring Your Function

Once the sample project is initialized, you’ll need to:

  1. Modify the project file to define the Python runtime and set security headers

  2. Create an environment file for your spaces keys, so that your function can retrieve the kubeconfig file stored.

  3. Replace the hello world sample with your API function code that retrieves cluster information.

  4. Create a build script for importing Python dependencies.

  5. Deploy the function to make it available in the cloud:

    doctl serverless deploy
    

You can find a complete example with all the required code and configuration in this repository DigitalOcean API Kube.

After deployment, you can test your function through the web interface to ensure it returns the expected information about your cluster.

Step 3 - Creating Your AI Agent

You can create your AI agent either through the web interface or using the API:

  1. In the GenAI platform, click “Create Agent”
  2. Name your agent (e.g., “K8s Agent”)
  3. Provide agent instructions (system prompt) to define its purpose
  4. Choose your preferred language model (e.g., Llama 3.3 Instruct-70B)
  5. Create the agent.

Step 4 - Add Web Crawling Data Source to your Knowledgebase

  1. Go to the GenAI Platform and select Knowledge Bases.
  2. Click on “Create Knowledge Base”. Provide a name and description for your Knowledge Base.
  3. Under “Select Data Sources”, URL for WebCrawling and provide the URL to be crawled
  4. Choose a storage location for storing indexed data and select the embedding model to be used for retrieval.
  5. Create the KnowledgeBase

Step 5 - Connecting your Knowledgebase to your Gen AI Agent

  1. Navigate to the Resources tab in the agent playground
  2. Under Knowledge Bases, Click on Add Knowledge bases.
  3. Select your knowledgebase and add it to your agent.

Step 6 - Connecting Your Function to the Agent Using the Web Interface

The final step is to link your function to the agent. You can do this either through the web interface or using the API:

  1. Navigate to the Resources tab in the agent playground
  2. Add a function route
  3. Select your namespace and function
  4. Provide function instructions to guide when the agent should call the function
  5. Define input and output schemas to help the language model understand how to use the function

The input schema specifies parameters the agent can send to your function (like pod Name), while the output schema helps the agent interpret the returned data.

Example Input Schema for Pod Function

{
  "status": {
    "type": "string",
    "required": false,
    "description": "Filter pods by status (e.g., Running, Pending, Failed)"
  },
  "namespace": {
    "type": "string",
    "required": false,
    "description": "Filter pods by namespace"
  },
  "ip": {
    "description": "Filter pods by a specific IP address",
    "type": "string",
    "required": false
  },
  "name": {
    "description": "Filter pods by pod name or partial match",
    "type": "string",
    "required": false
  }
}

Example Output Schema

{
  "pods": {
    "type": "string",
    "description": "JSON string containing list of pod information"
  },
  "count": {
    "type": "number",
    "description": "Total number of pods returned"
  },
  "error": {
    "description": "Error message if the request failed",
    "type": "string",
    "required": false
  },
  "status": {
    "type": "string",
    "description": "Status of the API request (success or error)"
  }
}

Testing Your AI Agent

With everything set up, you can now ask your agent questions about your DigitalOcean account:

  • “List all the pod in kube-system namespace”
  • “Can you validate this yaml?”
  • “Can you generate a yaml manifest for nginx deployment with 3 replicas?”

The agent will call your function, retrieve the information from the cluster, and provide you with an intelligent response.

Conclusion

By following this tutorial, you’ve successfully built a real-time AI-powered Kubernetes assistant using DigitalOcean’s GenAI Platform. This agent can generate YAML manifests, validate configurations, and troubleshoot Kubernetes issues using live data.

This approach eliminates the need for complex infrastructure, making AI-driven automation accessible to developers of all skill levels. With further customization, you can extend this agent’s capabilities to integrate with additional APIs, provide security recommendations, or even automate deployments.

Continue building with DigitalOcean Gen AI Platform.

About the author(s)

Rahul Shettigar
Rahul Shettigar
See author profile

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
Leave a comment


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.