Join our Discord Server
Collabnix Team The Collabnix Team is a diverse collective of Docker, Kubernetes, and IoT experts united by a passion for cloud-native technologies. With backgrounds spanning across DevOps, platform engineering, cloud architecture, and container orchestration, our contributors bring together decades of combined experience from various industries and technical domains.

Kubernetes MCP Server: Step by Step Guide

4 min read

In today’s cloud-native world, managing Kubernetes clusters efficiently is crucial for DevOps professionals and platform engineers. While command-line tools like kubectl are powerful, wouldn’t it be great if you could interact with your Kubernetes clusters using natural language through your AI assistant? This is exactly what MCP-Server-Kubernetes enables for Claude users.

What is MCP-Server-Kubernetes?

MCP-Server-Kubernetes is an open-source project that allows Claude AI to connect to your Kubernetes clusters and manage them through natural language conversation. It implements the Model Context Protocol (MCP), which enables AI assistants like Claude to interact with external systems and tools.

With this tool, you can ask Claude to:

  • List and describe pods, services, and deployments
  • Create new resources in your cluster
  • Check logs for debugging
  • Manage Helm charts
  • Scale deployments
  • And much more!

All through natural language conversation, without having to switch contexts or remember complex kubectl commands.

Key Features

MCP-Server-Kubernetes provides a comprehensive set of tools for Kubernetes management:

Resource Management

  • List and describe resources: Pods, services, deployments, nodes, namespaces, cronjobs
  • Creation and deletion: Create or delete pods, deployments, services, namespaces
  • Configuration: Create, update, and manage ConfigMaps

Deployment Operations

  • Scaling: Easily scale deployments up or down
  • Updates: Update deployments with new images or configurations
  • Logs: Retrieve logs from pods, deployments, or jobs

Helm Integration

  • Chart installation: Install Helm charts with custom values
  • Release management: Upgrade, update, or uninstall releases
  • Repository support: Work with custom Helm repositories

Networking

  • Port forwarding: Forward ports from pods or services to your local machine
  • Service management: Create, describe, and update services

Cluster Exploration

  • kubectl explain: Get detailed information about Kubernetes resources
  • Events: Monitor cluster events for debugging
  • API resources: List available API resources

Safety Features

  • Non-destructive mode: Limit operations to read-only or creation actions for safer access

Step-by-Step Guide: Using Claude with Kubernetes MCP Server

Prerequisites

Before starting, ensure you have:

  • A Kubernetes cluster you can connect to
  • kubectl installed and configured
  • Node.js installed (version 18 or higher)
  • Claude Desktop application installed

Step 1: Set Up Your Kubernetes Environment

Image 1: Verifying Kubernetes access Description: Terminal window showing the output of kubectl get nodes command, displaying the list of nodes in your cluster.

  1. Open a terminal window
  2. Run kubectl get nodes to verify you have access to your cluster
  3. Ensure the command returns a list of nodes without authentication errors
$ kubectl get nodes
NAME                STATUS   ROLES    AGE     VERSION
minikube           Ready    master   45d     v1.26.3

Step 2: Install MCP-Server-Kubernetes

Image 2: Installing MCP-Server-Kubernetes Description: Terminal window showing the npm install command being executed.

  1. Open a terminal and run:
npm install -g mcp-server-kubernetes
  1. Alternatively, you can use it directly with npx without installing:
npx mcp-server-kubernetes

Step 3: Configure Claude Desktop

  1. Locate your Claude Desktop configuration file:
    • Mac: ~/Library/Application Support/Claude/claude_desktop_config.json
    • Windows: %APPDATA%\Claude\claude_desktop_config.json
    • Linux: ~/.config/Claude/claude_desktop_config.json

  1. Edit the configuration file to add the MCP server:
{
"mcpServers": {
"kubernetes": {
"command": "npx",
"args": ["mcp-server-kubernetes"]
}
}
}
  1. If you want to enable read-only mode (safer for production environments), use:
{
"mcpServers": {
"kubernetes-readonly": {
"command": "npx",
"args": ["mcp-server-kubernetes"],
"env": {
"ALLOW_ONLY_NON_DESTRUCTIVE_TOOLS": "true"
}
}
}
}
  1. Save the file

Step 4: Launch Claude Desktop

  1. Start (or restart) Claude Desktop application
  2. The application will automatically load the MCP server configuration

Step 5: Verify MCP-Server-Kubernetes Connection

  1. In Claude, type a message to verify the connection:
Can you check if you're connected to my Kubernetes cluster and list the namespaces?
  1. Claude should respond with information about your Kubernetes namespaces:
I've successfully connected to your Kubernetes cluster. Here are the namespaces:

Namespaces:
- default (Active)
- kube-system (Active)
- kube-public (Active)
- kube-node-lease (Active)
...

Step 6: Basic Kubernetes Operations with Claude

  1. Ask Claude to list pods in a namespace:
Please list all pods in the default namespace.
  1. Claude should respond with pods information:
I'm connected to your Kubernetes cluster. Here are the pods in the default namespace:

Pods:
- nginx-deployment-66b6c48dd5-8r5xq (Running)
- nginx-deployment-66b6c48dd5-v7szd (Running)
...
  1. Ask for more details about a specific pod:
Can you describe the pod nginx-deployment-66b6c48dd5-8r5xq?
  1. Claude will provide detailed information about the pod:
Here's the detailed information for pod nginx-deployment-66b6c48dd5-8r5xq:

Name: nginx-deployment-66b6c48dd5-8r5xq
Namespace: default
Status: Running
IP: 10.244.0.23
Node: minikube
...

Step 7: Creating Resources with Claude

Image 9: Creating a deployment via Claude Description: Screenshot showing a conversation requesting Claude to create a new deployment and the successful completion message.

  1. Ask Claude to create a simple deployment:
Please create a deployment named "hello-world" with the nginx image and 2 replicas in the default namespace.
  1. Claude will interact with your Kubernetes cluster and create the deployment:
I'll create that deployment for you.

Successfully created deployment "hello-world" in namespace "default" with 2 replicas using the nginx image.

The deployment has been configured with:
- 2 replicas
- nginx:latest image
- Default CPU and memory settings

You can check the status of your new deployment with:
kubectl get deployment hello-world -n default

Step 8: Checking Logs with Claude

  1. Ask Claude to check logs from a pod:
Can you show me the logs from the hello-world deployment?
  1. Claude will fetch and display the logs:
Here are the logs from the pods in the hello-world deployment:

From pod hello-world-5d8b9b674d-f8xnq:
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
...

Step 9: Scaling Deployments

  1. Ask Claude to scale a deployment:
Please scale the hello-world deployment to 3 replicas.
  1. Claude will execute the scaling operation:
I've scaled the hello-world deployment in the default namespace from 2 to 3 replicas.

The deployment is now updating. The new replica is being created and should be running shortly.

Current status:
- Desired replicas: 3
- Current replicas: 3
- Updated replicas: 3
- Available replicas: 2 (third replica is still starting)

Step 10: Clean Up Resources

  1. Ask Claude to delete the resources you created:
Please delete the hello-world deployment.
  1. Claude will clean up the resources:
I've deleted the hello-world deployment from the default namespace.

The deletion request was successful. Kubernetes is now terminating the pods associated with this deployment.

If you want to verify the deployment is gone, you can ask me to list deployments in the default namespace.

Advanced Usage: Using Helm with Claude

  1. Ask Claude to install a Helm chart:
Can you install the bitnami/nginx Helm chart with release name "my-nginx" in the default namespace?
  1. Claude will install the requested chart:
I'm installing the bitnami/nginx Helm chart for you.

Successfully installed the bitnami/nginx Helm chart with release name "my-nginx" in the default namespace.

Release notes:
CHART NAME: nginx
CHART VERSION: 15.1.2
APP VERSION: 1.25.3

The nginx server can be accessed via port 80 on the following DNS name from within your cluster:
my-nginx.default.svc.cluster.local
...

MCP-Server-Kubernetes represents a powerful new paradigm in Kubernetes management by bridging the gap between AI assistants and your infrastructure. By enabling Claude to directly interact with your clusters, it reduces cognitive load, speeds up operations, and makes Kubernetes more accessible.

Whether you’re an experienced Kubernetes operator looking to streamline your workflow or someone just starting with containers, MCP-Server-Kubernetes offers a natural, conversation-based interface to your clusters that can significantly enhance your productivity.

Try it today and experience the future of Kubernetes management through AI assistance!

Have Queries? Join https://launchpass.com/collabnix

Collabnix Team The Collabnix Team is a diverse collective of Docker, Kubernetes, and IoT experts united by a passion for cloud-native technologies. With backgrounds spanning across DevOps, platform engineering, cloud architecture, and container orchestration, our contributors bring together decades of combined experience from various industries and technical domains.
Collabnixx
Chatbot
Join our Discord Server
Index