How to intermediate · 3 min read

MCP server Kubernetes deployment

Quick answer
Deploy an MCP server on Kubernetes by containerizing your Python mcp.server app using stdio_server for communication, then create a Kubernetes Deployment and Service manifest to run and expose the server. Use a Dockerfile to package your server code and apply the manifests with kubectl for scalable, managed deployment.

PREREQUISITES

  • Python 3.8+
  • Docker installed
  • kubectl configured for your Kubernetes cluster
  • pip install mcp
  • Basic knowledge of Kubernetes manifests

Setup MCP server environment

Install the mcp Python package and prepare your MCP server script using stdio_server for standard input/output communication, which is compatible with containerized environments like Kubernetes.

Create a requirements.txt with mcp and a Python script server.py that runs the MCP server.

python
pip install mcp

# requirements.txt
mcp

# server.py
from mcp.server import Server
from mcp.server.stdio import stdio_server

class MyAgent(Server):
    def handle_request(self, request):
        # Implement your agent logic here
        return {"response": "Hello from MCP server!"}

if __name__ == "__main__":
    stdio_server(MyAgent())

Containerize MCP server with Docker

Create a Dockerfile to containerize your MCP server app. This container will run your Python MCP server using stdio_server inside Kubernetes.

python
FROM python:3.10-slim
WORKDIR /app
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY server.py ./
CMD ["python", "server.py"]

Kubernetes deployment manifest

Define a Kubernetes Deployment and Service manifest to deploy and expose your MCP server container. This example runs one replica and exposes port 8080 (adjust as needed for your setup).

yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mcp-server
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mcp-server
  template:
    metadata:
      labels:
        app: mcp-server
    spec:
      containers:
      - name: mcp-server
        image: your-dockerhub-username/mcp-server:latest
        ports:
        - containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
  name: mcp-server-service
spec:
  selector:
    app: mcp-server
  ports:
  - protocol: TCP
    port: 80
    targetPort: 8080
  type: ClusterIP

Deploy and verify

Build and push your Docker image, then apply the Kubernetes manifests to deploy your MCP server.

Commands:

bash
docker build -t your-dockerhub-username/mcp-server:latest .
docker push your-dockerhub-username/mcp-server:latest
kubectl apply -f mcp-server-deployment.yaml
kubectl get pods
kubectl get svc mcp-server-service
output
NAME                          READY   STATUS    RESTARTS   AGE
mcp-server-xxxxxxxxxx-xxxxx   1/1     Running   0          1m

NAME                 TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)   AGE
mcp-server-service   ClusterIP   10.96.0.123     <none>        80/TCP    1m

Key Takeaways

  • Use stdio_server for MCP server communication in containerized environments.
  • Containerize your MCP server with a simple Python Dockerfile for Kubernetes deployment.
  • Define Kubernetes Deployment and Service manifests to manage MCP server lifecycle and networking.
  • Build, push, and deploy your container image with kubectl commands for production-ready MCP servers.
Verified 2026-04
Verify ↗