How to Configure Dify Kubernetes MCP Server

Published
Length
3 min read

Luis Felipe Dias

All posts

To set up a dify kubernetes mcp server, connect your Dify agent to a Model Context Protocol server with a scoped Kubernetes role. You then bind that role to a single namespace so the agent only reads or changes approved cluster objects. Most teams start by giving the server a broad admin token to test tool calls fast. When permissions stay that wide in production, one bad prompt can delete pods or read secrets across the whole cluster. How the dify kubernetes mcp server setup works Dify uses

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.

To set up a dify kubernetes mcp server, connect your Dify agent to a Model Context Protocol server with a scoped Kubernetes role. You then bind that role to a single namespace so the agent only reads or changes approved cluster objects. Most teams start by giving the server a broad admin token to test tool calls fast. When permissions stay that wide in production, one bad prompt can delete pods or read secrets across the whole cluster.

How the dify kubernetes mcp server setup works

Dify uses the Model Context Protocol to let language models call outside tools. The MCP server sits between Dify and your Kubernetes API server. When a user asks Dify a question, the model picks a tool on the MCP server. The MCP server then translates that tool call into a standard Kubernetes API request.

To make this work, the MCP server needs a valid cluster credential. You create a service account in Kubernetes and link it to RBAC rules. In Kubernetes RBAC, a Role sets permissions inside one namespace. A ClusterRole sets permissions across the whole cluster, including nodes and all namespaces.

A RoleBinding grants those permissions within one specific namespace. A ClusterRoleBinding grants access across the entire cluster at once. Kubernetes RBAC permissions are purely additive, which means there are no deny rules. You must start with zero access and add only the exact verbs the agent needs.

You also need to watch subresources in the API URL. Kubernetes RBAC writes subresources with a slash, such as pod logs or pod exec calls. If Dify needs to read pod logs, the role must allow the log subresource. If you grant the exec subresource, the agent can run shell commands inside containers.

Why native roles leave a gap in runtime control

Native Kubernetes RBAC checks who logs in and which API resource they call. That setup solves basic access setup for static apps and service accounts. It keeps an agent inside one namespace or blocks it from deleting deployments. Still, native RBAC does not inspect what happens inside an allowed request during flight.

Once a role allows pod log reads, the MCP server pulls full log streams. Those logs often hold user emails, phone numbers, card numbers, or national IDs. The native API server sends all that raw text straight back to the Dify model. Masking tools can rewrite matched fields in results before they reach the model prompt.

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

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

The same gap appears when an agent has permission to run pod exec calls. Kubernetes RBAC checks if the service account can call the exec subresource on that pod. It does not check which shell command the Dify agent sends inside the container. A model with exec rights can run destructive commands or dump container memory.

Scoping cluster roles for safe agent tool calls

Start by listing the exact questions your Dify app needs to answer. For read-only debugging, build a Kubernetes Role in a single target namespace. Grant only read verbs like get, list, and watch on pods and events. Leave out secret resources so the model cannot pull raw API keys or passwords.

Avoid using a ClusterRoleBinding unless the Dify workflow must inspect cluster nodes. If you share one ClusterRole across teams, bind it per namespace with a RoleBinding. Review subresource rules often and remove pod exec permissions from automated agent accounts. Keep write actions tied to human approval steps rather than open model tool calls.

Govern kubectl and API calls in flight

Identity providers and Kubernetes RBAC decide who logs into a cluster. They cannot redact keys inside returned JSON objects or hold a risky delete call for review. By design, hoop.dev runs as an open-source proxy, a sidecar for your Kubernetes API, checking requests and responses without replacing RBAC.

First, hoop.dev guardrails refuse banned methods, paths, or headers before they run. Next, hoop.dev data masking rewrites sensitive keys in returned Secret, ConfigMap, and log responses in memory, and writes each decision to the audit trail. Explore the repo on GitHub.

Frequently asked questions

Can I block specific resources with a Kubernetes deny rule?

No, Kubernetes RBAC rules are purely additive and do not support deny rules. To block access to secrets, leave secrets out of the Role definition.

How do I let Dify read pod logs without giving container shell access?

Grant get access to the pod log subresource in your Kubernetes Role. Do not include the pod exec subresource in that same role.

Should the MCP server use a RoleBinding or a ClusterRoleBinding?

Use a RoleBinding whenever the Dify agent works inside one namespace. A ClusterRoleBinding gives cluster-wide access and increases risk if a prompt goes wrong.

The query runs. The emails stay hidden.