使用说明
触手状mcp
用于Kubernetes命名空间生命周期、凭据管理、工作流自检和集群操作的集群内MCP(模型上下文协议)服务器。将来自开发人员工作站的直接kube-api访问替换为由作用域RBAC支持的单个经过身份验证的HTTP端点。
为什么
持有集群范围管理员kubeconfig的开发人员工作站是一种安全反模式。触手可及的mcp通过受控的ServiceAccount代理Kubernetes操作,因此CLI客户端(以及任何支持mcp的客户端)通过一个经过身份验证的端点与集群交互,而不是原始的kube-api访问。
相关存储库
| 存储库 | 目的 |
|---|---|
| 触手的 | Go CLI+Deno工作流引擎 |
| 触手技能 | 人工智能助手的代理技能定义 |
| 触手支架 | 工作流脚手架目录(快速启动) |
| 触手状docs | 文件网站 |
文档
完整文档: randybias、ithub.io/tantacular-docs --看 MCP工具参考, MCP服务器设置,以及 外骨骼.
建筑
MCP服务器还管理 模块代理 在 tentacular-support 命名空间。启动时,代理协调器(pkg/proxy/)auto创建了一个esm.sh部署和服务,为工作流Pod缓存jsr/npm模块。这消除了工作流容器的直接互联网出口。
请求流
- HTTP请求命中
:8080/mcp和Authorization: Bearer <token> auth.Middleware验证令牌(如果无效,则用401拒绝;绕过/healthz)- MCP-SDK
StreamableHTTPHandler解析消息并路由到注册的工具 register.go包装器:解组参数,运行guard.CheckNamespace(),调用处理程序,封送结果- 处理程序调用
pkg/k8s集群中使用的函数rest.Config - 结果作为MCP返回
Content和type: "text"包含JSON
先决条件
- 转到1.25+
- Kubernetes集群(适用于本地开发)
kubectl配置了群集访问权限- Docker(用于构建容器镜像)
openssl(用于生成身份验证令牌)
快速开始
通过伞形图部署平台(推荐)
雨伞图(charts/tentacular-platform/)部署完整的平台:MCP服务器、PostgreSQL、NATS、证书管理器(可选)、esm-sh代理、命名空间管理和网络策略。它创建了三个命名空间(tentacular-system, tentacular-exoskeleton, tentacular-support),部署所有子部件,并通过以下方式连接外骨骼Secret envFrom.
发展 (emptyDir存储、最小资源、NodePort访问):
helm dependency update charts/tentacular-platform/
helm install tentacular charts/tentacular-platform/ \
-f charts/tentacular-platform/ci/dev-values.yaml \
-n tentacular-system --create-namespace
开发值包括测试凭据和禁用持久存储,因此没有额外的 --set 需要旗帜。通过节点端口30080访问MCP。
生产 (持久存储、TLS、nginx Ingress):
生产需要证书管理器CRD进行TLS证书管理。如果证书管理器尚未存在,请先安装:
# Step 1: Install cert-manager (skip if already installed)
helm repo add jetstack https://charts.jetstack.io
helm repo update
helm install cert-manager jetstack/cert-manager \
-n cert-manager --create-namespace --set crds.enabled=true
# Step 2: Install the platform
helm dependency update charts/tentacular-platform/
helm install tentacular charts/tentacular-platform/ \
-f charts/tentacular-platform/ci/prod-values.yaml \
-n tentacular-system --create-namespace \
--set tentacular-mcp.auth.token="$(openssl rand -hex 32)" \
--set postgresql.auth.password="$(openssl rand -hex 16)" \
--set nats.config.merge.authorization.token="$(openssl rand -hex 16)"
如果您不需要TLS证书,请禁用它们并跳过证书管理器步骤:
helm install tentacular charts/tentacular-platform/ \
-f charts/tentacular-platform/ci/prod-values.yaml \
-n tentacular-system --create-namespace \
--set tls.clusterIssuers.create=false \
--set tls.certificates.mcp.create=false \
--set tentacular-mcp.auth.token="$(openssl rand -hex 32)" \
--set postgresql.auth.password="$(openssl rand -hex 16)" \
--set nats.config.merge.authorization.token="$(openssl rand -hex 16)"
这 -n tentacular-system 需要标记,以便MCP吊舱及其Secret位于同一位置。看 charts/tentacular-platform/README.md 对于所有值配置文件、入口模式(nodeport、ingress、istio、alb-istio)、网络策略和组件切换。
仅限MCP服务器(独立)
TOKEN=$(openssl rand -hex 32)
helm install tentacular-mcp ./charts/tentacular-mcp \
--namespace tentacular-system --create-namespace \
--set auth.token="${TOKEN}"
手动部署(Kustomize)
或者,直接使用Kustomize进行部署:
kubectl apply -k deploy/manifests/
这将创建:
tentacular-system命名空间- ServiceAccount、ClusterRole和ClusterRoleBinding
- 身份验证密钥
- 部署(单副本、无发行版容器、非根)
- 8080端口上的群集IP服务
Helm值
自定义部署的关键值:
| 值 | 默认值 | 描述 |
|---|---|---|
image.repository |
ghcr.io/randybias/tentacular-mcp |
容器图片 |
image.tag |
latest |
图像标签 |
image.pullPolicy |
IfNotPresent |
拉动政策 |
auth.token |
"" |
承载令牌(使用生成 openssl rand -hex 32) |
auth.existingSecret |
"" |
使用现有的Secret,而不是创建一个Secret |
namespace.create |
true |
创建 tentacular-system 命名空间 |
service.type |
ClusterIP |
服务类型 |
service.port |
8080 |
服务端口 |
resources.requests.memory |
64Mi |
内存请求 |
resources.limits.memory |
256Mi |
内存限制 |
CLI配置
部署后,配置触手CLI以连接到MCP服务器:
# Option 1: interactive setup
tntc configure
# Option 2: manual config (~/.tentacular/config.yaml)
mcp:
endpoint: http://tentacular-mcp.tentacular-system.svc.cluster.local:8080/mcp
token_path: ~/.tentacular/mcp-token
存储令牌:
echo "<TOKEN>" > ~/.tentacular/mcp-token
chmod 600 ~/.tentacular/mcp-token
连接
# Port-forward to reach the server from outside the cluster
kubectl port-forward -n tentacular-system svc/tentacular-mcp 8080:8080
# Verify the health endpoint
curl http://localhost:8080/healthz
# Send an MCP initialize request (using any MCP client)
# The server listens on /mcp via Streamable HTTP transport
MCP工具
在13个职能组中组织了36个工具。所有命名空间范围的工具都强制执行自我保护保护,拒绝针对系统命名空间的操作。
命名空间生命周期
| 工具 | 说明 |
|---|---|
ns_create |
使用PSA标签、默认拒绝NetworkPolicy、DNS允许策略、ResourceQuota、LimitRange和工作流SA/Role/RoleBinding创建托管命名空间。接受 small, medium,或 large 配额预设。 |
ns_delete |
删除托管命名空间和所有子资源。 |
ns_get |
获取命名空间详细信息,包括标签、注释、配额摘要和限制范围。 |
ns_list |
列出所有触手管理的命名空间。 |
ns_update |
更新托管命名空间上预设的标签、注释或资源配额。 |
凭据管理
| 工具 | 说明 |
|---|---|
cred_issue_token |
通过TokenRequest API发布一个短暂的ServiceAccount令牌。TTL可配置为10至1440分钟。 |
cred_kubeconfig |
生成一个包含时间限制令牌、集群CA和API服务器URL的作用域kubeconfig YAML |
cred_rotate |
通过重新创建工作流ServiceAccount来旋转凭据,使所有先前的令牌无效。 |
工作流程反思
| 工具 | 说明 |
|---|---|
wf_pods |
在命名空间中列出Pod,包括阶段、准备状态、重启计数、映像和年龄。 |
wf_logs |
尾舱日志(快照,非流式)。支持容器选择和行数。 |
wf_events |
列出命名空间事件,包括类型、原因、消息、对象引用和计数。 |
wf_jobs |
在命名空间中列出作业和CronJobs,包括状态、计划和持续时间。 |
wf_restart |
通过用重启时间戳修补pod模板来重新启动部署。在ConfigMap/Secret更改、凭据轮换或gVisor启用后有用。 |
集群操作
| 工具 | 说明 |
|---|---|
cluster_preflight |
运行飞行前验证检查(API连接、命名空间访问、RBAC、gVisor可用性)。 |
cluster_profile |
生成完整的集群配置文件:K8s版本、节点、CNI、存储类、运行时类、扩展和外骨骼服务。 |
gVisor沙箱
| 工具 | 说明 |
|---|---|
gvisor_check |
检查gVisor RuntimeClass是否在集群中可用。 |
gvisor_annotate_ns |
使用gVisor运行时类对托管命名空间进行注释。 |
gvisor_verify |
运行验证pod以确认gVisor沙箱隔离功能正常。 |
外骨骼(第1阶段)
| 工具 | 说明 |
|---|---|
exo_status |
返回外骨骼功能状态,包括哪些支持服务(Postgres、NATS、RustFS、SPIRE)可用。 |
exo_registration |
返回工作流部署的外骨骼注册详细信息(机密内容)。敏感值被编辑。 |
exo_list |
通过在所有命名空间中扫描带有外骨骼标签的Secrets,列出所有具有外骨骼注册的工作流。 |
部署生命周期
| 工具 | 说明 |
|---|---|
wf_apply |
使用动态客户端将任意Kubernetes清单应用为命名部署。在部署/作业/CronJob清单上自动注入符合PSA的安全上下文。按名称标签跟踪资源以进行垃圾回收。 |
wf_remove |
删除与部署名称关联的所有资源。 |
wf_status |
检查命名部署中所有资源的状态。 |
工作流执行
| 工具 | 说明 |
|---|---|
wf_run |
通过直接将POSTing发送到工作流的ClusterIP服务来触发已部署的工作流 /run 终点。NetworkPolicy允许通过namespaceSelector从触手系统进入。返回带有执行持续时间的JSON输出。超时可配置(默认120秒,最大600秒)。不会创建临时Pod。 |
模块代理
| 工具 | 说明 |
|---|---|
proxy_status |
检查集群内模块代理(esm.sh)的安装和就绪状态。返回安装状态、就绪状态、命名空间、映像和存储类型。 |
工作流运行状况
| 工具 | 说明 |
|---|---|
wf_health |
获取单个工作流部署的G/A/R(绿色/琥珀色/红色)运行状况。检查吊舱准备情况并探测发动机 /health 终点。随着 detail=true,包括执行遥测 /health?detail=1. |
wf_health_ns |
汇总命名空间中所有触手工作流部署的G/A/R健康状态。返回每个工作流状态和绿色/琥珀色/红色计数的摘要。 |
群集运行状况
| 工具 | 说明 |
|---|---|
health_nodes |
查询节点准备状态、容量、可分配资源和条件。 |
health_ns_usage |
报告命名空间资源利用率与配额(CPU、内存、pod计数)。 |
health_cluster_summary |
总体集群资源摘要:总节点、Pod、CPU和内存容量/请求。 |
安全审计
| 工具 | 说明 |
|---|---|
audit_rbac |
扫描命名空间RBAC以查找权限过大的角色(通配符动词、敏感资源、通过绑定/升级/模拟的升级路径),并提供补救建议。 |
audit_netpol |
验证NetworkPolicy覆盖范围:默认拒绝存在、过于宽泛的允许规则、跨命名空间入口检测,并提供补救建议。 |
audit_psa |
验证Pod安全准入标签:强制/审核/警告级别、特权检测、级别不匹配检测,并提供补救建议。 |
工作流发现
| 工具 | 说明 |
|---|---|
wf_list |
列出跨命名空间的所有工作流部署,包括所有者、版本、标记和副本状态。支持按所有者和标签过滤。 |
wf_describe |
描述一个单一的工作流部署,其中包含来自相关ConfigMap的详细元数据、注释、图像和丰富数据。 |
认证
所有请求 /mcp 需要 Authorization: Bearer <token> 头球这 /healthz 端点未经身份验证。
服务器从加载其预期的令牌 TENTACULAR_MCP_TOKEN 环境变量。在标准部署中,这是从以下位置填充的 tentacular-mcp-token Kubernetes秘密通过 secretKeyRef.
生成令牌
# Generate a 32-byte hex token
openssl rand -hex 32
通过Helm部署时,将令牌传递给 --set auth.token=<token>.
令牌存储在 tentacular-mcp-token Kubernetes的秘密。
检索已部署的令牌
kubectl get secret tentacular-mcp-token -n tentacular-system \
-o jsonpath='{.data.token}' | base64 -d
部署
Kustomize部署
kubectl apply -k deploy/manifests/
kustomization按顺序部署这些资源:
tentacular-system命名空间- 服务账号+集群角色+集群角色绑定
- 身份验证密钥
- 部署(单副本、无发行版非根映像)
- 集群IP服务(端口8080)
验证部署
# Check the pod is running
kubectl get pods -n tentacular-system
# Check logs
kubectl logs -n tentacular-system -l app.kubernetes.io/name=tentacular-mcp
# Port-forward and test
kubectl port-forward -n tentacular-system svc/tentacular-mcp 8080:8080 &
curl http://localhost:8080/healthz
回滚
kubectl rollout undo deployment/tentacular-mcp -n tentacular-system
或缩放到零:
kubectl scale deployment/tentacular-mcp -n tentacular-system --replicas=0
没有需要清理的持久状态——所有状态都存在于Kubernetes对象中。
发展
建筑
make build # Build binary to bin/tentacular-mcp
make docker-build # Build Docker image
make lint # Run golangci-lint and go vet
make clean # Remove build artifacts
测试
测试分为4个层次:
| 层级 | 命令 | 要求 |
|---|---|---|
| 单位 | make test-unit |
不需要集群 |
| 集成 | make test-integration |
种类集群(自动配置) |
| E2E | make test-e2e |
生产k0s集群;集 TENTACULAR_E2E_KUBECONFIG |
| 全部 | make test-all |
按顺序运行所有层 |
# Unit tests only (default)
make test
# Integration tests (sets up and tears down a kind cluster)
make test-integration
# E2E tests (requires a real cluster)
TENTACULAR_E2E_KUBECONFIG=/path/to/kubeconfig make test-e2e
项目结构
cmd/tentacular-mcp/main.go Entry point with graceful shutdown
pkg/auth/ Bearer token middleware
pkg/exoskeleton/ Exoskeleton subsystem (registrars, identity, injection)
pkg/guard/ Self-protection namespace guard
pkg/k8s/ Kubernetes client and operations
pkg/proxy/ Module proxy reconciler and manifests
pkg/server/ MCP server setup and HTTP handler
pkg/tools/ 36 MCP tool handlers (one file per group)
charts/tentacular-platform/ Umbrella Helm chart (recommended deployment)
charts/tentacular-mcp/ Standalone MCP server Helm chart
deploy/manifests/ Kustomize deployment manifests
test/integration/ Integration tests (kind cluster)
test/e2e/ E2E tests (production cluster)
配置
| 环境变量 | 默认值 | 描述 |
|---|---|---|
LISTEN_ADDR |
:8080 |
HTTP服务器绑定到的地址和端口 |
TENTACULAR_MCP_TOKEN |
(必需) | 用于客户端身份验证的承载身份验证令牌 |
TENTACULAR_MCP_NAMESPACE |
tentacular-system |
安装MCP服务器的命名空间 |
TENTACULAR_PROXY_RECONCILER_DISABLED |
(未设置) | 设置为 "true" 禁用内置的esm-sh代理协调器(伞形图使用) |
安全模型
吊舱安全准入(PSA)
由创建的所有命名空间 ns_create 标有 restricted PSA简介:
pod-security.kubernetes.io/enforce: restrictedpod-security.kubernetes.io/enforce-version: latest
wf_apply 自动在部署/作业/CronJob清单上注入符合PSA的安全上下文(runAsNonRoot、readOnlyRootFilesystem、drop ALL功能、seccomp RuntimeDefault、/tmp emptyDir卷)。保留用户指定的值。
网络策略
每个创建的命名空间都会得到:
- A. 默认拒绝 网络策略阻止所有入口和出口
- A. DNS允许 网络策略允许端口53上的UDP/TCP出口到kube-system/kube-dns
当工作流声明 tentacular-* 依赖关系,外骨骼富集管道会自动将出口规则附加到每个配置的支持服务(Postgres、NATS、RustFS)的工作流NetworkPolicy中,以服务的命名空间和端口为目标。
RBAC范围界定
服务器的ClusterRole的作用域恰好是36个工具所需的动词和资源。它比 cluster-admin.关键制约因素:
- 对节点、存储类、运行时类、CRD的只读访问
- 为Pod创建/删除(仅限gVisor验证)
- 由工具处理程序管理的资源的命名空间CRUD
selfsubjectaccessreviews用于飞行前RBAC验证
自我保护
guard.CheckNamespace() 在每个命名空间范围的工具之前运行。它拒绝任何针对目标的操作 tentacular-system, tentacular-support, tentacular-exoskeleton, kube-system, kube-public, kube-node-lease,以及 default,防止服务器修改其自己的部署或关键集群命名空间。
集装箱安全
部署使用以下方式运行:
runAsNonRoot: true(用户ID 65534)readOnlyRootFilesystem: trueallowPrivilegeEscalation: false- 所有功能都下降了
RuntimeDefaultseccomp配置文件- 分散基本图像(
gcr.io/distroless/static-debian12:nonroot)
CLI集成
触手CLI(tntc)委派所有群集操作
连接到此MCP服务器。配置MCP连接详细信息
每种环境 ~/.tentacular/config.yaml 或通过
TNTC_MCP_ENDPOINT / TNTC_MCP_TOKEN 环境变量。
所有CLI命令都会自动使用MCP服务器--否
需要每个命令标志。
CLI无法直接访问Kubernetes API。面向所有集群 命令(部署、运行、列表、状态、日志、取消部署、审核、, 集群检查、集群配置文件)通过MCP路由。
启动时,MCP服务器的代理协调器会自动在中创建esm.sh模块代理 tentacular-support.
CLI使用的MCP工具
| CLI命令 | MCP工具 |
|---|---|
cluster check |
cluster_preflight |
cluster profile |
cluster_profile |
deploy |
wf_apply, ns_create |
run |
wf_run |
list |
wf_list |
status |
wf_status |
logs |
wf_logs |
undeploy |
wf_remove |
audit |
audit_rbac, audit_netpol, audit_psa |
看 MCP服务器设置指南 了解全部细节。
贡献
- 遵循现有的代码模式——工具处理程序是独立的函数
*k8s.Client并返回结构化结果 - 在中添加新工具
pkg/tools/遵循每组一个文件的惯例 - 通过注册工具
pkg/tools/register.go--包装器处理JSON解组、保护检查和MCP协议问题 - 在代码旁边编写单元测试;为K8s交互添加集成测试
- 跑
make lint提交更改之前 - 对所有提交消息使用常规提交
许可证
版权所有(c)2025-2026 Mirantis,股份有限公司保留所有权利。看 许可证 了解详情。
