convez.ai
MCP ServerDevOps & InfraestruturaAvançado
giantswarm

MCP Kubernetes

giantswarm/mcp-kubernetes

Controle total de clusters Kubernetes pelo Claude com OAuth, multi-cluster e observabilidade

Ver no GitHub
InicialPluginScore · de 0 a 100

Servidor MCP para interagir com clusters Kubernetes através do Claude. Oferece ferramentas completas de gerenciamento de recursos, operações com pods, autenticação multi-modo e suporte a múltiplos clusters com observabilidade em nível de produção.

Instalação

$npx convez-ai giantswarm/mcp-kubernetes

1 comando no terminal: detecta o formato do repositório (marketplace ou plugin avulso) e instala via Claude Code. Requer Node 18+ e o Claude Code instalado.

Métricas

Estrelas
2
Forks
0
Acompanhando
0
Saúde
62%
Último commit
há 1 dia
Versão
v1.15.0
Issues abertas
15
Contribuidores
15

Casos de uso

  • Gerenciar recursos Kubernetes remotamente via chat
  • Executar comandos e acessar logs de pods em tempo real
  • Orquestração de múltiplos clusters com CAPI
  • Automatizar operações de DevOps com segurança (dry-run, modo não-destrutivo)

Veredito

MCP server robusto e production-ready para Kubernetes. Cobertura completa de operações cluster, autenticação corporativa (OAuth 2.1) e observabilidade industrial. Ideal para equipes DevOps que querem integrar gestão Kubernetes ao fluxo de conversação com Claude.

README

A tradução para o português deste README ainda está na fila.

mcp-kubernetes

A Model Context Protocol (MCP) server that provides tools for interacting with Kubernetes clusters.

Features

  • Resource Management: Get, list, describe, create, apply, delete, and patch Kubernetes resources
  • Pod Operations: Get logs, execute commands, and set up port forwarding
  • Context Management: List, get, and switch between Kubernetes contexts
  • Cluster Information: Get API resources and cluster health status
  • Multiple Authentication Modes: Support for kubeconfig, in-cluster, OAuth 2.1, and federated multi-cluster authentication
  • Multi-Cluster Support: Federation with Cluster API (CAPI) for managing workload clusters from a management cluster
  • Multiple Transport Types: Support for stdio and streamable HTTP
  • Safety Features: Non-destructive mode, dry-run capability, and operation restrictions
  • OAuth 2.1 Support: Secure token-based authentication with Dex OIDC (default) and Google OAuth providers
  • Production-Grade Observability: OpenTelemetry instrumentation with Prometheus metrics and distributed tracing

Installation

go install github.com/giantswarm/mcp-kubernetes@latest

Usage

Basic Usage

# Start the MCP server with default settings (stdio transport, kubeconfig authentication)
mcp-kubernetes serve

# Start with debug logging
mcp-kubernetes serve --debug

# Start with in-cluster authentication (when running as a pod in Kubernetes)
mcp-kubernetes serve --in-cluster

Authentication Modes

The server supports multiple authentication modes:

Kubeconfig Authentication (Default)

Uses standard kubeconfig file authentication. The server will look for kubeconfig in the default locations (~/.kube/config) or use the KUBECONFIG environment variable.

# Use default kubeconfig
mcp-kubernetes serve

# Use specific kubeconfig (via environment variable)
KUBECONFIG=/path/to/kubeconfig mcp-kubernetes serve

In-Cluster Authentication

Uses service account token when running inside a Kubernetes pod. This mode automatically uses the mounted service account credentials.

# Enable in-cluster authentication
mcp-kubernetes serve --in-cluster

Requirements for in-cluster mode:

  • Must be running inside a Kubernetes pod
  • Service account token must be mounted at /var/run/secrets/kubernetes.io/serviceaccount/token
  • CA certificate must be available at /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
  • Namespace must be available at /var/run/secrets/kubernetes.io/serviceaccount/namespace

OAuth 2.1 Authentication

Uses OAuth 2.1 with Dex OIDC (default) or Google OAuth provider for secure, token-based authentication (available for HTTP transports only).

# Start with Dex OAuth authentication (default provider)
mcp-kubernetes serve \
  --transport=streamable-http \
  --enable-oauth \
  --oauth-base-url=https://mcp.example.com \
  --dex-issuer-url=https://dex.example.com \
  --dex-client-id=mcp-kubernetes \
  --dex-client-secret=YOUR_DEX_SECRET \
  --dex-connector-id=github \
  --registration-token=YOUR_SECURE_TOKEN

# Or use Google OAuth provider
mcp-kubernetes serve \
  --transport=streamable-http \
  --enable-oauth \
  --oauth-provider=google \
  --oauth-base-url=https://mcp.example.com \
  --google-client-id=YOUR_CLIENT_ID \
  --google-client-secret=YOUR_CLIENT_SECRET \
  --registration-token=YOUR_SECURE_TOKEN

See docs/oauth.md for detailed OAuth setup and configuration.

Federation (Multi-Cluster with CAPI)

Enables access to multiple workload clusters through a management cluster using Cluster API (CAPI). The server discovers workload clusters dynamically and uses user impersonation for RBAC enforcement on each cluster.

# Enable federation mode with OAuth
mcp-kubernetes serve \
  --transport=streamable-http \
  --in-cluster \
  --enable-oauth \
  --downstream-oauth \
  --enable-capi \
  --oauth-base-url=https://mcp.example.com \
  --dex-issuer-url=https://dex.example.com \
  --dex-client-id=mcp-kubernetes \
  --dex-client-secret=YOUR_DEX_SECRET

Security model:

  • Management Cluster RBAC: Users must have permission to list CAPI Cluster resources and read kubeconfig secrets
  • Workload Cluster RBAC: Operations use impersonation headers, delegating authorization to each cluster's RBAC policies
  • User Isolation: Cached clients are keyed by (cluster, user) pairs to prevent cross-user access

Impersonation headers added to workload cluster requests:

  • Impersonate-User: User's email from OAuth
  • Impersonate-Group: User's groups from OAuth
  • Impersonate-Extra-agent: mcp-kubernetes (for audit trail)

SSO Token Passthrough Mode (Alternative):

For organizations where workload cluster API servers are configured with OIDC authentication, an alternative authentication mode forwards the user's SSO token directly to workload clusters instead of using impersonation:

# Helm values for SSO passthrough mode
capiMode:
  enabled: true
  workloadClusterAuth:
    mode: "sso-passthrough"  # Instead of default "impersonation"
    caSecretSuffix: "-ca"    # CA-only secrets (no admin credentials needed)
AspectImpersonation (default)SSO Passthrough
ServiceAccount privilegesHigh (kubeconfig secrets)Low (CA secrets only)
Kubeconfig secret accessRequiredNot required
WC API server requirementsNoneOIDC configuration required
Audit trailShows impersonated userShows direct OIDC user
Fallback behaviorN/ANone (by design)

Important: There is no automatic fallback between modes. If SSO passthrough fails (e.g., WC API server rejects the token), the operation fails. This is intentional - mixing modes would require maintaining access to admin credentials, defeating the security benefit.

See docs/sso-passthrough-wc.md for detailed configuration and requirements.

Observability

The server includes comprehensive OpenTelemetry instrumentation for production monitoring:

  • Metrics: Prometheus-compatible metrics for HTTP requests, Kubernetes operations, and sessions
  • Distributed Tracing: OpenTelemetry traces for request flows and K8s API calls
  • Metrics Endpoint: /metrics endpoint for Prometheus scraping
# Enable instrumentation (enabled by default)
INSTRUMENTATION_ENABLED=true

# Configure metrics exporter (prometheus, otlp, stdout)
METRICS_EXPORTER=prometheus

# Configure tracing exporter (otlp, stdout, none)
TRACING_EXPORTER=otlp
OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318

# Set trace sampling rate (0.0 to 1.0)
OTEL_TRACES_SAMPLER_ARG=0.1

Available Metrics:

  • http_requests_total - HTTP request counter
  • http_request_duration_seconds - HTTP request duration histogram
  • mcp_kubernetes_operations_total - Kubernetes operation counter (management + workload scopes)
  • mcp_kubernetes_operation_duration_seconds - K8s operation duration histogram
  • kubernetes_pod_operations_total - Pod operation counter
  • oauth_downstream_auth_total - OAuth authentication counter
  • active_port_forward_sessions - Active port-forward sessions gauge

See docs/observability.md for detailed metrics documentation, Prometheus queries, and alerting examples.

Transport Types

Standard I/O (Default)

For local development and direct integration with MCP clients:

mcp-kubernetes serve --transport stdio

Streamable HTTP (Recommended for Production)

For network-accessible deployments with OAuth support:

mcp-kubernetes serve --transport streamable-http --http-addr :8080

Configuration Options

# Safety and operation modes
--non-destructive     # Enable non-destructive mode (default: true)
--dry-run            # Enable dry run mode (default: false)

# Performance tuning
--qps-limit 20.0     # QPS limit for Kubernetes API calls
--burst-limit 30     # Burst limit for Kubernetes API calls

# Authentication
--in-cluster                   # Use in-cluster authentication instead of kubeconfig
--enable-oauth                 # Enable OAuth 2.1 authentication (for HTTP transports)
--oauth-base-url string        # OAuth base URL (e.g., https://mcp.example.com)
--google-client-id string      # Google OAuth Client ID
--google-client-secret string  # Google OAuth Client Secret
--registration-token string    # OAuth client registration access token
--allow-public-registration    # Allow unauthenticated OAuth client registration

# Debugging
--debug              # Enable debug logging

# Transport-specific options
--transport string            # Transport type: stdio or streamable-http
--http-addr :8080            # HTTP server address (for streamable-http)
--http-endpoint /mcp         # HTTP endpoint path (default: /mcp)
--disable-streaming          # Disable streaming for streamable-http transport

Running in Kubernetes

The recommended way to deploy mcp-kubernetes in a Kubernetes cluster is using the Helm chart, which handles RBAC, Ingress, TLS, and OAuth configuration.

Using Helm (Recommended)

# Add the Giant Swarm app catalog
helm repo add giantswarm https://giantswarm.github.io/giantswarm-catalog/

# Install with default configuration
helm install mcp-kubernetes giantswarm/mcp-kubernetes

# Install with Ingress and TLS enabled
helm install mcp-kubernetes giantswarm/mcp-kubernetes \
  --set ingress.enabled=true \
  --set ingress.hosts[0].host=mcp.example.com \
  --set ingress.hosts[0].paths[0].path=/ \
  --set ingress.hosts[0].paths[0].pathType=Prefix \
  --set ingress.tls[0].secretName=mcp-kubernetes-tls \
  --set ingress.tls[0].hosts[0]=mcp.example.com

# Install with OAuth enabled
helm install mcp-kubernetes giantswarm/mcp-kubernetes \
  --set mcpKubernetes.oauth.enabled=true \
  --set mcpKubernetes.oauth.baseURL=https://mcp.example.com \
  --set mcpKubernetes.oauth.dex.issuerURL=https://dex.example.com \
  --set mcpKubernetes.oauth.dex.clientID=mcp-kubernetes \
  --set mcpKubernetes.oauth.existingSecret=mcp-kubernetes-oauth

See helm/mcp-kubernetes/values.yaml for all configuration options, including:

  • Ingress: TLS termination, custom annotations, multiple hosts
  • OAuth 2.1: Dex or Google providers, client registration, downstream OAuth
  • CAPI Mode: Multi-cluster federation via Cluster API
  • Observability: Prometheus ServiceMonitor, OpenTelemetry tracing

Connecting to the MCP Server

Once deployed with Ingress enabled, MCP clients connect to the /mcp endpoint:

{
  "mcpServers": {
    "kubernetes": {
      "url": "https://mcp.example.com/mcp"
    }
  }
}

The endpoint path is configurable via mcpKubernetes.httpEndpoint in the Helm values (default: /mcp).

Available Tools

The MCP server provides the following tools. The 15 tools that previously had a kubernetes_ prefix remain invokable under their old kubernetes_<name> names as deprecated backward-compat aliases, but are hidden from tools/list so new clients only see the bare names below. The aliases will be removed in a future release; please migrate.

Resource Management

  • get - Get a specific resource
  • list - List resources with pagination
  • describe - Get detailed resource information
  • create - Create a new resource
  • apply - Apply resource configuration
  • delete - Delete a resource
  • patch - Patch a resource
  • scale - Scale deployments, replicasets, statefulsets

Pod Operations

  • logs - Get logs from pod containers
  • exec - Execute commands in pod containers

Port Forwarding

  • port_forward - Set up port forwarding to a pod or service
  • list_port_forward_sessions - List active port-forward sessions
  • stop_port_forward_session - Stop a specific port-forward session
  • stop_all_port_forward_sessions - Stop all port-forward sessions

Context Management

  • context_list - List available Kubernetes contexts
  • context_get_current - Get the current context
  • context_use - Switch to a different context

Cluster Information

  • api_resources - Get available API resources
  • cluster_health - Get cluster health information

Access Control

  • can_i - Check whether the current user can perform an action on a resource

Cluster API (CAPI)

  • capi_list_clusters - List Cluster API workload clusters
  • capi_get_cluster - Get a Cluster API workload cluster
  • capi_resolve_cluster - Resolve a CAPI cluster reference
  • capi_cluster_health - Get health information for a CAPI workload cluster

Development

Building

make build

Testing

make test

Linting

make lint

Security

Authentication & Authorization

  • The server runs in non-destructive mode by default
  • Supports dry-run mode for safe operation testing
  • Allows restriction of operations and namespaces
  • Follows Kubernetes RBAC when using in-cluster authentication
  • OAuth 2.1 support with PKCE enforcement for HTTP transports
  • Downstream OAuth authentication for per-user RBAC enforcement

Secret Management (CRITICAL for Production)

⚠️ PRODUCTION REQUIREMENT: You MUST use a secret management solution for production deployments.

Recommended Solutions:

  • HashiCorp Vault
  • AWS Secrets Manager
  • Google Cloud Secret Manager
  • Azure Key Vault
  • Kubernetes External Secrets Operator

NEVER use environment variables for secrets in production because they:

  • Are visible in process listings (ps aux, docker inspect)
  • Get leaked in logs and error messages
  • Have no audit trail or rotation support
  • Are not encrypted at rest
  • Cannot be securely deleted

For detailed setup and examples, see:

Security Best Practices

Development:

  • Use environment variables only for local development
  • Never commit secrets to Git
  • Use pre-commit hooks (gitleaks, git-secrets)
  • Generate secrets securely (avoid shell history)

Production:

  • Store secrets in a secret manager (required)
  • Enable encryption at rest for Kubernetes Secrets
  • Rotate encryption keys every 90 days
  • Enable audit logging and monitoring
  • Use HTTPS with valid TLS certificates
  • Follow the comprehensive production checklist

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Ver o original no GitHub

Bom para

Relacionados