A Google Agent Development Kit (ADK) powered assistant that interacts with Kubernetes clusters to provide information about resources.
This repository contains a Kubernetes Assistant Agent built with Google's Agent Development Kit (ADK) that can help you manage and monitor your Kubernetes clusters through natural language conversations. The agent leverages the Google Gemini model to understand user queries and uses Kubernetes API functions to retrieve information from your cluster.
The Kubernetes Assistant can:
- List all namespaces in your Kubernetes cluster
- List deployments, pods, services, secrets, daemonsets, and configmaps in a specific namespace
- Retrieve all major resources (deployments, pods, services, secrets, daemonsets, configmaps) in a specific namespace
- Get detailed information about deployments and pods
- Scale deployments to desired replica counts
- Retrieve pod logs for debugging
- Monitor resource health status (pods and deployments)
- Get cluster events for a specific namespace or across all namespaces with configurable limits
- Python 3.10+
- Google API key for Gemini access (https://aistudio.google.com/apikey)
- Kubernetes configuration file set up on your machine
- Required Python packages:
google-adk
kubernetes>=28.1.0
python-dateutil>=2.8.2
-
Clone this repository:
git clone https://github.com/serkanhaytac/google-adk-kubernetes.git cd google-adk-kubernetes
-
Create a virtual environment and activate it:
python -m venv venv source venv/bin/activate
-
Install the required dependencies:
pip install -r requirements.txt
-
Set up your Google API key:
export GOOGLE_API_KEY="your-api-key"
-
Ensure your Kubernetes configuration is properly set up and accessible.
Run the agent using the following command:
adk web
This will start the agent in web mode, allowing you to interact with it through a web interface on localhost:8000.
To run the agent in API mode, use the following command:
adk api
To test the agent in API mode, use the following command first create a new session by issuing the following command:
curl -X POST http://0.0.0.0:8000/apps/kube/users/u_123/sessions/s_123 -H "Content-Type: application/json" -d '{"state": {"key1": "value1", "key2": 42}}'
Followed by issuing the following command to send a message to the agent:
curl -X POST http://0.0.0.0:8000/apps/kube/users/u_123/sessions/s_123/messages -H "Content-Type: application/json" -d '{"message": "How many pods are running in the default namespace?"}'
kube/
agent.py
: Contains the agent codetools/
__init__.py
tools.py
: Contains Kubernetes API functions used by the agent
__init__.py
: Package initialization file
requirements.txt
: Lists all required Python packagesREADME.md
: This documentation file
list_namespaces()
: List all namespaces in the clusterlist_deployments_from_namespace(namespace)
: List deployments in a namespacelist_pods_from_namespace(namespace)
: List pods in a namespacelist_services_from_namespace(namespace)
: List services in a namespacelist_secrets_from_namespace(namespace)
: List secrets in a namespacelist_daemonsets_from_namespace(namespace)
: List daemonsets in a namespacelist_configmaps_from_namespace(namespace)
: List configmaps in a namespacelist_all_resources(namespace)
: List major resources (deployments, pods, services, secrets, daemonsets, configmaps) in a namespace
get_deployment_details(deployment_name, namespace)
: Get detailed deployment informationscale_deployment(deployment_name, replicas, namespace)
: Scale a deployment
get_pod_details(pod_name, namespace)
: Get detailed pod informationget_pod_logs(pod_name, namespace, container=None, tail_lines=100)
: Get pod logs
get_resource_health(resource_name, resource_type, namespace)
: Check resource health (supports 'pod' and 'deployment')get_events(namespace, limit=200)
: Get cluster events for a specific namespaceget_events_all_namespaces(limit=200)
: Get cluster events across all namespaces
This agent requires proper Kubernetes cluster access and credentials. Ensure that:
- Your kubeconfig file is properly configured
- You have the necessary permissions for the operations you're performing
- Sensitive credentials are properly managed and not exposed