AI-Powered Kubernetes MCP Server

AI-Powered Kubernetes MCP Server

Enables natural-language management of Kubernetes clusters via kubectl-ai and Gemini, providing commands like listing pods, scaling deployments, and retrieving logs through a FastAPI backend.

Category
Visit Server

README

🧠 AI-Powered Kubernetes MCP Server (Minikube + Gemini + kubectl-ai)

This project deploys an AI-connected Kubernetes MCP (Model-Controller-Prompt) server on an EC2 instance using Minikube, Google Gemini, and kubectl-ai. The MCP server allows natural-language interaction with Kubernetes β€” powered by a custom schema and FastAPI backend.


πŸ“– Full Guide Available

πŸ“ Check out the full Medium article walkthrough here:
πŸ‘‰ Read on Medium


🧱 Architecture Overview

  • EC2 Ubuntu Instance (T2.Medium, 30 GiB EBS)
  • Minikube (Docker driver)
  • kubectl-ai – Google’s CLI for AI-driven Kubernetes commands
  • Gemini API (1.5 Flash) – Natural language LLM
  • FastAPI MCP Server – Hosts custom mcp-schema.json for command interpretation
  • NodePort Service – Exposes MCP server endpoint
  • Demo App – my-website-app deployed for live testing

πŸ“¦ Prerequisites

Tool Required
Ubuntu 22.04 EC2 βœ…
Docker (non-root) βœ…
Minikube βœ…
Go 1.22+ βœ…
kubectl βœ…
Gemini API Key βœ…

βš™οΈ Setup Steps

πŸ” 1. Create Security Group

  • Allow SSH (22)
  • Allow NodePort range: 30000–32767 (TCP)
  • Allow HTTP (80)

☁️ 2. Launch EC2 Instance

  • AMI: Ubuntu 22.04+
  • Type: t2.medium or higher
  • Disk: 30 GiB
  • User-data:
    #!/bin/bash
    
    

set -e

Update system and install essentials

apt-get update -y && apt-get upgrade -y apt-get install -y curl wget git ca-certificates gnupg lsb-release apt-transport-https software-properties-common

---- Python ----

apt-get install -y python3 python3-pip update-alternatives --install /usr/bin/python python /usr/bin/python3 1 update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 1

---- Docker ----

apt-get install -y docker.io systemctl enable docker systemctl start dockeru


---

### πŸ§‘β€πŸ’» 3. Initial Setup After SSH

```bash
sudo usermod -aG docker ubuntu
sudo reboot

πŸ“¦ 4. Install Requirements

# kubectl

# Go

Follow official Minikube install guide:
πŸ‘‰ https://minikube.sigs.k8s.io/docs/start/


πŸ“ 5. Clone Repos

git clone https://github.com/your-username/k8s-mcp-server-prod.git
cd k8s-mcp-server-prod

git clone https://github.com/GoogleCloudPlatform/kubectl-ai.git
cd kubectl-ai
go build -o kubectl-ai ./cmd/kubectl-ai
sudo mv kubectl-ai /usr/local/bin/

☸️ 6. Start Minikube

minikube start --driver=docker

πŸ”Œ 7. Deploy MCP + App

kubectl apply -f rbac.yaml
kubectl apply -f my-website-app.yaml
kubectl apply -f mcp-deployment.yaml
kubectl apply -f mcp-service.yaml

πŸ” 8. Test MCP Server

minikube ip  # e.g. 192.168.49.2
kubectl get svc mcp-service  # Note NodePort, e.g. 31390

curl http://192.168.49.2:31390/mcp-schema.json

βœ… Should return your schema in JSON.


πŸ“˜ 9. Configure kubectl-ai

mkdir -p ~/.kube/kubectl-ai
nano ~/.kube/kubectl-ai/config.yaml

Paste:

mcp:
  endpoint: http://192.168.49.2:31390/mcp-schema.json
  name: mcp-server

llm:
  provider: gemini
  model: gemini-1.5-flash

πŸ”‘ 10. Create Gemini Secret

kubectl create secret generic gemini-api-key   --from-literal=GEMINI_API_KEY=your-key

export GEMINI_API_KEY=your-key
echo 'export GEMINI_API_KEY=your-key' >> ~/.bashrc
source ~/.bashrc

🧠 11. Use kubectl ai

kubectl ai --model gemini-1.5-flash

πŸ’¬ Demo Prompts

You can now ask kubectl ai things like:

Prompt Action
List all pods in the default namespace list_pods
Restart the my-website-app deployment restart_deployment
Scale the my-website-app to 5 replicas scale_deployment
Delete pod my-website-app-xyz delete_pod
Get logs from pod in default namespace get_pod_logs
List all nodes get_nodes
Get cluster namespaces get_namespaces
Get events in default namespace get_events

🧹 Cleanup

kubectl delete -f mcp-service.yaml
kubectl delete -f mcp-deployment.yaml
kubectl delete -f my-website-app.yaml
kubectl delete -f rbac.yaml
kubectl delete secret gemini-api-key

πŸ™Œ Acknowledgements


πŸ“Œ Next Steps

  • Add HTTPS ingress controller with TLS
  • Package MCP as a Helm chart
  • Add multi-model support for OpenAI or Anthropic

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured