How to Configure CrewAI Kubernetes MCP Server

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up a crewai kubernetes mcp server by linking an agent tool to a cluster role. The server reads local credentials and sends agent commands to the Kubernetes API. Engineering teams often use admin keys during early tests to make things work fast. That habit gives autonomous agents broad access across every namespace and node. If an agent hallucinates a bad command, broad roles let it delete live pods. How a crewai kubernetes mcp server uses cluster roles In this setup, the agent framewo

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

You set up a crewai kubernetes mcp server by linking an agent tool to a cluster role. The server reads local credentials and sends agent commands to the Kubernetes API. Engineering teams often use admin keys during early tests to make things work fast. That habit gives autonomous agents broad access across every namespace and node. If an agent hallucinates a bad command, broad roles let it delete live pods.

How a crewai kubernetes mcp server uses cluster roles

In this setup, the agent framework uses the Model Context Protocol to run cluster tools. You register the MCP server as a tool inside your agent task definition. When a task starts, the agent picks a tool and sends a structured request. The MCP server translates that tool call into a standard Kubernetes API call. The cluster API server checks the identity attached to that incoming request.

Kubernetes role-based access control uses four main objects to manage these permissions. A Role sets rules inside one specific namespace for your agent workloads. A ClusterRole sets rules across the entire cluster, including nodes and all namespaces. Both objects hold purely additive rules, which means Kubernetes has no deny rules. You then create a RoleBinding to grant permissions inside one single namespace. You use a ClusterRoleBinding when the agent needs access across the whole cluster.

Many teams start by binding the server to a broad cluster role. A safer setup uses a dedicated service account for the MCP server process. You bind that service account to a tight Role in one staging namespace. You also need separate rules for subresources like pod logs or pod exec calls. In Kubernetes RBAC, a rule for pods does not cover subresources by default. You must declare subresources with a slash, such as the pod log path.

Why native roles leave gaps for live agent actions

Native Kubernetes RBAC solves the problem of who can talk to the API server. It checks if the MCP server identity can read pods or update deployments. This setup stops an unauthorized process from touching namespaces outside its assigned scope. If you only grant read rules on pods, the agent cannot delete workloads.

Still, static roles cannot inspect what an individual command does in flight. Kubernetes RBAC has no deny rules, so every added permission expands agent reach. If an agent needs to run commands inside a pod, you grant exec rules. Once you grant exec access, the API server allows any command inside that container. The cluster role cannot tell a safe status check from a destructive shell command.

Kubernetes API Server Access + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Subresource rules also have limits when you try to lock down specific target names. In Kubernetes, resource name restrictions on create calls only apply to top-level resources. You cannot use that field alone to block specific actions on subresources. Also, pod logs and cluster configs often contain sensitive data in plain text. When an agent reads pod logs, raw emails or phone numbers flow into prompts. Native cluster roles cannot rewrite matched fields in results before the agent reads them.

Steps to harden your agent and cluster setup

Start by removing default admin credentials from the host that runs your agents. Create a dedicated service account that only serves this specific agent workflow. Write a namespace Role that lists only the exact verbs the agent needs. Stick to read verbs like get and list for your first agent tasks.

Avoid ClusterRoleBindings unless the agent truly must inspect nodes or cluster-wide resources. Keep write verbs and exec subresources out of the base role definition. When an agent must change state, require a human check before the tool runs. Split read tools and write tools into separate agent roles with distinct permissions. Log every tool request and API response so your team can audit agent behavior.

Add request guardrails and response masking beside Kubernetes

Cluster roles and service accounts govern who reaches the Kubernetes API. Still, a broad role or agent can delete workloads or print sensitive values from ConfigMaps and logs. In practice, hoop.dev runs beside the API server as a sidecar for your Kubernetes API and checks every request and response alongside RBAC.

With hoop.dev Kubernetes controls, guardrails can allow listing Secret names while refusing reads of Secret data before execution. Data masking redacts matched keys in returned JSON responses and log streams in memory. Furthermore, hoop.dev holds SOC 2 Type II and is MIT licensed on GitHub.

Frequently asked questions

How does CrewAI talk to a Kubernetes cluster through MCP?

CrewAI loads the MCP server as a tool and sends structured requests during tasks. The MCP server translates those requests into Kubernetes API calls using its local kubeconfig.

Should I use a Role or a ClusterRole for an AI agent?

Use a Role with a RoleBinding to keep the agent inside one single namespace. Only use a ClusterRole if the agent must read resources across all namespaces.

Why can my agent still run risky commands with RBAC enabled?

Kubernetes RBAC checks who logs in and which API resource they call. It does not inspect shell arguments inside pod exec calls or filter returned log data.

The query runs. The emails stay hidden.