samcolon
MCP Serversamcolonpublic

k8s_mcp_server_prod

部署基于Minikube、Gemini和kubectl-ai的AI连接Kubernetes MCP服务器。

Repository Info

2
Stars
1
Forks
2
Watchers
0
Issues
Python
Language
-
License

About This Server

部署基于Minikube、Gemini和kubectl-ai的AI连接Kubernetes MCP服务器。

Model Context Protocol (MCP) - This server can be integrated with AI applications to provide additional context and capabilities, enabling enhanced AI interactions and functionality.

Documentation

🧠 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 Appmy-website-app deployed for live testing

📦 Prerequisites

ToolRequired
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:

PromptAction
List all pods in the default namespacelist_pods
Restart the my-website-app deploymentrestart_deployment
Scale the my-website-app to 5 replicasscale_deployment
Delete pod my-website-app-xyzdelete_pod
Get logs from pod in default namespaceget_pod_logs
List all nodesget_nodes
Get cluster namespacesget_namespaces
Get events in default namespaceget_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

  • Google kubectl-ai
  • Minikube
  • Gemini API
  • FastAPI

📌 Next Steps

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

Quick Start

1

Clone the repository

git clone https://github.com/samcolon/k8s_mcp_server_prod
2

Install dependencies

cd k8s_mcp_server_prod
npm install
3

Follow the documentation

Check the repository's README.md file for specific installation and usage instructions.

Repository Details

Ownersamcolon
Repok8s_mcp_server_prod
LanguagePython
License-
Last fetched8/10/2025

Recommended MCP Servers

💬

Discord MCP

Enable AI assistants to seamlessly interact with Discord servers, channels, and messages.

integrationsdiscordchat
🔗

Knit MCP

Connect AI agents to 200+ SaaS applications and automate workflows.

integrationsautomationsaas
🕷️

Apify MCP Server

Deploy and interact with Apify actors for web scraping and data extraction.

apifycrawlerdata
🌐

BrowserStack MCP

BrowserStack MCP Server for automated testing across multiple browsers.

testingqabrowsers

Zapier MCP

A Zapier server that provides automation capabilities for various apps.

zapierautomation