DEV Community

Cover image for Managing Kubernetes Clusters Using K8s MCP Server
Sanskriti Harmukh for Vultr

Posted on with Aashish Chaurasiya Originally published at docs.vultr.com

Managing Kubernetes Clusters Using K8s MCP Server

Model Context Protocol (MCP) is a new approach to organizing context for large language models, letting them act more intelligently and maintain continuity across tasks, tools, and sessions. By defining key elements like user intent, memory, and available tools, MCP enables more seamless, context-aware interactions in AI applications. This guide walks through running a Kubernetes MCP server container so you can interact with a Kubernetes cluster using natural language, and shows how to connect it to Claude Desktop to manage the cluster conversationally. By the end, you'll have a Kubernetes MCP server running locally and wired into Claude Desktop for natural-language cluster management.


Prerequisites

Before you begin:


Get Started Right Away

Make sure you've downloaded your Kubernetes cluster's kubeconfig file to your local system before proceeding.

1. Display all available contexts defined in the kubeconfig file:

$ kubectl config get-contexts
Enter fullscreen mode Exit fullscreen mode

Copy the context value to use in the later steps.

2. Pull the sample Kubernetes MCP server Docker container image:

$ docker pull ghcr.io/alexei-led/k8s-mcp-server:latest
Enter fullscreen mode Exit fullscreen mode

3. Run the sample Kubernetes MCP server Docker container image:

$ docker run -i --rm \
    -v ~/.kube:/home/appuser/.kube:ro \
    -e K8S_CONTEXT=<K8S_CLUSTER_CONTEXT_VALUE> \
    ghcr.io/alexei-led/k8s-mcp-server:latest
Enter fullscreen mode Exit fullscreen mode

4. Confirm the image is running in the Docker Desktop application.


Understand the MCP Server

  • Unified Kubernetes CLI Tools — built-in support for multiple Kubernetes tools like kubectl, helm, istioctl, and argocd, all within a single containerized environment.
  • Cloud-Native Integration — native compatibility with major managed Kubernetes providers.
  • Secure by Design — runs as a non-root user and enforces strict validation on incoming commands to maintain security and control.
  • Flexible Command Chaining — supports command piping and integrates smoothly with Unix utilities like jq, grep, and sed for complex workflows.
  • Simplified Configuration — easily customizable through environment variables, minimizing setup time and complexity.

Use Claude Desktop to Interact

The Claude Desktop application automatically detects MCP servers defined in its configuration file and makes them accessible within any conversation.

1. Start the Claude Desktop application.

2. Locate the settings option in the application.

3. Select Developer settings.

4. Click Edit Config.

5. Add the following configuration snippet to your Claude Desktop config file:

{
"mcpServers": {
    "kubernetes": {
    "command": "docker",
    "args": [
        "run",
        "-i",
        "--rm",
        "-v",
        "/Users/YOUR_USER_NAME/.kube:/home/appuser/.kube:ro",
        "-e",
        "K8S_CONTEXT=<K8S_CLUSTER_CONTEXT_VALUE>",
        "ghcr.io/alexei-led/k8s-mcp-server:latest"
    ]
    }
}
}
Enter fullscreen mode Exit fullscreen mode

Replace the value of K8S_CONTEXT with your actual Kubernetes context name. Also update the mount path /Users/YOUR_USER_NAME/.kube to point to your real .kube directory (usually ~/.kube on most systems).

6. Restart the Claude Desktop application once the new configuration is in place.

7. Confirm the server is running: go to the Developer settings in Claude Desktop and check that the status next to the JSON file shows as running.

8. Make sure the MCP server tools are available to the application.

MCP tools

Ask Questions and Perform Operations

You can manage your Kubernetes cluster by chatting naturally using the Claude Desktop application.

K8s cluster info

Make sure the responses match the actual state of your cluster.

Example Operations Supported by the Kubernetes MCP Server

Advanced Operations

  • Check the status of the Istio service mesh.
  • Create an ArgoCD application for a repository.

Deployments & Configuration

  • Deploy the Nginx Helm chart.
  • Create a deployment with 3 replicas of nginx:latest.
  • Set up an Ingress controller.

Troubleshooting

  • Describe the failing pod and explain the error.
  • Check if a service is properly connected to its pods.

Basic Commands

  • Show all pods in the default namespace.
  • Get all services across all namespaces.
  • Display the logs for the Nginx pod.

Next Steps

  • Extend the MCP server configuration to manage multiple cluster contexts side by side.
  • Pair the MCP server with the ArgoCD and Istio tooling already built into the container.
  • Explore additional natural-language operations for scaling, troubleshooting, and Helm deployments.

For the full guide with additional tips, visit the original article on Vultr Docs.

Top comments (0)