LJH-snow/dsh-tool-kubernetes

dsh-tool-kubernetes

Kubernetes tools for DeepSeek Harness: cluster, namespace, workload, pod, log, rollout, and manifest operations

미분류awesome-dsh-plugin

dsh-tool-kubernetes

English | 中文

A Cordis tool plugin that gives DeepSeek Harness (dsh) Kubernetes workflows: cluster/context inspection, namespace and workload discovery, pod logs, replica scaling, deployment rollouts, ConfigMaps, Secrets, Services, and manifest application.

The plugin registers 25 tools with the official ctx.tools.register(defineTool(...)) contract. It uses the official Kubernetes JavaScript client for kubeconfig loading and API calls, keeps write operations disabled by default, and returns stable business values for missing configuration and missing resources.

Install

Install directly from GitHub (no npm publish needed):

npm install github:LJH-snow/dsh-tool-kubernetes
# or a specific branch/tag
npm install github:LJH-snow/dsh-tool-kubernetes#main

Or from a local checkout:

git clone https://github.com/LJH-snow/dsh-tool-kubernetes
cd dsh-tool-kubernetes
npm install && npm run build   # builds to lib/
npm install /path/to/dsh-tool-kubernetes

Requires @deepseek-ai/cordis (^4.0.1) and @deepseek-ai/dsh-tools (^0.1.0-rc.6) as peer dependencies, provided by the host dsh runtime.

Configuration

Load the plugin in a dsh composition config (cordis.yml):

- name: 'dsh-tool-kubernetes'
  config:
    # Optional kubeconfig path. Defaults to $KUBECONFIG or ~/.kube/config.
    # kubeconfig: '/Users/you/.kube/config'
    # Optional kubeconfig context. Defaults to current-context.
    # context: 'prod'
    # Optional default namespace. Context namespace is used when omitted.
    namespace: 'team'
    # Write tools are off unless this is true.
    allowWrite: true
    # Optional namespace allowlist. Empty means every namespace is allowed when allowWrite is true.
    writeNamespaces:
      - team
    # Optional kind allowlist. Required to opt in to cluster-scoped, RBAC, Secret, or ServiceAccount writes.
    # writeKinds: [Deployment, StatefulSet]
    # Optional client-side pod log limits.
    # logMaxLines: 1000
    # logMaxBytes: 131072
    # logTimeoutMs: 15000

Full example: examples/cordis.yml.

Tools

Read-only

ToolDescription
k8s_get_configCurrent context, kubeconfig contexts, API server, default namespace
k8s_list_namespacesNamespace phase and creation time
k8s_list_nodesNode readiness, roles, kubelet version, internal IP
k8s_list_podsPods with phase, ready containers, restarts, node, containers
k8s_get_podOne pod with phase and container state
k8s_read_pod_logsTail pod logs with container/timestamps/previous options
k8s_list_deploymentsReplica and rollout counts for all deployments in a namespace
k8s_get_deploymentOne deployment with images and rollout counts
k8s_rollout_status_deploymentProgressing condition, revision, ready/updated/available replicas
k8s_list_statefulsetsStatefulSets with desired/ready replicas
k8s_get_statefulsetOne StatefulSet with images and replica state
k8s_list_servicesService type, cluster IP, external IP, ports
k8s_get_serviceOne service with selectors and exposed ports
k8s_list_ingressesIngress hosts and load balancer address
k8s_list_configmapsConfigMap key names and creation time
k8s_get_configmapOne ConfigMap with key names
k8s_list_secretsSecret names/types/key names only, never values
k8s_get_secretOne Secret with key names only
k8s_list_eventsRecent events with source, involved object, reason, count

Write

ToolDescription
k8s_scale_deploymentScale a deployment
k8s_scale_statefulsetScale a StatefulSet
k8s_restart_deploymentAdd a restartedAt annotation to a deployment pod template
k8s_update_deployment_imageUpdate one container image in a deployment
k8s_rollout_undo_deploymentRoll a deployment back to a previous ReplicaSet revision
k8s_apply_manifestCreate or patch one or more YAML/JSON manifests

Behavior contract

  • Kubernetes access comes from a kubeconfig path, $KUBECONFIG, ~/.kube/config, or in-cluster service account files resolved by the official Kubernetes client.
  • Missing configuration returns { connected: false, reason } instead of throwing during normal tool calls.
  • Missing resources return { found: false }; write operations return { ok: false, reason } for gating or API failures.
  • Write tools are disabled unless allowWrite: true. When writeNamespaces is set, it acts as a namespace allowlist; writeKinds is an explicit kind allowlist.
  • Cluster-scoped, RBAC, Secret, and ServiceAccount writes are denied by default. Add the exact kind to writeKinds to opt in.
  • k8s_apply_manifest validates the namespace and kind gate before any API request, including cluster-scoped manifests such as Namespace or Node.
  • k8s_list_secrets and k8s_get_secret intentionally return key names only; Secret values are not returned.
  • List limits are clamped to 1-100 (default 20). Pod log tail lines are clamped to 1-500 (default 200), then the client applies a 15-second timeout, redacts credentials, and caps output by logMaxLines/logMaxBytes (defaults 1000/128 KiB).

Development

npm install
npm run typecheck   # type check
npm test            # unit tests (vitest)
npm run build       # build to lib/

See DEVELOPMENT.md for technical notes and decisions.

Publishing

  1. Ensure npm run typecheck, npm test, and npm run build all pass.
  2. Publish with npm publish --access public.
  3. Add the dsh-plugin topic to the GitHub repository for ecosystem discovery.

License

MIT